Mise à jour des dépendences

This commit is contained in:
Noizette 2020-10-24 00:24:16 +02:00
parent bfecdbfe98
commit 4b3fa030d8
180 changed files with 2026 additions and 737 deletions

View file

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

View file

@ -5,7 +5,6 @@ FPDI - Free PDF Document Importer
[![Total Downloads](https://poser.pugx.org/setasign/fpdi/downloads.svg)](https://packagist.org/packages/setasign/fpdi)
[![Latest Unstable Version](https://poser.pugx.org/setasign/fpdi/v/unstable.svg)](https://packagist.org/packages/setasign/fpdi)
[![License](https://poser.pugx.org/setasign/fpdi/license.svg)](https://packagist.org/packages/setasign/fpdi)
[![Build Status](https://travis-ci.org/Setasign/FPDI.svg?branch=development)](https://travis-ci.org/Setasign/FPDI)
:heavy_exclamation_mark: This document refers to FPDI 2. Version 1 is deprecated and development is discontinued. :heavy_exclamation_mark:
@ -18,75 +17,39 @@ FPDI can also be used as an extension for [TCPDF](https://github.com/tecnickcom/
## Installation with [Composer](https://packagist.org/packages/setasign/fpdi)
Because FPDI can be used with FPDF, TCPDF or tFPDF we didn't added a fixed dependency in the main
composer.json file but we added metadata packages for
[FPDF](https://github.com/Setasign/FPDI-FPDF),
[TCPDF](https://github.com/Setasign/FPDI-TCPDF) and
[tFPDF](https://github.com/Setasign/FPDI-tFPDF).
### Evaluate Dependencies Automatically
For FPDF add following [package](https://github.com/Setasign/FPDI-FPDF) to your composer.json:
```json
{
"require": {
"setasign/fpdi-fpdf": "^2.0"
}
}
```
For TCPDF add following [package](https://github.com/Setasign/FPDI-TCPDF) to your composer.json:
```json
{
"require": {
"setasign/fpdi-tcpdf": "^2.0"
}
}
```
For tFPDF add following [package](https://github.com/Setasign/FPDI-tFPDF) to your composer.json:
```json
{
"require": {
"setasign/fpdi-tfpdf": "^2.1"
}
}
```
### Manual Dependencies
If you don't want to use the metadata packages, it is up to you to add the dependencies to your
composer.json file.
Because FPDI can be used with FPDF, TCPDF or tFPDF we haven't added a fixed dependency in the main
composer.json file. You need to add the dependency to the PDF generation library of your choice
yourself.
To use FPDI with FPDF include following in your composer.json file:
```json
{
"require": {
"setasign/fpdf": "^1.8",
"setasign/fpdf": "1.8.*",
"setasign/fpdi": "^2.0"
}
}
```
If you want to use TCPDF, your have to update your composer.json respectively to:
If you want to use TCPDF, you have to update your composer.json to:
```json
{
"require": {
"tecnickcom/tcpdf": "^6.2",
"tecnickcom/tcpdf": "6.2.*",
"setasign/fpdi": "^2.0"
}
}
```
If you want to use tFPDF, your have to update your composer.json respectively to:
If you want to use tFPDF, you have to update your composer.json to:
```json
{
"require": {
"tecnickcom/tfpdf": "1.25",
"setasign/fpdi": "^2.1"
"setasign/tfpdf": "1.31.*",
"setasign/fpdi": "^2.3"
}
}
```
@ -165,4 +128,4 @@ $pdf->useTemplate($tplId, 10, 10, 100);
$pdf->Output();
```
A full end-user documentation and API reference is available [here](https://manuals.setasign.com/fpdi-manual/).
A full end-user documentation and API reference is available [here](https://manuals.setasign.com/fpdi-manual/).

View file

@ -0,0 +1,5 @@
## Security contact information
To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.

View file

@ -18,6 +18,9 @@
"php": "^5.6 || ^7.0",
"ext-zlib": "*"
},
"conflict": {
"setasign/tfpdf": "<1.31"
},
"authors": [
{
"name": "Jan Slabon",
@ -31,16 +34,14 @@
}
],
"suggest": {
"setasign/fpdf": "FPDI will extend this class but as it is also possible to use TCPDF or tFPDF as an alternative. There's no fixed dependency configured.",
"setasign/fpdi-fpdf": "Use this package to automatically evaluate dependencies to FPDF.",
"setasign/fpdi-tcpdf": "Use this package to automatically evaluate dependencies to TCPDF.",
"setasign/fpdi-tfpdf": "Use this package to automatically evaluate dependencies to tFPDF."
"setasign/fpdf": "FPDI will extend this class but as it is also possible to use TCPDF or tFPDF as an alternative. There's no fixed dependency configured."
},
"require-dev": {
"phpunit/phpunit": "~5.7",
"setasign/fpdf": "~1.8",
"tecnickcom/tcpdf": "~6.2",
"setasign/tfpdf": "1.25"
"setasign/tfpdf": "1.31",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload-dev": {
"psr-4": {

17
lib/MPDF/vendor/setasign/fpdi/phpcs.xml vendored Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<file>src</file>
<!-- <file>tests</file>-->
<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>
<rule ref="PSR12">
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>
</rule>
</ruleset>

View file

@ -0,0 +1,19 @@
parameters:
level: 5
paths:
- src
#- tests
ignoreErrors:
-
message: "#^Return typehint of method setasign\\\\Fpdi\\\\Fpdi\\:\\:getPdfParserInstance\\(\\) has invalid type setasign\\\\FpdiPdfParser\\\\PdfParser\\\\PdfParser\\.$#"
count: 1
path: src/Fpdi.php
-
message: "#^Return typehint of method setasign\\\\Fpdi\\\\Tcpdf\\\\Fpdi\\:\\:getPdfParserInstance\\(\\) has invalid type setasign\\\\FpdiPdfParser\\\\PdfParser\\\\PdfParser\\.$#"
count: 1
path: src/Tcpdf/Fpdi.php
-
message: "#^Return typehint of method setasign\\\\Fpdi\\\\Tfpdf\\\\Fpdi\\:\\:getPdfParserInstance\\(\\) has invalid type setasign\\\\FpdiPdfParser\\\\PdfParser\\\\PdfParser\\.$#"
count: 1
path: src/Tfpdf/Fpdi.php

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ namespace setasign\Fpdi;
* Class FpdfTpl
*
* This class adds a templating feature to FPDF.
*
* @package setasign\Fpdi
*/
class FpdfTpl extends \FPDF
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ namespace setasign\Fpdi;
* Trait FpdfTplTrait
*
* This class adds a templating feature to tFPDF.
*
* @package setasign\Fpdi
*/
trait FpdfTplTrait
{
@ -61,7 +60,8 @@ trait FpdfTplTrait
$size = $this->_getpagesize($size);
if ($orientation != $this->CurOrientation
if (
$orientation != $this->CurOrientation
|| $size[0] != $this->CurPageSize[0]
|| $size[1] != $this->CurPageSize[1]
) {
@ -109,7 +109,7 @@ trait FpdfTplTrait
unset($x['tpl']);
\extract($x, EXTR_IF_EXISTS);
/** @noinspection NotOptimalIfConditionsInspection */
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
/** @noinspection PhpConditionAlreadyCheckedInspection */
if (\is_array($x)) {
$x = 0;
}
@ -266,7 +266,7 @@ trait FpdfTplTrait
*/
public function endTemplate()
{
if (null === $this->currentTemplateId) {
if ($this->currentTemplateId === null) {
return false;
}
@ -418,7 +418,11 @@ trait FpdfTplTrait
$this->templates[$key]['objectNumber'] = $this->n;
$this->_put('<</Type /XObject /Subtype /Form /FormType 1');
$this->_put(\sprintf('/BBox[0 0 %.2F %.2F]', $template['width'] * $this->k, $template['height'] * $this->k));
$this->_put(\sprintf(
'/BBox[0 0 %.2F %.2F]',
$template['width'] * $this->k,
$template['height'] * $this->k
));
$this->_put('/Resources 2 0 R'); // default resources dictionary of FPDF
if ($this->compress) {
@ -463,4 +467,4 @@ trait FpdfTplTrait
parent::_out($s);
}
}
}
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -18,8 +19,6 @@ use setasign\Fpdi\PdfParser\Type\PdfNull;
* Class Fpdi
*
* This class let you import pages of existing PDF documents into a reusable structure for FPDF.
*
* @package setasign\Fpdi
*/
class Fpdi extends FpdfTpl
{
@ -30,7 +29,7 @@ class Fpdi extends FpdfTpl
*
* @string
*/
const VERSION = '2.2.0';
const VERSION = '2.3.4';
protected function _enddoc()
{
@ -113,7 +112,6 @@ class Fpdi extends FpdfTpl
while (($objectNumber = \array_pop($this->objectsToCopy[$readerId])) !== null) {
try {
$object = $parser->getIndirectObject($objectNumber);
} catch (CrossReferenceException $e) {
if ($e->getCode() === CrossReferenceException::OBJECT_NOT_FOUND) {
$object = PdfIndirectObject::create($objectNumber, 0, new PdfNull());

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi;
/**
* Base exception class for the FPDI package.
*
* @package setasign\Fpdi
*/
class FpdiException extends \Exception
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -41,8 +42,6 @@ use /* This namespace/class is used by the commercial FPDI PDF-Parser add-on. */
*
* This trait offers the core functionalities of FPDI. By passing them to a trait we can reuse it with e.g. TCPDF in a
* very easy way.
*
* @package setasign\Fpdi
*/
trait FpdiTrait
{
@ -63,7 +62,7 @@ trait FpdiTrait
/**
* The current reader id.
*
* @var string
* @var string|null
*/
protected $currentReaderId;
@ -104,7 +103,7 @@ trait FpdiTrait
unset($this->readers[$id]);
}
$this->createdReaders= [];
$this->createdReaders = [];
}
/**
@ -299,7 +298,7 @@ trait FpdiTrait
if ($rotation !== 0) {
$rotation *= -1;
$angle = $rotation * M_PI/180;
$angle = $rotation * M_PI / 180;
$a = \cos($angle);
$b = \sin($angle);
$c = -$b;
@ -336,7 +335,8 @@ trait FpdiTrait
$contents = PdfType::resolve($contentsObject, $reader->getParser());
// just copy the stream reference if it is only a single stream
if (($contentsIsStream = ($contents instanceof PdfStream))
if (
($contentsIsStream = ($contents instanceof PdfStream))
|| ($contents instanceof PdfArray && \count($contents->value) === 1)
) {
if ($contentsIsStream) {
@ -494,26 +494,20 @@ trait FpdiTrait
} else {
$this->_put(\rtrim(\rtrim(\sprintf('%.5F', $value->value), '0'), '.') . ' ', false);
}
} elseif ($value instanceof PdfName) {
$this->_put('/' . $value->value . ' ', false);
} elseif ($value instanceof PdfString) {
$this->_put('(' . $value->value . ')', false);
} elseif ($value instanceof PdfHexString) {
$this->_put('<' . $value->value . '>');
} elseif ($value instanceof PdfBoolean) {
$this->_put($value->value ? 'true ' : 'false ', false);
} elseif ($value instanceof PdfArray) {
$this->_put('[', false);
foreach ($value->value as $entry) {
$this->writePdfType($entry);
}
$this->_put(']');
} elseif ($value instanceof PdfDictionary) {
$this->_put('<<', false);
foreach ($value->value as $name => $entry) {
@ -521,13 +515,10 @@ trait FpdiTrait
$this->writePdfType($entry);
}
$this->_put('>>');
} elseif ($value instanceof PdfToken) {
$this->_put($value->value);
} elseif ($value instanceof PdfNull) {
$this->_put('null ');
} elseif ($value instanceof PdfStream) {
/**
* @var $value PdfStream
@ -536,7 +527,6 @@ trait FpdiTrait
$this->_put('stream');
$this->_put($value->getStream());
$this->_put('endstream');
} elseif ($value instanceof PdfIndirectObjectReference) {
if (!isset($this->objectMap[$this->currentReaderId])) {
$this->objectMap[$this->currentReaderId] = [];
@ -548,10 +538,9 @@ trait FpdiTrait
}
$this->_put($this->objectMap[$this->currentReaderId][$value->value] . ' 0 R ', false);
} elseif ($value instanceof PdfIndirectObject) {
/**
* @var $value PdfIndirectObject
* @var PdfIndirectObject $value
*/
$n = $this->objectMap[$this->currentReaderId][$value->objectNumber];
$this->_newobj($n);

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -16,8 +17,6 @@ use setasign\Fpdi\PdfParser\Type\PdfTypeException;
/**
* Abstract class for cross-reference reader classes.
*
* @package setasign\Fpdi\PdfParser\CrossReference
*/
abstract class AbstractReader
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -21,8 +22,6 @@ use setasign\Fpdi\PdfParser\Type\PdfTypeException;
* Class CrossReference
*
* This class processes the standard cross reference of a PDF document.
*
* @package setasign\Fpdi\PdfParser\CrossReference
*/
class CrossReference
{
@ -31,7 +30,7 @@ class CrossReference
*
* @var int
*/
static public $trailerSearchLength = 5500;
public static $trailerSearchLength = 5500;
/**
* @var int
@ -235,8 +234,15 @@ class CrossReference
}
if ($initValue instanceof PdfIndirectObject) {
// check for encryption
$stream = PdfStream::ensure($initValue->value);
try {
$stream = PdfStream::ensure($initValue->value);
} catch (PdfTypeException $e) {
throw new CrossReferenceException(
'Invalid object type at xref reference offset.',
CrossReferenceException::INVALID_DATA,
$e
);
}
$type = PdfDictionary::get($stream->value, 'Type');
if ($type->value !== 'XRef') {

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\PdfParser\PdfParserException;
/**
* Exception used by the CrossReference and Reader classes.
*
* @package setasign\Fpdi\PdfParser\CrossReference
*/
class CrossReferenceException extends PdfParserException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -17,8 +18,6 @@ use setasign\Fpdi\PdfParser\StreamReader;
*
* This reader allows a very less overhead parsing of single entries of the cross-reference, because the main entries
* are only read when needed and not in a single run.
*
* @package setasign\Fpdi\PdfParser\CrossReference
*/
class FixedReader extends AbstractReader implements ReaderInterface
{
@ -63,6 +62,10 @@ class FixedReader extends AbstractReader implements ReaderInterface
public function getOffsetFor($objectNumber)
{
foreach ($this->subSections as $offset => list($startObject, $objectCount)) {
/**
* @var int $startObject
* @var int $objectCount
*/
if ($objectNumber >= $startObject && $objectNumber < ($startObject + $objectCount)) {
$position = $offset + 20 * ($objectNumber - $startObject);
$this->reader->ensure($position, 20);

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -17,8 +18,6 @@ use setasign\Fpdi\PdfParser\StreamReader;
*
* This reader class read all cross-reference entries in a single run.
* It supports reading cross-references with e.g. invalid data (e.g. entries with a length < or > 20 bytes).
*
* @package setasign\Fpdi\PdfParser\CrossReference
*/
class LineReader extends AbstractReader implements ReaderInterface
{
@ -72,18 +71,16 @@ class LineReader extends AbstractReader implements ReaderInterface
*/
protected function extract(StreamReader $reader)
{
$cycles = -1;
$bytesPerCycle = 100;
$reader->reset(null, $bytesPerCycle);
while (
($trailerPos = \strpos($reader->getBuffer(false), 'trailer', \max($bytesPerCycle * $cycles++, 0))) === false
) {
if ($reader->increaseLength($bytesPerCycle) === false) {
break;
}
}
$cycles = 0;
do {
// 6 = length of "trailer" - 1
$pos = \max(($bytesPerCycle * $cycles) - 6, 0);
$trailerPos = \strpos($reader->getBuffer(false), 'trailer', $pos);
$cycles++;
} while ($trailerPos === false && $reader->increaseLength($bytesPerCycle) !== false);
if ($trailerPos === false) {
throw new CrossReferenceException(
@ -127,44 +124,41 @@ class LineReader extends AbstractReader implements ReaderInterface
}
unset($differentLineEndings, $m);
$linesCount = \count($lines);
$start = null;
$entryCount = 0;
if (!\is_array($lines)) {
$this->offsets = [];
return;
}
$start = 0;
$offsets = [];
/** @noinspection ForeachInvariantsInspection */
for ($i = 0; $i < $linesCount; $i++) {
$line = \trim($lines[$i]);
if ($line) {
$pieces = \explode(' ', $line);
// trim all lines and remove empty lines
$lines = \array_filter(\array_map('\trim', $lines));
foreach ($lines as $line) {
$pieces = \explode(' ', $line);
$c = \count($pieces);
switch ($c) {
case 2:
$start = (int) $pieces[0];
$entryCount += (int) $pieces[1];
break;
switch (\count($pieces)) {
case 2:
$start = (int) $pieces[0];
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 3:
switch ($pieces[2]) {
case 'n':
$offsets[$start] = [(int) $pieces[0], (int) $pieces[1]];
$start++;
break 2;
case 'f':
$start++;
break 2;
}
// fall through if pieces doesn't match
case 3:
switch ($pieces[2]) {
case 'n':
$offsets[$start] = [(int) $pieces[0], (int) $pieces[1]];
$start++;
break 2;
case 'f':
$start++;
break 2;
}
// fall through if pieces doesn't match
default:
throw new CrossReferenceException(
\sprintf('Unexpected data in xref table (%s)', \implode(' ', $pieces)),
CrossReferenceException::INVALID_DATA
);
}
default:
throw new CrossReferenceException(
\sprintf('Unexpected data in xref table (%s)', \implode(' ', $pieces)),
CrossReferenceException::INVALID_DATA
);
}
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\PdfParser\Type\PdfDictionary;
/**
* ReaderInterface for cross-reference readers.
*
* @package setasign\Fpdi\PdfParser\CrossReference
*/
interface ReaderInterface
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Class for handling ASCII base-85 encoded data
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class Ascii85 implements FilterInterface
{
@ -29,6 +28,8 @@ class Ascii85 implements FilterInterface
$state = 0;
$chn = null;
$data = \preg_replace('/\s/', '', $data);
$l = \strlen($data);
/** @noinspection ForeachInvariantsInspection */
@ -44,13 +45,12 @@ class Ascii85 implements FilterInterface
if ($ch === 126 && isset($data[$k + 1]) && (\ord($data[$k + 1]) & 0xFF) === 62) {
break;
}
if (\preg_match('/^\s$/', \chr($ch))) {
continue;
}
if ($ch === 122 /* z */ && $state === 0) {
$out .= \chr(0) . \chr(0) . \chr(0) . \chr(0);
continue;
}
if ($ch < 33 /* ! */ || $ch > 117 /* u */) {
throw new Ascii85Exception(
'Illegal character found while ASCII85 decode.',
@ -86,12 +86,10 @@ class Ascii85 implements FilterInterface
if ($state === 2) {
$r = $chn[0] * 85 * 85 * 85 * 85 + ($chn[1] + 1) * 85 * 85 * 85;
$out .= \chr($r >> 24);
} elseif ($state === 3) {
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + ($chn[2] + 1) * 85 * 85;
$out .= \chr($r >> 24);
$out .= \chr($r >> 16);
} elseif ($state === 4) {
$r = $chn[0] * 85 * 85 * 85 * 85 + $chn[1] * 85 * 85 * 85 + $chn[2] * 85 * 85 + ($chn[3] + 1) * 85;
$out .= \chr($r >> 24);

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Exception for Ascii85 filter class
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class Ascii85Exception extends FilterException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Class for handling ASCII hexadecimal encoded data
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class AsciiHex implements FilterInterface
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\PdfParser\PdfParserException;
/**
* Exception for filters
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class FilterException extends PdfParserException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Interface for filters
*
* @package setasign\Fpdi\PdfParser\Filter
*/
interface FilterInterface
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Class for handling zlib/deflate encoded data
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class Flate implements FilterInterface
{
@ -32,7 +31,7 @@ class Flate implements FilterInterface
/**
* Decodes a flate compressed string.
*
* @param string $data The input string
* @param string|false $data The input string
* @return string
* @throws FlateException
*/
@ -40,23 +39,32 @@ class Flate implements FilterInterface
{
if ($this->extensionLoaded()) {
$oData = $data;
$data = @((\strlen($data) > 0) ? \gzuncompress($data) : '');
$data = (($data !== '') ? @\gzuncompress($data) : '');
if ($data === false) {
// let's try if the checksum is CRC32
$fh = fopen('php://temp', 'w+b');
fwrite($fh, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $oData);
stream_filter_append($fh, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 30]);
fseek($fh, 0);
$data = @stream_get_contents($fh);
fclose($fh);
if ($data) {
return $data;
}
// Try this fallback
$tries = 1;
while ($tries < 10 && ($data === false || \strlen($data) < (\strlen($oData) - $tries - 1))) {
$data = @(\gzinflate(\substr($oData, $tries)));
$tries = 0;
$oDataLen = strlen($oData);
while ($tries < 6 && ($data === false || (strlen($data) < ($oDataLen - $tries - 1)))) {
$data = @(gzinflate(substr($oData, $tries)));
$tries++;
}
if ($data === false) {
// let's try if the checksum is CRC32
$fh = fopen('php://temp', 'w+b');
\fwrite($fh, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $oData);
\stream_filter_append($fh, 'zlib.inflate', \STREAM_FILTER_READ, ['window' => 30]);
\fseek($fh, 0);
$data = \stream_get_contents($fh);
\fclose($fh);
// let's use this fallback only if the $data is longer than the original data
if (strlen($data) > ($oDataLen - $tries - 1)) {
return $data;
}
if (!$data) {

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Exception for flate filter class
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class FlateException extends FilterException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Class for handling LZW encoded data
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class Lzw implements FilterInterface
{
@ -103,7 +102,6 @@ class Lzw implements FilterInterface
$uncompData .= $this->sTable[$code];
$oldCode = $code;
} else {
if ($code < $this->tIdx) {
$string = $this->sTable[$code];

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Filter;
/**
* Exception for LZW filter class
*
* @package setasign\Fpdi\PdfParser\Filter
*/
class LzwException extends FilterException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -20,14 +21,13 @@ use setasign\Fpdi\PdfParser\Type\PdfIndirectObjectReference;
use setasign\Fpdi\PdfParser\Type\PdfName;
use setasign\Fpdi\PdfParser\Type\PdfNull;
use setasign\Fpdi\PdfParser\Type\PdfNumeric;
use setasign\Fpdi\PdfParser\Type\PdfStream;
use setasign\Fpdi\PdfParser\Type\PdfString;
use setasign\Fpdi\PdfParser\Type\PdfToken;
use setasign\Fpdi\PdfParser\Type\PdfType;
/**
* A PDF parser class
*
* @package setasign\Fpdi\PdfParser
*/
class PdfParser
{
@ -56,7 +56,7 @@ class PdfParser
protected $fileHeaderOffset;
/**
* @var CrossReference
* @var CrossReference|null
*/
protected $xref;
@ -121,7 +121,6 @@ class PdfParser
}
$this->streamReader->reset(0);
$offset = false;
$maxIterations = 1000;
while (true) {
$buffer = $this->streamReader->getBuffer(false);
@ -181,7 +180,10 @@ class PdfParser
$catalog = $this->getCatalog();
if (isset($catalog->value['Version'])) {
$versionParts = \explode('.', PdfName::unescape(PdfType::resolve($catalog->value['Version'], $this)->value));
$versionParts = \explode(
'.',
PdfName::unescape(PdfType::resolve($catalog->value['Version'], $this)->value)
);
if (count($versionParts) === 2) {
list($major, $minor) = $versionParts;
}
@ -200,8 +202,7 @@ class PdfParser
*/
public function getCatalog()
{
$xref = $this->getCrossReference();
$trailer = $xref->getTrailer();
$trailer = $this->getCrossReference()->getTrailer();
$catalog = PdfType::resolve(PdfDictionary::get($trailer, 'Root'), $this);
@ -224,8 +225,7 @@ class PdfParser
return $this->objects[$objectNumber];
}
$xref = $this->getCrossReference();
$object = $xref->getIndirectObject($objectNumber);
$object = $this->getCrossReference()->getIndirectObject($objectNumber);
if ($cache) {
$this->objects[$objectNumber] = $object;
@ -239,7 +239,7 @@ class PdfParser
*
* @param null|bool|string $token
* @param null|string $expectedType
* @return bool|PdfArray|PdfBoolean|PdfHexString|PdfName|PdfNull|PdfNumeric|PdfString|PdfToken|PdfIndirectObjectReference
* @return false|PdfArray|PdfBoolean|PdfDictionary|PdfHexString|PdfIndirectObject|PdfIndirectObjectReference|PdfName|PdfNull|PdfNumeric|PdfStream|PdfString|PdfToken
* @throws Type\PdfTypeException
*/
public function readValue($token = null, $expectedType = null)
@ -281,37 +281,38 @@ class PdfParser
default:
if (\is_numeric($token)) {
if (($token2 = $this->tokenizer->getNextToken()) !== false) {
if (\is_numeric($token2)) {
if (($token3 = $this->tokenizer->getNextToken()) !== false) {
switch ($token3) {
case 'obj':
if ($expectedType !== null && $expectedType !== PdfIndirectObject::class) {
throw new Type\PdfTypeException(
'Got unexpected token type.', Type\PdfTypeException::INVALID_DATA_TYPE
);
}
return PdfIndirectObject::parse(
$token,
$token2,
$this,
$this->tokenizer,
$this->streamReader
if (\is_numeric($token2) && ($token3 = $this->tokenizer->getNextToken()) !== false) {
switch ($token3) {
case 'obj':
if ($expectedType !== null && $expectedType !== PdfIndirectObject::class) {
throw new Type\PdfTypeException(
'Got unexpected token type.',
Type\PdfTypeException::INVALID_DATA_TYPE
);
case 'R':
if ($expectedType !== null &&
$expectedType !== PdfIndirectObjectReference::class
) {
throw new Type\PdfTypeException(
'Got unexpected token type.', Type\PdfTypeException::INVALID_DATA_TYPE
);
}
}
return PdfIndirectObjectReference::create($token, $token2);
}
return PdfIndirectObject::parse(
(int) $token,
(int) $token2,
$this,
$this->tokenizer,
$this->streamReader
);
case 'R':
if (
$expectedType !== null &&
$expectedType !== PdfIndirectObjectReference::class
) {
throw new Type\PdfTypeException(
'Got unexpected token type.',
Type\PdfTypeException::INVALID_DATA_TYPE
);
}
$this->tokenizer->pushStack($token3);
return PdfIndirectObjectReference::create((int) $token, (int) $token2);
}
$this->tokenizer->pushStack($token3);
}
$this->tokenizer->pushStack($token2);
@ -319,10 +320,11 @@ class PdfParser
if ($expectedType !== null && $expectedType !== PdfNumeric::class) {
throw new Type\PdfTypeException(
'Got unexpected token type.', Type\PdfTypeException::INVALID_DATA_TYPE
'Got unexpected token type.',
Type\PdfTypeException::INVALID_DATA_TYPE
);
}
return PdfNumeric::create($token);
return PdfNumeric::create($token + 0);
}
if ($token === 'true' || $token === 'false') {
@ -337,7 +339,8 @@ class PdfParser
if ($expectedType !== null && $expectedType !== PdfToken::class) {
throw new Type\PdfTypeException(
'Got unexpected token type.', Type\PdfTypeException::INVALID_DATA_TYPE
'Got unexpected token type.',
Type\PdfTypeException::INVALID_DATA_TYPE
);
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\FpdiException;
/**
* Exception for the pdf parser class
*
* @package setasign\Fpdi\PdfParser
*/
class PdfParserException extends FpdiException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser;
/**
* A stream reader class
*
* @package setasign\Fpdi\PdfParser
*/
class StreamReader
{
@ -192,8 +191,9 @@ class StreamReader
public function getByte($position = null)
{
$position = (int) ($position !== null ? $position : $this->offset);
if ($position >= $this->bufferLength &&
(!$this->increaseLength() || $position >= $this->bufferLength)
if (
$position >= $this->bufferLength
&& (!$this->increaseLength() || $position >= $this->bufferLength)
) {
return false;
}
@ -226,8 +226,9 @@ class StreamReader
$offset = $this->offset;
}
if ($offset >= $this->bufferLength &&
((!$this->increaseLength()) || $offset >= $this->bufferLength)
if (
$offset >= $this->bufferLength
&& ((!$this->increaseLength()) || $offset >= $this->bufferLength)
) {
return false;
}
@ -245,7 +246,7 @@ class StreamReader
*
* @param int $length
* @param int|null $position
* @return string
* @return string|false
*/
public function readBytes($length, $position = null)
{
@ -262,8 +263,9 @@ class StreamReader
$offset = $this->offset;
}
if (($offset + $length) > $this->bufferLength &&
((!$this->increaseLength($length)) || ($offset + $length) > $this->bufferLength)
if (
($offset + $length) > $this->bufferLength
&& ((!$this->increaseLength($length)) || ($offset + $length) > $this->bufferLength)
) {
return false;
}
@ -433,7 +435,8 @@ class StreamReader
*/
public function ensure($pos, $length)
{
if ($pos >= $this->position
if (
$pos >= $this->position
&& $pos < ($this->position + $this->bufferLength)
&& ($this->position + $this->bufferLength) >= ($pos + $length)
) {

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser;
/**
* A tokenizer class.
*
* @package setasign\Fpdi\PdfParser
*/
class Tokenizer
{
@ -82,13 +81,7 @@ class Tokenizer
return false;
}
if ($byte === "\x20" ||
$byte === "\x0A" ||
$byte === "\x0D" ||
$byte === "\x0C" ||
$byte === "\x09" ||
$byte === "\x00"
) {
if (\in_array($byte, ["\x20", "\x0A", "\x0D", "\x0C", "\x09", "\x00"], true)) {
if ($this->leapWhiteSpaces() === false) {
return false;
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -15,7 +16,6 @@ use setasign\Fpdi\PdfParser\Tokenizer;
/**
* Class representing a PDF array object
*
* @package setasign\Fpdi\PdfParser\Type
* @property array $value The value of the PDF type.
*/
class PdfArray extends PdfType
@ -41,7 +41,7 @@ class PdfArray extends PdfType
$result[] = $value;
}
$v = new self;
$v = new self();
$v->value = $result;
return $v;
@ -55,7 +55,7 @@ class PdfArray extends PdfType
*/
public static function create(array $values = [])
{
$v = new self;
$v = new self();
$v->value = $values;
return $v;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Type;
/**
* Class representing a boolean PDF object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfBoolean extends PdfType
{
@ -24,8 +23,8 @@ class PdfBoolean extends PdfType
*/
public static function create($value)
{
$v = new self;
$v->value = (boolean) $value;
$v = new self();
$v->value = (bool) $value;
return $v;
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -15,8 +16,6 @@ use setasign\Fpdi\PdfParser\Tokenizer;
/**
* Class representing a PDF dictionary object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfDictionary extends PdfType
{
@ -79,7 +78,7 @@ class PdfDictionary extends PdfType
$entries[$key->value] = $value;
}
$v = new self;
$v = new self();
$v->value = $entries;
return $v;
@ -93,7 +92,7 @@ class PdfDictionary extends PdfType
*/
public static function create(array $entries = [])
{
$v = new self;
$v = new self();
$v->value = $entries;
return $v;
@ -104,7 +103,7 @@ class PdfDictionary extends PdfType
*
* @param mixed $dictionary
* @param string $key
* @param PdfType|mixed|null $default
* @param PdfType|null $default
* @return PdfNull|PdfType
* @throws PdfTypeException
*/

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\PdfParser\StreamReader;
/**
* Class representing a hexadecimal encoded PDF string object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfHexString extends PdfType
{
@ -28,10 +27,6 @@ class PdfHexString extends PdfType
{
$bufferOffset = $streamReader->getOffset();
/**
* @var string $buffer
* @var int $pos
*/
while (true) {
$buffer = $streamReader->getBuffer(false);
$pos = \strpos($buffer, '>', $bufferOffset);
@ -48,7 +43,7 @@ class PdfHexString extends PdfType
$result = \substr($buffer, $bufferOffset, $pos - $bufferOffset);
$streamReader->setOffset($pos + 1);
$v = new self;
$v = new self();
$v->value = $result;
return $v;
@ -62,7 +57,7 @@ class PdfHexString extends PdfType
*/
public static function create($string)
{
$v = new self;
$v = new self();
$v->value = $string;
return $v;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -15,8 +16,6 @@ use setasign\Fpdi\PdfParser\Tokenizer;
/**
* Class representing an indirect object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfIndirectObject extends PdfType
{
@ -50,7 +49,7 @@ class PdfIndirectObject extends PdfType
$tokenizer->pushStack($nextToken);
}
$v = new self;
$v = new self();
$v->objectNumber = (int) $objectNumberToken;
$v->generationNumber = (int) $objectGenerationNumberToken;
$v->value = $value;
@ -68,7 +67,7 @@ class PdfIndirectObject extends PdfType
*/
public static function create($objectNumber, $generationNumber, PdfType $value)
{
$v = new self;
$v = new self();
$v->objectNumber = (int) $objectNumber;
$v->generationNumber = (int) $generationNumber;
$v->value = $value;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Type;
/**
* Class representing an indirect object reference
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfIndirectObjectReference extends PdfType
{
@ -25,7 +24,7 @@ class PdfIndirectObjectReference extends PdfType
*/
public static function create($objectNumber, $generationNumber)
{
$v = new self;
$v = new self();
$v->value = (int) $objectNumber;
$v->generationNumber = (int) $generationNumber;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -14,8 +15,6 @@ use setasign\Fpdi\PdfParser\Tokenizer;
/**
* Class representing a PDF name object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfName extends PdfType
{
@ -28,7 +27,7 @@ class PdfName extends PdfType
*/
public static function parse(Tokenizer $tokenizer, StreamReader $streamReader)
{
$v = new self;
$v = new self();
if (\strspn($streamReader->getByte(), "\x00\x09\x0A\x0C\x0D\x20()<>[]{}/%") === 0) {
$v->value = (string) $tokenizer->getNextToken();
return $v;
@ -44,13 +43,14 @@ class PdfName extends PdfType
* @param string $value
* @return string
*/
static public function unescape($value)
public static function unescape($value)
{
if (strpos($value, '#') === false)
if (strpos($value, '#') === false) {
return $value;
}
return preg_replace_callback('/#[a-fA-F\d]{2}/', function($matches) {
return chr(hexdec($matches[0]));
return preg_replace_callback('/#([a-fA-F\d]{2})/', function ($matches) {
return chr(hexdec($matches[1]));
}, $value);
}
@ -62,7 +62,7 @@ class PdfName extends PdfType
*/
public static function create($string)
{
$v = new self;
$v = new self();
$v->value = $string;
return $v;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Type;
/**
* Class representing a PDF null object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfNull extends PdfType
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Type;
/**
* Class representing a numeric PDF object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfNumeric extends PdfType
{
@ -24,7 +23,7 @@ class PdfNumeric extends PdfType
*/
public static function create($value)
{
$v = new self;
$v = new self();
$v->value = $value + 0;
return $v;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -22,8 +23,6 @@ use setasign\FpdiPdfParser\PdfParser\Filter\Predictor;
/**
* Class representing a PDF stream object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfStream extends PdfType
{
@ -38,7 +37,7 @@ class PdfStream extends PdfType
*/
public static function parse(PdfDictionary $dictionary, StreamReader $reader, PdfParser $parser = null)
{
$v = new self;
$v = new self();
$v->value = $dictionary;
$v->reader = $reader;
$v->parser = $parser;
@ -54,7 +53,7 @@ class PdfStream extends PdfType
}
}
if (false === $firstByte) {
if ($firstByte === false) {
throw new PdfTypeException(
'Unable to parse stream data. No newline after the stream keyword found.',
PdfTypeException::NO_NEWLINE_AFTER_STREAM_KEYWORD
@ -86,7 +85,7 @@ class PdfStream extends PdfType
*/
public static function create(PdfDictionary $dictionary, $stream)
{
$v = new self;
$v = new self();
$v->value = $dictionary;
$v->stream = (string) $stream;
@ -115,7 +114,7 @@ class PdfStream extends PdfType
/**
* The stream reader instance.
*
* @var StreamReader
* @var StreamReader|null
*/
protected $reader;
@ -208,6 +207,13 @@ class PdfStream extends PdfType
}
}
// There are streams in the wild, which have only white signs in them but need to be parsed manually due
// to a problem encountered before (e.g. Length === 0). We should set them to empty streams to avoid problems
// in further processing (e.g. applying of filters).
if (trim($buffer) === '') {
$buffer = '';
}
return $buffer;
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\PdfParser\StreamReader;
/**
* Class representing a PDF string object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfString extends PdfType
{
@ -47,7 +46,7 @@ class PdfString extends PdfType
$result = \substr($buffer, $startPos, $openBrackets + $pos - $startPos - 1);
$streamReader->setOffset($pos);
$v = new self;
$v = new self();
$v->value = $result;
return $v;
@ -61,7 +60,7 @@ class PdfString extends PdfType
*/
public static function create($value)
{
$v = new self;
$v = new self();
$v->value = $value;
return $v;
@ -138,22 +137,23 @@ class PdfString extends PdfType
$actualChar = \ord($s[$count]);
// ascii 48 = number 0
// ascii 57 = number 9
if ($actualChar >= 48 &&
$actualChar <= 57) {
if ($actualChar >= 48 && $actualChar <= 57) {
$oct = '' . $s[$count];
/** @noinspection NotOptimalIfConditionsInspection */
if ($count + 1 < $n &&
\ord($s[$count + 1]) >= 48 &&
\ord($s[$count + 1]) <= 57
if (
$count + 1 < $n
&& \ord($s[$count + 1]) >= 48
&& \ord($s[$count + 1]) <= 57
) {
$count++;
$oct .= $s[$count];
/** @noinspection NotOptimalIfConditionsInspection */
if ($count + 1 < $n &&
\ord($s[$count + 1]) >= 48 &&
\ord($s[$count + 1]) <= 57
if (
$count + 1 < $n
&& \ord($s[$count + 1]) >= 48
&& \ord($s[$count + 1]) <= 57
) {
$oct .= $s[++$count];
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfParser\Type;
/**
* Class representing PDF token object
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfToken extends PdfType
{
@ -24,7 +23,7 @@ class PdfToken extends PdfType
*/
public static function create($token)
{
$v = new self;
$v = new self();
$v->value = $token;
return $v;

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -15,8 +16,6 @@ use setasign\Fpdi\PdfParser\PdfParserException;
/**
* A class defining a PDF data type
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfType
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\PdfParser\PdfParserException;
/**
* Exception class for pdf type classes
*
* @package setasign\Fpdi\PdfParser\Type
*/
class PdfTypeException extends PdfParserException
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -19,8 +20,6 @@ use setasign\Fpdi\PdfParser\Type\PdfTypeException;
/**
* Class representing a rectangle
*
* @package setasign\Fpdi\PdfReader\DataStructure
*/
class Rectangle
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -25,8 +26,6 @@ use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
/**
* Class representing a page of a PDF document
*
* @package setasign\Fpdi\PdfReader
*/
class Page
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -11,8 +12,6 @@ namespace setasign\Fpdi\PdfReader;
/**
* An abstract class for page boundary constants and some helper methods
*
* @package setasign\Fpdi\PdfReader
*/
abstract class PageBoundaries
{

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -14,6 +15,7 @@ use setasign\Fpdi\PdfParser\PdfParser;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfParser\Type\PdfArray;
use setasign\Fpdi\PdfParser\Type\PdfDictionary;
use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
use setasign\Fpdi\PdfParser\Type\PdfIndirectObjectReference;
use setasign\Fpdi\PdfParser\Type\PdfNumeric;
use setasign\Fpdi\PdfParser\Type\PdfType;
@ -21,8 +23,6 @@ use setasign\Fpdi\PdfParser\Type\PdfTypeException;
/**
* A PDF reader class
*
* @package setasign\Fpdi\PdfReader
*/
class PdfReader
{
@ -39,7 +39,7 @@ class PdfReader
/**
* Indirect objects of resolved pages.
*
* @var PdfIndirectObjectReference[]
* @var PdfIndirectObjectReference[]|PdfIndirectObject[]
*/
protected $pages = [];
@ -59,7 +59,6 @@ class PdfReader
public function __destruct()
{
if ($this->parser !== null) {
/** @noinspection PhpInternalEntityUsedInspection */
$this->parser->cleanUp();
}
}
@ -165,9 +164,22 @@ class PdfReader
$page = $this->parser->getIndirectObject($page->value);
$dict = PdfType::resolve($page, $this->parser);
$type = PdfDictionary::get($dict, 'Type');
if ($type->value === 'Pages') {
$kids = PdfType::resolve(PdfDictionary::get($dict, 'Kids'), $this->parser);
$page = $this->pages[$pageNumber - 1] = $readPages($kids);
try {
$page = $this->pages[$pageNumber - 1] = $readPages($kids);
} catch (PdfReaderException $e) {
if ($e->getCode() !== PdfReaderException::KIDS_EMPTY) {
throw $e;
}
// let's reset the pages array and read all page objects
$this->pages = [];
$this->readPages(true);
// @phpstan-ignore-next-line
$page = $this->pages[$pageNumber - 1];
}
} else {
$this->pages[$pageNumber - 1] = $page;
}
@ -179,24 +191,25 @@ class PdfReader
/**
* Walk the page tree and resolve all indirect objects of all pages.
*
* @throws PdfTypeException
* @param bool $readAll
* @throws CrossReferenceException
* @throws PdfParserException
* @throws PdfTypeException
*/
protected function readPages()
protected function readPages($readAll = false)
{
if (\count($this->pages) > 0) {
return;
}
$readPages = function ($kids, $count) use (&$readPages) {
$readPages = function ($kids, $count) use (&$readPages, $readAll) {
$kids = PdfArray::ensure($kids);
$isLeaf = $count->value === \count($kids->value);
$isLeaf = ($count->value === \count($kids->value));
foreach ($kids->value as $reference) {
$reference = PdfIndirectObjectReference::ensure($reference);
if ($isLeaf) {
if (!$readAll && $isLeaf) {
$this->pages[] = $reference;
continue;
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -13,8 +14,6 @@ use setasign\Fpdi\FpdiException;
/**
* Exception for the pdf reader class
*
* @package setasign\Fpdi\PdfReader
*/
class PdfReaderException extends FpdiException
{

View file

@ -1,5 +1,13 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
namespace setasign\Fpdi\Tcpdf;
use setasign\Fpdi\FpdiTrait;
@ -20,7 +28,7 @@ use setasign\Fpdi\PdfParser\Type\PdfTypeException;
*
* This class let you import pages of existing PDF documents into a reusable structure for TCPDF.
*
* @package setasign\Fpdi
* @method _encrypt_data(int $n, string $s) string
*/
class Fpdi extends \TCPDF
{
@ -34,7 +42,7 @@ class Fpdi extends \TCPDF
*
* @string
*/
const VERSION = '2.2.0';
const VERSION = '2.3.4';
/**
* A counter for template ids.
@ -46,7 +54,7 @@ class Fpdi extends \TCPDF
/**
* The currently used object number.
*
* @var int
* @var int|null
*/
protected $currentObjectNumber;
@ -166,7 +174,6 @@ class Fpdi extends \TCPDF
while (($objectNumber = \array_pop($this->objectsToCopy[$readerId])) !== null) {
try {
$object = $parser->getIndirectObject($objectNumber);
} catch (CrossReferenceException $e) {
if ($e->getCode() === CrossReferenceException::OBJECT_NOT_FOUND) {
$object = PdfIndirectObject::create($objectNumber, 0, new PdfNull());
@ -240,27 +247,24 @@ class Fpdi extends \TCPDF
$string = PdfString::unescape($value->value);
$string = $this->_encrypt_data($this->currentObjectNumber, $string);
$value->value = \TCPDF_STATIC::_escape($string);
} elseif ($value instanceof PdfHexString) {
$filter = new AsciiHex();
$string = $filter->decode($value->value);
$string = $this->_encrypt_data($this->currentObjectNumber, $string);
$value->value = $filter->encode($string, true);
} elseif ($value instanceof PdfStream) {
$stream = $value->getStream();
$stream = $this->_encrypt_data($this->currentObjectNumber, $stream);
$dictionary = $value->value;
$dictionary->value['Length'] = PdfNumeric::create(\strlen($stream));
$value = PdfStream::create($dictionary, $stream);
} elseif ($value instanceof PdfIndirectObject) {
/**
* @var $value PdfIndirectObject
* @var PdfIndirectObject $value
*/
$this->currentObjectNumber = $this->objectMap[$this->currentReaderId][$value->objectNumber];
}
$this->fpdiWritePdfType($value);
}
}
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -14,7 +15,6 @@ namespace setasign\Fpdi;
*
* This class let you import pages of existing PDF documents into a reusable structure for TCPDF.
*
* @package setasign\Fpdi
* @deprecated Class was moved to \setasign\Fpdi\Tcpdf\Fpdi
*/
class TcpdfFpdi extends \setasign\Fpdi\Tcpdf\Fpdi

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -15,85 +16,8 @@ use setasign\Fpdi\FpdfTplTrait;
* Class FpdfTpl
*
* We need to change some access levels and implement the setPageFormat() method to bring back compatibility to tFPDF.
*
* @package setasign\Fpdi\Tfpdf
*/
class FpdfTpl extends \tFPDF
{
use FpdfTplTrait {
_putimages as _protectedPutimages;
_putxobjectdict as _protectedPutxobjectdict;
}
/**
* Make the method public as in tFPDF.
*/
public function _putimages()
{
$this->_protectedPutimages();
}
/**
* Make the method public as in tFPDF.
*/
public function _putxobjectdict()
{
$this->_protectedPutxobjectdict();
}
/**
* Set the page format of the current page.
*
* @param array $size An array with two values defining the size.
* @param string $orientation "L" for landscape, "P" for portrait.
* @throws \BadMethodCallException
*/
public function setPageFormat($size, $orientation)
{
if ($this->currentTemplateId !== null) {
throw new \BadMethodCallException('The page format cannot be changed when writing to a template.');
}
if (!\in_array($orientation, ['P', 'L'], true)) {
throw new \InvalidArgumentException(\sprintf(
'Invalid page orientation "%s"! Only "P" and "L" are allowed!',
$orientation
));
}
$size = $this->_getpagesize($size);
if ($orientation != $this->CurOrientation
|| $size[0] != $this->CurPageSize[0]
|| $size[1] != $this->CurPageSize[1]
) {
// New size or orientation
if ($orientation === 'P') {
$this->w = $size[0];
$this->h = $size[1];
} else {
$this->w = $size[1];
$this->h = $size[0];
}
$this->wPt = $this->w * $this->k;
$this->hPt = $this->h * $this->k;
$this->PageBreakTrigger = $this->h - $this->bMargin;
$this->CurOrientation = $orientation;
$this->CurPageSize = $size;
$this->PageSizes[$this->page] = array($this->wPt, $this->hPt);
}
}
/**
* @inheritdoc
*/
protected function _put($s, $newLine = true)
{
if ($newLine) {
$this->buffer .= $s . "\n";
} else {
$this->buffer .= $s;
}
}
}
use FpdfTplTrait;
}

View file

@ -1,9 +1,10 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@ -19,8 +20,6 @@ use setasign\Fpdi\PdfParser\Type\PdfNull;
* Class Fpdi
*
* This class let you import pages of existing PDF documents into a reusable structure for tFPDF.
*
* @package setasign\Fpdi
*/
class Fpdi extends FpdfTpl
{
@ -31,7 +30,7 @@ class Fpdi extends FpdfTpl
*
* @string
*/
const VERSION = '2.2.0';
const VERSION = '2.3.4';
public function _enddoc()
{
@ -114,7 +113,6 @@ class Fpdi extends FpdfTpl
while (($objectNumber = \array_pop($this->objectsToCopy[$readerId])) !== null) {
try {
$object = $parser->getIndirectObject($objectNumber);
} catch (CrossReferenceException $e) {
if ($e->getCode() === CrossReferenceException::OBJECT_NOT_FOUND) {
$object = PdfIndirectObject::create($objectNumber, 0, new PdfNull());
@ -133,7 +131,7 @@ class Fpdi extends FpdfTpl
/**
* @inheritdoc
*/
public function _putxobjectdict()
protected function _putxobjectdict()
{
foreach ($this->importedPages as $key => $pageData) {
$this->_put('/' . $pageData['id'] . ' ' . $pageData['objectNumber'] . ' 0 R');
@ -145,20 +143,12 @@ class Fpdi extends FpdfTpl
/**
* @inheritdoc
*/
public function _newobj($n = null)
protected function _put($s, $newLine = true)
{
// Begin a new object
if($n === null)
$n = ++$this->n;
$this->offsets[$n] = $this->_getoffset();
$this->_put($n.' 0 obj');
if ($newLine) {
$this->buffer .= $s . "\n";
} else {
$this->buffer .= $s;
}
}
/**
* @inheritdoc
*/
protected function _getoffset()
{
return strlen($this->buffer);
}
}
}

View file

@ -1,18 +1,20 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
// @phpstan-ignore-next-line
spl_autoload_register(function ($class) {
if (strpos($class, 'setasign\Fpdi\\') === 0) {
$filename = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 14)) . '.php';
$fullpath = __DIR__ . DIRECTORY_SEPARATOR . $filename;
if (file_exists($fullpath)) {
if (is_file($fullpath)) {
/** @noinspection PhpIncludeInspection */
require_once $fullpath;
}