This commit is contained in:
wangjinlei
2024-07-17 09:23:45 +08:00
parent edf9deeb1a
commit 881ac3e056
1001 changed files with 41032 additions and 5452 deletions

View File

@@ -4,7 +4,7 @@
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @copyright Copyright (c) 2023 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
@@ -25,6 +25,7 @@ use setasign\Fpdi\PdfParser\Type\PdfStream;
use setasign\Fpdi\PdfParser\Type\PdfString;
use setasign\Fpdi\PdfParser\Type\PdfToken;
use setasign\Fpdi\PdfParser\Type\PdfType;
use setasign\Fpdi\PdfParser\Type\PdfTypeException;
/**
* A PDF parser class
@@ -145,7 +146,7 @@ class PdfParser
}
/**
* Get the cross reference instance.
* Get the cross-reference instance.
*
* @return CrossReference
* @throws CrossReferenceException
@@ -258,25 +259,25 @@ class PdfParser
switch ($token) {
case '(':
$this->ensureExpectedType($token, $expectedType);
return PdfString::parse($this->streamReader);
return $this->parsePdfString();
case '<':
if ($this->streamReader->getByte() === '<') {
$this->ensureExpectedType('<<', $expectedType);
$this->streamReader->addOffset(1);
return PdfDictionary::parse($this->tokenizer, $this->streamReader, $this);
return $this->parsePdfDictionary();
}
$this->ensureExpectedType($token, $expectedType);
return PdfHexString::parse($this->streamReader);
return $this->parsePdfHexString();
case '/':
$this->ensureExpectedType($token, $expectedType);
return PdfName::parse($this->tokenizer, $this->streamReader);
return $this->parsePdfName();
case '[':
$this->ensureExpectedType($token, $expectedType);
return PdfArray::parse($this->tokenizer, $this);
return $this->parsePdfArray();
default:
if (\is_numeric($token)) {
@@ -291,13 +292,7 @@ class PdfParser
);
}
return PdfIndirectObject::parse(
(int) $token,
(int) $token2,
$this,
$this->tokenizer,
$this->streamReader
);
return $this->parsePdfIndirectObject((int)$token, (int)$token2);
case 'R':
if (
$expectedType !== null &&
@@ -309,7 +304,7 @@ class PdfParser
);
}
return PdfIndirectObjectReference::create((int) $token, (int) $token2);
return PdfIndirectObjectReference::create((int)$token, (int)$token2);
}
$this->tokenizer->pushStack($token3);
@@ -351,6 +346,65 @@ class PdfParser
}
}
/**
* @return PdfString
*/
protected function parsePdfString()
{
return PdfString::parse($this->streamReader);
}
/**
* @return false|PdfHexString
*/
protected function parsePdfHexString()
{
return PdfHexString::parse($this->streamReader);
}
/**
* @return bool|PdfDictionary
* @throws PdfTypeException
*/
protected function parsePdfDictionary()
{
return PdfDictionary::parse($this->tokenizer, $this->streamReader, $this);
}
/**
* @return PdfName
*/
protected function parsePdfName()
{
return PdfName::parse($this->tokenizer, $this->streamReader);
}
/**
* @return false|PdfArray
* @throws PdfTypeException
*/
protected function parsePdfArray()
{
return PdfArray::parse($this->tokenizer, $this);
}
/**
* @param int $objectNumber
* @param int $generationNumber
* @return false|PdfIndirectObject
* @throws Type\PdfTypeException
*/
protected function parsePdfIndirectObject($objectNumber, $generationNumber)
{
return PdfIndirectObject::parse(
$objectNumber,
$generationNumber,
$this,
$this->tokenizer,
$this->streamReader
);
}
/**
* Ensures that the token will evaluate to an expected object type (or not).
*
@@ -359,7 +413,7 @@ class PdfParser
* @return bool
* @throws Type\PdfTypeException
*/
private function ensureExpectedType($token, $expectedType)
protected function ensureExpectedType($token, $expectedType)
{
static $mapping = [
'(' => PdfString::class,