Merge branch 'MDL-71717' of git://github.com/paulholden/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2021-06-24 00:18:45 +02:00
commit d9347556e3
7 changed files with 50 additions and 40 deletions

View File

@ -29,7 +29,7 @@ class Fpdi extends FpdfTpl
*
* @string
*/
const VERSION = '2.3.5';
const VERSION = '2.3.6';
protected function _enddoc()
{

View File

@ -334,43 +334,48 @@ trait FpdiTrait
// try to use the existing content stream
$pageDict = $page->getPageDictionary();
$contentsObject = PdfType::resolve(PdfDictionary::get($pageDict, 'Contents'), $reader->getParser(), true);
$contents = PdfType::resolve($contentsObject, $reader->getParser());
try {
$contentsObject = PdfType::resolve(PdfDictionary::get($pageDict, 'Contents'), $reader->getParser(), true);
$contents = PdfType::resolve($contentsObject, $reader->getParser());
// just copy the stream reference if it is only a single stream
if (
($contentsIsStream = ($contents instanceof PdfStream))
|| ($contents instanceof PdfArray && \count($contents->value) === 1)
) {
if ($contentsIsStream) {
/**
* @var PdfIndirectObject $contentsObject
*/
$stream = $contents;
// just copy the stream reference if it is only a single stream
if (
($contentsIsStream = ($contents instanceof PdfStream))
|| ($contents instanceof PdfArray && \count($contents->value) === 1)
) {
if ($contentsIsStream) {
/**
* @var PdfIndirectObject $contentsObject
*/
$stream = $contents;
} else {
$stream = PdfType::resolve($contents->value[0], $reader->getParser());
}
$filter = PdfDictionary::get($stream->value, 'Filter');
if (!$filter instanceof PdfNull) {
$dict->value['Filter'] = $filter;
}
$length = PdfType::resolve(PdfDictionary::get($stream->value, 'Length'), $reader->getParser());
$dict->value['Length'] = $length;
$stream->value = $dict;
// otherwise extract it from the array and re-compress the whole stream
} else {
$stream = PdfType::resolve($contents->value[0], $reader->getParser());
$streamContent = $this->compress
? \gzcompress($page->getContentStream())
: $page->getContentStream();
$dict->value['Length'] = PdfNumeric::create(\strlen($streamContent));
if ($this->compress) {
$dict->value['Filter'] = PdfName::create('FlateDecode');
}
$stream = PdfStream::create($dict, $streamContent);
}
$filter = PdfDictionary::get($stream->value, 'Filter');
if (!$filter instanceof PdfNull) {
$dict->value['Filter'] = $filter;
}
$length = PdfType::resolve(PdfDictionary::get($stream->value, 'Length'), $reader->getParser());
$dict->value['Length'] = $length;
$stream->value = $dict;
// otherwise extract it from the array and re-compress the whole stream
} else {
$streamContent = $this->compress
? \gzcompress($page->getContentStream())
: $page->getContentStream();
$dict->value['Length'] = PdfNumeric::create(\strlen($streamContent));
if ($this->compress) {
$dict->value['Filter'] = PdfName::create('FlateDecode');
}
$stream = PdfStream::create($dict, $streamContent);
// Catch faulty pages and use an empty content stream
} catch (FpdiException $e) {
$dict->value['Length'] = PdfNumeric::create(0);
$stream = PdfStream::create($dict, '');
}
$this->importedPages[$pageId] = [

View File

@ -42,7 +42,7 @@ class Fpdi extends \pdf
*
* @string
*/
const VERSION = '2.3.5';
const VERSION = '2.3.6';
/**
* A counter for template ids.

View File

@ -30,7 +30,7 @@ class Fpdi extends FpdfTpl
*
* @string
*/
const VERSION = '2.3.5';
const VERSION = '2.3.6';
public function _enddoc()
{

View File

@ -8,8 +8,7 @@
* @license http://opensource.org/licenses/mit-license The MIT License
*/
// @phpstan-ignore-next-line
spl_autoload_register(function ($class) {
spl_autoload_register(static function ($class) {
if (strpos($class, 'setasign\Fpdi\\') === 0) {
$filename = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 14)) . '.php';
$fullpath = __DIR__ . DIRECTORY_SEPARATOR . $filename;

View File

@ -19,6 +19,12 @@ Installation
3) Update mod/assign/feedback/editpdf/fpdi/Tcpdf/Fpdi.php(or whichever file it has been replaced with) to extend 'pdf' instead of 'TCPDF'.
4) Make a note below of any changes made.
2021/05/26
----------
1/ Updated to 2.3.6
Updated by Paul Holden (MDL-71717)
2020/12/16
----------
1/ Updated to 2.3.5

View File

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