MDL-60301 libraries: Upgrade FPDI to 1.6.2

This commit is contained in:
Ankit Agarwal 2017-10-03 10:13:38 +05:30
parent 23ab0d7788
commit faa9be014b
12 changed files with 80 additions and 35 deletions

View file

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2015 Setasign - Jan Slabon, https://www.setasign.com Copyright (c) 2017 Setasign - Jan Slabon, https://www.setasign.com
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
/** /**

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
/** /**

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
/** /**

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
if (!class_exists('fpdi_bridge')) { if (!class_exists('fpdi_bridge')) {

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
if (!class_exists('FPDF_TPL')) { if (!class_exists('FPDF_TPL')) {
@ -22,7 +22,7 @@ class FPDI extends FPDF_TPL
* *
* @string * @string
*/ */
const VERSION = '1.6.1'; const VERSION = '1.6.2';
/** /**
* Actual filename * Actual filename
@ -88,6 +88,7 @@ class FPDI extends FPDF_TPL
* *
* @param string $filename A valid path to the PDF document from which pages should be imported from * @param string $filename A valid path to the PDF document from which pages should be imported from
* @return int The number of pages in the document * @return int The number of pages in the document
* @throws Exception
*/ */
public function setSourceFile($filename) public function setSourceFile($filename)
{ {
@ -95,17 +96,28 @@ class FPDI extends FPDF_TPL
if (false !== $_filename) if (false !== $_filename)
$filename = $_filename; $filename = $_filename;
$this->currentFilename = $filename; $currentFilename = $this->currentFilename;
$currentParser = $this->currentParser;
if (!isset($this->parsers[$filename])) { try {
$this->parsers[$filename] = $this->_getPdfParser($filename); $this->currentFilename = $filename;
$this->setPdfVersion(
max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion()) if (!isset($this->parsers[$filename])) {
); $this->parsers[$filename] = $this->_getPdfParser($filename);
$this->setPdfVersion(
max($this->getPdfVersion(), $this->parsers[$filename]->getPdfVersion())
);
}
$this->currentParser = $this->parsers[$filename];
} catch (Exception $e) {
unset($this->parsers[$filename]);
$this->currentFilename = $currentFilename;
$this->currentParser = $currentParser;
throw $e;
} }
$this->currentParser = $this->parsers[$filename];
return $this->parsers[$filename]->getPageCount(); return $this->parsers[$filename]->getPageCount();
} }

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
/** /**
@ -16,12 +16,21 @@
* This way it is possible to use FPDI for both FPDF and TCPDF with one FPDI version. * This way it is possible to use FPDI for both FPDF and TCPDF with one FPDI version.
*/ */
if (!class_exists('TCPDF', false)) {
/** /**
* Class fpdi_bridge * Class fpdi_bridge
*
* This has been modified to use the Moodle pdf class which in turn extends the TCPDF class.
*/ */
class fpdi_bridge extends pdf class fpdi_bridge extends FPDF
{
// empty body
}
} else {
/**
* Class fpdi_bridge
*/
class fpdi_bridge extends TCPDF
{ {
/** /**
* Array of Tpl-Data * Array of Tpl-Data
@ -194,3 +203,4 @@
return current(unpack('H*', $str)); return current(unpack('H*', $str));
} }
} }
}

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (http://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
if (!class_exists('pdf_parser')) { if (!class_exists('pdf_parser')) {
@ -155,6 +155,10 @@ class fpdi_pdf_parser extends pdf_parser
if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) { if (isset($this->_pages[$this->pageNo][1][1]['/Contents'])) {
$contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']); $contents = $this->_getPageContent($this->_pages[$this->pageNo][1][1]['/Contents']);
foreach ($contents AS $tmpContent) { foreach ($contents AS $tmpContent) {
if ($tmpContent[0] !== pdf_parser::TYPE_STREAM) {
continue;
}
$buffer .= $this->_unFilterStream($tmpContent) . ' '; $buffer .= $this->_unFilterStream($tmpContent) . ' ';
} }
} }
@ -335,6 +339,10 @@ class fpdi_pdf_parser extends pdf_parser
foreach ($kids as $v) { foreach ($kids as $v) {
$pg = $this->resolveObject($v); $pg = $this->resolveObject($v);
if ($pg[0] !== pdf_parser::TYPE_OBJECT) {
throw new Exception('Invalid data type in page tree.');
}
if ($pg[1][1]['/Type'][1] === '/Pages') { if ($pg[1][1]['/Type'][1] === '/Pages') {
// If one of the kids is an embedded // If one of the kids is an embedded
// /Pages array, resolve it as well. // /Pages array, resolve it as well.

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
/** /**
@ -67,7 +67,14 @@ class pdf_context
public function getPos() public function getPos()
{ {
if ($this->_mode == 0) { if ($this->_mode == 0) {
return ftell($this->file); if (feof($this->file)) {
$stat = fstat($this->file);
fseek($this->file, $stat['size']);
}
$pos = ftell($this->file);
return $pos;
} else { } else {
return 0; return 0;
} }
@ -85,7 +92,7 @@ class pdf_context
{ {
if ($this->_mode == 0) { if ($this->_mode == 0) {
if (!is_null($pos)) { if (!is_null($pos)) {
fseek ($this->file, $pos); fseek($this->file, $pos);
} }
$this->buffer = $l > 0 ? fread($this->file, $l) : ''; $this->buffer = $l > 0 ? fread($this->file, $l) : '';

View file

@ -3,9 +3,9 @@
* This file is part of FPDI * This file is part of FPDI
* *
* @package FPDI * @package FPDI
* @copyright Copyright (c) 2015 Setasign - Jan Slabon (http://www.setasign.com) * @copyright Copyright (c) 2017 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License * @license http://opensource.org/licenses/mit-license The MIT License
* @version 1.6.1 * @version 1.6.2
*/ */
/** /**

View file

@ -19,6 +19,14 @@ Installation
3) Update mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php (or the replacement file) to extend 'pdf' instead of 'TCPDF'. 3) Update mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php (or the replacement file) to extend 'pdf' instead of 'TCPDF'.
4) Make a note below of any changes made. 4) Make a note below of any changes made.
2017/10/03
----------
1/ Updated to 1.6.2
2/ Cherry-picked changes in MDL-55848
3/ Renamed 'TCPDF' to 'pdf' as stated above.
Updated by Ankit Agarwal<ankit.agrr@gmail.com> (MDL-60301)
2016/11/15 2016/11/15
---------- ----------

View file

@ -4,7 +4,7 @@
<location>fpdi</location> <location>fpdi</location>
<name>FPDI</name> <name>FPDI</name>
<license>MIT</license> <license>MIT</license>
<version>1.6.1</version> <version>1.6.2</version>
<licenseversion></licenseversion> <licenseversion></licenseversion>
</library> </library>
</libraries> </libraries>