Skip to content

Commit

Permalink
Merge branch 'MDL-71717' of git://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 23, 2021
2 parents 5df31d9 + 3bd4d67 commit d934755
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
2 changes: 1 addition & 1 deletion mod/assign/feedback/editpdf/fpdi/Fpdi.php
Expand Up @@ -29,7 +29,7 @@ class Fpdi extends FpdfTpl
*
* @string
*/
const VERSION = '2.3.5';
const VERSION = '2.3.6';

protected function _enddoc()
{
Expand Down
71 changes: 38 additions & 33 deletions mod/assign/feedback/editpdf/fpdi/FpdiTrait.php
Expand Up @@ -334,43 +334,48 @@ public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupX
// 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());

// 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;
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;
} 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();

$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;
$dict->value['Length'] = PdfNumeric::create(\strlen($streamContent));
if ($this->compress) {
$dict->value['Filter'] = PdfName::create('FlateDecode');
}

// 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);
}

$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] = [
Expand Down
2 changes: 1 addition & 1 deletion mod/assign/feedback/editpdf/fpdi/Tcpdf/Fpdi.php
Expand Up @@ -42,7 +42,7 @@ class Fpdi extends \pdf
*
* @string
*/
const VERSION = '2.3.5';
const VERSION = '2.3.6';

/**
* A counter for template ids.
Expand Down
2 changes: 1 addition & 1 deletion mod/assign/feedback/editpdf/fpdi/Tfpdf/Fpdi.php
Expand Up @@ -30,7 +30,7 @@ class Fpdi extends FpdfTpl
*
* @string
*/
const VERSION = '2.3.5';
const VERSION = '2.3.6';

public function _enddoc()
{
Expand Down
3 changes: 1 addition & 2 deletions mod/assign/feedback/editpdf/fpdi/autoload.php
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions mod/assign/feedback/editpdf/fpdi/readme_moodle.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mod/assign/feedback/editpdf/thirdpartylibs.xml
Expand Up @@ -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>

0 comments on commit d934755

Please sign in to comment.