diff --git a/src/Document/ContentStream/Command/Operator/State/TextStateOperator.php b/src/Document/ContentStream/Command/Operator/State/TextStateOperator.php index e37fb662..b8adac59 100644 --- a/src/Document/ContentStream/Command/Operator/State/TextStateOperator.php +++ b/src/Document/ContentStream/Command/Operator/State/TextStateOperator.php @@ -7,7 +7,7 @@ use PrinsFrank\PdfParser\Document\ContentStream\Command\Operator\State\Interaction\InteractsWithTextState; use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TextState; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; use PrinsFrank\PdfParser\Exception\InvalidArgumentException; use PrinsFrank\PdfParser\Exception\ParseFailureException; @@ -51,7 +51,7 @@ public function applyToTextState(string $operands, TextState $textState): TextSt } return $textState->withFont( - DictionaryKey::tryFrom($matches['fontReference']) ?? new ExtendedDictionaryKey($matches['fontReference']), + DictionaryKey::tryFrom($matches['fontReference']) ?? new NameObjectStringValue($matches['fontReference']), (float) $matches['FontSize'], ); } diff --git a/src/Document/ContentStream/Command/Operator/State/XObjectOperator.php b/src/Document/ContentStream/Command/Operator/State/XObjectOperator.php index 1173f472..28b96ff4 100644 --- a/src/Document/ContentStream/Command/Operator/State/XObjectOperator.php +++ b/src/Document/ContentStream/Command/Operator/State/XObjectOperator.php @@ -5,10 +5,11 @@ use Override; use PrinsFrank\PdfParser\Document\ContentStream\Command\Operator\State\Interaction\IncludesXObjects; use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TransformationMatrix; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Reference\ReferenceValue; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; use PrinsFrank\PdfParser\Document\Object\Decorator\Page; use PrinsFrank\PdfParser\Document\Object\Decorator\XObject; +use PrinsFrank\PdfParser\Exception\ParseFailureException; /** * @internal @@ -22,7 +23,7 @@ enum XObjectOperator: string implements IncludesXObjects { #[Override] public function getPositionedTextElements(string $operands, TransformationMatrix $transformationMatrix, Page|XObject $context, array $visitedObjectIds): array { $reference = $context->getXObjectsDictionary() - ?->getValueForKey($context->document, ExtendedDictionaryKey::fromKeyString($operands), ReferenceValue::class); + ?->getValueForKey($context->document, NameObjectStringValue::fromValue($operands) ?? throw new ParseFailureException(), ReferenceValue::class); if ($reference === null) { return []; } diff --git a/src/Document/ContentStream/PositionedText/TextState.php b/src/Document/ContentStream/PositionedText/TextState.php index e4033544..25ee51c5 100644 --- a/src/Document/ContentStream/PositionedText/TextState.php +++ b/src/Document/ContentStream/PositionedText/TextState.php @@ -3,11 +3,11 @@ namespace PrinsFrank\PdfParser\Document\ContentStream\PositionedText; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; readonly class TextState { public function __construct( - public DictionaryKey|ExtendedDictionaryKey|null $fontName, // Tf + public DictionaryKey|NameObjectStringValue|null $fontName, // Tf public ?float $fontSize, // Tfs public float $charSpace = 0, // Tc public float $wordSpace = 0, // Tw @@ -17,7 +17,7 @@ public function __construct( public float $rise = 0, // Trise ) {} - public function withFont(DictionaryKey|ExtendedDictionaryKey|null $fontName, ?float $fontSize): self { + public function withFont(DictionaryKey|NameObjectStringValue|null $fontName, ?float $fontSize): self { return new TextState( $fontName, $fontSize, diff --git a/src/Document/Dictionary/Dictionary.php b/src/Document/Dictionary/Dictionary.php index 5e55c1e0..d31c2847 100644 --- a/src/Document/Dictionary/Dictionary.php +++ b/src/Document/Dictionary/Dictionary.php @@ -5,7 +5,6 @@ use PrinsFrank\PdfParser\Document\Dictionary\DictionaryEntry\DictionaryEntry; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\ArrayValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\DictionaryArrayValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\DictionaryValue; @@ -41,10 +40,10 @@ public function __construct( * @param class-string $expectedValueType * @return T */ - public function getValueForKey(?Document $document, DictionaryKey|ExtendedDictionaryKey $dictionaryKey, string $expectedValueType): DictionaryValue|Dictionary|NameValue|null { + public function getValueForKey(?Document $document, DictionaryKey|NameObjectStringValue $dictionaryKey, string $expectedValueType): DictionaryValue|Dictionary|NameValue|null { foreach ($this->dictionaryEntries as $dictionaryEntry) { if (($dictionaryKey instanceof DictionaryKey && $dictionaryEntry->key === $dictionaryKey) === false - && ($dictionaryKey instanceof ExtendedDictionaryKey && $dictionaryEntry->key instanceof ExtendedDictionaryKey && $dictionaryEntry->key->value === $dictionaryKey->value) === false) { + && ($dictionaryKey instanceof NameObjectStringValue && $dictionaryEntry->key instanceof NameObjectStringValue && $dictionaryEntry->key->value === $dictionaryKey->value) === false) { continue; } @@ -102,7 +101,7 @@ public function getValueForKey(?Document $document, DictionaryKey|ExtendedDictio return null; } - public function getStringValue(?Document $document, DictionaryKey|ExtendedDictionaryKey $dictionaryKey): HexadecimalStringValue|LiteralStringValue|NameObjectStringValue|null { + public function getStringValue(?Document $document, DictionaryKey|NameObjectStringValue $dictionaryKey): HexadecimalStringValue|LiteralStringValue|NameObjectStringValue|null { return match ($this->getTypeForKey($dictionaryKey)) { HexadecimalStringValue::class => $this->getValueForKey($document, $dictionaryKey, HexadecimalStringValue::class), LiteralStringValue::class => $this->getValueForKey($document, $dictionaryKey, LiteralStringValue::class), @@ -112,7 +111,7 @@ public function getStringValue(?Document $document, DictionaryKey|ExtendedDictio } /** @return class-string */ - public function getTypeForKey(DictionaryKey|ExtendedDictionaryKey $dictionaryKey): ?string { + public function getTypeForKey(DictionaryKey|NameObjectStringValue $dictionaryKey): ?string { foreach ($this->dictionaryEntries as $dictionaryEntry) { if ($dictionaryEntry->key === $dictionaryKey) { return $dictionaryEntry->value::class; @@ -153,7 +152,7 @@ public function getSubDictionary(?Document $document, DictionaryKey $dictionaryK * @param class-string|null $expectedDecoratorFQN * @return ($expectedDecoratorFQN is null ? DecoratedObject : T) */ - public function getObjectForReference(Document $document, DictionaryKey|ExtendedDictionaryKey $dictionaryKey, ?string $expectedDecoratorFQN = null): ?DecoratedObject { + public function getObjectForReference(Document $document, DictionaryKey|NameObjectStringValue $dictionaryKey, ?string $expectedDecoratorFQN = null): ?DecoratedObject { $reference = $this->getValueForKey($document, $dictionaryKey, ReferenceValue::class); if ($reference === null) { return null; @@ -168,7 +167,7 @@ public function getObjectForReference(Document $document, DictionaryKey|Extended * @param class-string|null $expectedDecoratorFQN * @return ($expectedDecoratorFQN is null ? list : list) */ - public function getObjectsForReference(Document $document, DictionaryKey|ExtendedDictionaryKey $dictionaryKey, ?string $expectedDecoratorFQN = null): array { + public function getObjectsForReference(Document $document, DictionaryKey|NameObjectStringValue $dictionaryKey, ?string $expectedDecoratorFQN = null): array { $references = $this->getValueForKey($document, $dictionaryKey, ReferenceValueArray::class); if ($references === null) { return []; diff --git a/src/Document/Dictionary/DictionaryEntry/DictionaryEntry.php b/src/Document/Dictionary/DictionaryEntry/DictionaryEntry.php index 063fbaa8..3f39936c 100644 --- a/src/Document/Dictionary/DictionaryEntry/DictionaryEntry.php +++ b/src/Document/Dictionary/DictionaryEntry/DictionaryEntry.php @@ -5,14 +5,14 @@ use PrinsFrank\PdfParser\Document\Dictionary\Dictionary; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\DictionaryValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Name\NameValue; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; /** @api */ readonly class DictionaryEntry { public function __construct( - public DictionaryKey|ExtendedDictionaryKey $key, + public DictionaryKey|NameObjectStringValue $key, public DictionaryValue|Dictionary|NameValue $value, ) {} } diff --git a/src/Document/Dictionary/DictionaryEntry/DictionaryEntryFactory.php b/src/Document/Dictionary/DictionaryEntry/DictionaryEntryFactory.php index 69940387..44c25c81 100644 --- a/src/Document/Dictionary/DictionaryEntry/DictionaryEntryFactory.php +++ b/src/Document/Dictionary/DictionaryEntry/DictionaryEntryFactory.php @@ -7,12 +7,12 @@ use PrinsFrank\PdfParser\Document\Dictionary\Dictionary; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryFactory; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\ArrayValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\DictionaryValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Name\NameValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Reference\ReferenceValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Reference\ReferenceValueArray; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; use PrinsFrank\PdfParser\Document\Dictionary\Normalization\NameValueNormalizer; use PrinsFrank\PdfParser\Document\Encryption\RC4; use PrinsFrank\PdfParser\Document\Security\EncryptionContext; @@ -27,7 +27,8 @@ class DictionaryEntryFactory { */ public static function fromKeyValuePair(?EncryptionContext $encryptionContext, string $keyString, string|array $dictionaryValue): ?DictionaryEntry { $dictionaryKey = DictionaryKey::tryFromKeyString($keyString) - ?? ExtendedDictionaryKey::fromKeyString($keyString); + ?? NameObjectStringValue::fromValue($keyString) + ?? throw new ParseFailureException(); return new DictionaryEntry($dictionaryKey, self::getValue($encryptionContext, $dictionaryKey, $dictionaryValue)); } @@ -36,7 +37,7 @@ public static function fromKeyValuePair(?EncryptionContext $encryptionContext, s * @param string|array $value * @throws PdfParserException */ - protected static function getValue(?EncryptionContext $encryptionContext, DictionaryKey|ExtendedDictionaryKey $dictionaryKey, string|array $value): Dictionary|DictionaryValue|NameValue { + protected static function getValue(?EncryptionContext $encryptionContext, DictionaryKey|NameObjectStringValue $dictionaryKey, string|array $value): Dictionary|DictionaryValue|NameValue { if ($encryptionContext !== null && is_string($value)) { if (str_starts_with($value, '<') && str_ends_with($value, '>') && ($binaryValue = hex2bin(substr($value, 1, -1))) !== false) { $value = '<' . bin2hex(RC4::crypt($encryptionContext->getObjectEncryptionKey(), $binaryValue)) . '>'; @@ -81,8 +82,8 @@ protected static function getValue(?EncryptionContext $encryptionContext, Dictio return $referenceValueArray; } - if (in_array(ExtendedDictionaryKey::class, $allowedValueTypes, true) && is_string($value) && ($extendedDictionaryKey = ExtendedDictionaryKey::fromValue($value)) !== null) { - return $extendedDictionaryKey; + if (in_array(NameObjectStringValue::class, $allowedValueTypes, true) && is_string($value) && ($nameObjectStringValue = NameObjectStringValue::fromValue($value)) !== null) { + return $nameObjectStringValue; } throw new ParseFailureException(sprintf('Value "%s" for dictionary key %s could not be parsed to a valid value type', is_array($value) ? 'array()' : $value, $dictionaryKey->value)); diff --git a/src/Document/Dictionary/DictionaryKey/DictionaryKey.php b/src/Document/Dictionary/DictionaryKey/DictionaryKey.php index ea082ea7..220b3a27 100644 --- a/src/Document/Dictionary/DictionaryKey/DictionaryKey.php +++ b/src/Document/Dictionary/DictionaryKey/DictionaryKey.php @@ -828,7 +828,7 @@ public function getValueTypes(): array { self::EMBEDDED_FILES => [Dictionary::class], self::ENCODE => [ArrayValue::class], self::ENCODED_BYTE_ALIGN => [BooleanValue::class], - self::ENCODING => [EncodingNameValue::class, Dictionary::class, ExtendedDictionaryKey::class], + self::ENCODING => [EncodingNameValue::class, Dictionary::class, NameObjectStringValue::class], self::ENCRYPT => [Dictionary::class], self::ENCRYPT_METADATA => [BooleanValue::class], self::ENCRYPTION_REVISION => [IntegerValue::class], diff --git a/src/Document/Dictionary/DictionaryKey/ExtendedDictionaryKey.php b/src/Document/Dictionary/DictionaryKey/ExtendedDictionaryKey.php deleted file mode 100644 index d107555f..00000000 --- a/src/Document/Dictionary/DictionaryKey/ExtendedDictionaryKey.php +++ /dev/null @@ -1,60 +0,0 @@ -getDictionary()->getTypeForKey(DictionaryKey::ENCODING), [null, EncodingNameValue::class, ExtendedDictionaryKey::class], true)) { + if (in_array($this->getDictionary()->getTypeForKey(DictionaryKey::ENCODING), [null, EncodingNameValue::class, NameObjectStringValue::class], true)) { return null; } diff --git a/src/Document/Object/Decorator/Page.php b/src/Document/Object/Decorator/Page.php index 89efba17..6fc60636 100644 --- a/src/Document/Object/Decorator/Page.php +++ b/src/Document/Object/Decorator/Page.php @@ -9,9 +9,9 @@ use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TransformationMatrix; use PrinsFrank\PdfParser\Document\Dictionary\Dictionary; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Rectangle\Rectangle; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Reference\ReferenceValue; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; use PrinsFrank\PdfParser\Exception\InvalidArgumentException; use PrinsFrank\PdfParser\Exception\ParseFailureException; use PrinsFrank\PdfParser\Exception\PdfParserException; @@ -104,7 +104,7 @@ public function getFontDictionary(): ?Dictionary { ?->getSubDictionary($this->document, DictionaryKey::FONT); } - public function getFont(DictionaryKey|ExtendedDictionaryKey $dictionaryKey): ?Font { + public function getFont(DictionaryKey|NameObjectStringValue $dictionaryKey): ?Font { $font = $this->getFontDictionary() ?->getObjectForReference($this->document, $dictionaryKey, Font::class); if ($font !== null) { diff --git a/tests/Feature/H3SimpleStringTest.php b/tests/Feature/H3SimpleStringTest.php index db16e59b..01d236ad 100644 --- a/tests/Feature/H3SimpleStringTest.php +++ b/tests/Feature/H3SimpleStringTest.php @@ -12,7 +12,6 @@ use PrinsFrank\PdfParser\Document\Dictionary\Dictionary; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryEntry\DictionaryEntry; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Integer\IntegerValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Name\EncodingNameValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Name\SubtypeNameValue; @@ -154,7 +153,7 @@ public function testStructure(): void { new DictionaryEntry( DictionaryKey::FONT, new Dictionary( - new DictionaryEntry(new ExtendedDictionaryKey('F1'), new ReferenceValue(7, 0)), + new DictionaryEntry(new NameObjectStringValue('F1'), new ReferenceValue(7, 0)), ), ), )), @@ -220,8 +219,8 @@ public function testStructure(): void { new Dictionary( new DictionaryEntry(DictionaryKey::TYPE, TypeNameValue::FONT), new DictionaryEntry(DictionaryKey::SUBTYPE, SubtypeNameValue::TYPE_1), - new DictionaryEntry(DictionaryKey::NAME, new NameObjectStringValue('/F1')), - new DictionaryEntry(DictionaryKey::BASE_FONT, new NameObjectStringValue('/Helvetica')), + new DictionaryEntry(DictionaryKey::NAME, new NameObjectStringValue('F1')), + new DictionaryEntry(DictionaryKey::BASE_FONT, new NameObjectStringValue('Helvetica')), new DictionaryEntry(DictionaryKey::ENCODING, EncodingNameValue::MacRomanEncoding), ), $obj7?->getDictionary(), diff --git a/tests/Unit/Document/ContentStream/Command/Operator/State/TextStateOperatorTest.php b/tests/Unit/Document/ContentStream/Command/Operator/State/TextStateOperatorTest.php index bbf5f7f4..0dcbb411 100644 --- a/tests/Unit/Document/ContentStream/Command/Operator/State/TextStateOperatorTest.php +++ b/tests/Unit/Document/ContentStream/Command/Operator/State/TextStateOperatorTest.php @@ -7,22 +7,22 @@ use PHPUnit\Framework\TestCase; use PrinsFrank\PdfParser\Document\ContentStream\Command\Operator\State\TextStateOperator; use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TextState; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; use PrinsFrank\PdfParser\Exception\ParseFailureException; #[CoversClass(TextStateOperator::class)] class TextStateOperatorTest extends TestCase { public function testApplyToTextState(): void { static::assertEquals( - new TextState(new ExtendedDictionaryKey('F0'), 12, 0, 0, 100, 0, 0, 0), + new TextState(new NameObjectStringValue('F0'), 12, 0, 0, 100, 0, 0, 0), TextStateOperator::FONT_SIZE->applyToTextState('/F0 12', new TextState(null, null)), ); static::assertEquals( - new TextState(new ExtendedDictionaryKey('F0'), -12, 0, 0, 100, 0, 0, 0), + new TextState(new NameObjectStringValue('F0'), -12, 0, 0, 100, 0, 0, 0), TextStateOperator::FONT_SIZE->applyToTextState('/F0 -12', new TextState(null, null)), ); static::assertEquals( - new TextState(new ExtendedDictionaryKey('F2+0'), 12, 0, 0, 100, 0, 0, 0), + new TextState(new NameObjectStringValue('F2+0'), 12, 0, 0, 100, 0, 0, 0), TextStateOperator::FONT_SIZE->applyToTextState('/F2+0 12', new TextState(null, null)), ); } diff --git a/tests/Unit/Document/ContentStream/ContentStreamTest.php b/tests/Unit/Document/ContentStream/ContentStreamTest.php index 5a263c78..523f8c03 100644 --- a/tests/Unit/Document/ContentStream/ContentStreamTest.php +++ b/tests/Unit/Document/ContentStream/ContentStreamTest.php @@ -10,9 +10,9 @@ use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TextSegment\TextSegment; use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TextState; use PrinsFrank\PdfParser\Document\ContentStream\PositionedText\TransformationMatrix; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\HexadecimalStringValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\LiteralStringValue; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; use PrinsFrank\PdfParser\Document\Object\Decorator\GenericObject; use PrinsFrank\PdfParser\Document\Object\Decorator\Page; use PrinsFrank\PdfParser\Stream\FileStream; @@ -134,30 +134,30 @@ public function testGetPositionedTextElements(): void { $decoratedObject->expects(self::once())->method('getStream')->willReturn($contentStream); static::assertEquals( [ - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0024'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 759.6821291075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0025'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 79.33170315, 759.6821291075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0026'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 86.6634063, 759.6821291075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 94.60161225, 759.6821291075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0027'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 745.1358641075001), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0028'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 79.938205725, 745.1358641075001), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0029'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 87.269908875, 745.1358641075001), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 93.984375, 745.1358641075001), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 108.0, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002A'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 144.0, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002B'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 152.550075525, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002C'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 160.48828125, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 163.54226325000002, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 166.596245025, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 169.65022679999998, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 172.704208575, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 175.75819035, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 178.812172125, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002D'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 181.86615375, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002E'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 187.3622475, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002F'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 194.69395065, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 200.80728, 730.5896001075), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), - new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 716.0433351075001), new TextState(new ExtendedDictionaryKey('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0024'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 759.6821291075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0025'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 79.33170315, 759.6821291075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0026'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 86.6634063, 759.6821291075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 94.60161225, 759.6821291075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0027'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 745.1358641075001), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0028'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 79.938205725, 745.1358641075001), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0029'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 87.269908875, 745.1358641075001), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 93.984375, 745.1358641075001), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 108.0, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002A'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 144.0, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002B'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 152.550075525, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002C'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 160.48828125, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 163.54226325000002, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 166.596245025, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 169.65022679999998, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 172.704208575, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 175.75819035, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 178.812172125, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002D'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 181.86615375, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002E'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 187.3622475, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('002F'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 194.69395065, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 200.80728, 730.5896001075), new TextState(new NameObjectStringValue('F4'), 14.666667)), + new PositionedTextElement([new TextSegment(new HexadecimalStringValue('0003'), null)], new TransformationMatrix(0.75, 0, 0, 0.75, 72.0, 716.0433351075001), new TextState(new NameObjectStringValue('F4'), 14.666667)), ], ContentStreamParser::parse([$decoratedObject])->getPositionedTextElements($this->createMock(Page::class), new TransformationMatrix(1, 0, 0, 1, 0, 0), []), ); @@ -178,8 +178,8 @@ public function testGetPositionedTextElementsWithTextStateOutsideTextObject(): v $decoratedObject->expects(self::once())->method('getStream')->willReturn($contentStream); static::assertEquals( [ - new PositionedTextElement([new TextSegment(new LiteralStringValue('[Hello'), null)], new TransformationMatrix(1.0, 0, 0, 1.0, 0.0, 0.0), new TextState(new ExtendedDictionaryKey('F1'), 7)), - new PositionedTextElement([new TextSegment(new LiteralStringValue('World]'), null)], new TransformationMatrix(1.0, 0, 0, 1.0, 0.0, 0.0), new TextState(new ExtendedDictionaryKey('F1'), 7)), + new PositionedTextElement([new TextSegment(new LiteralStringValue('[Hello'), null)], new TransformationMatrix(1.0, 0, 0, 1.0, 0.0, 0.0), new TextState(new NameObjectStringValue('F1'), 7)), + new PositionedTextElement([new TextSegment(new LiteralStringValue('World]'), null)], new TransformationMatrix(1.0, 0, 0, 1.0, 0.0, 0.0), new TextState(new NameObjectStringValue('F1'), 7)), ], ContentStreamParser::parse([$decoratedObject])->getPositionedTextElements($this->createMock(Page::class), new TransformationMatrix(1, 0, 0, 1, 0, 0), []), ); diff --git a/tests/Unit/Document/Dictionary/DictionaryEntry/DictionaryEntryTest.php b/tests/Unit/Document/Dictionary/DictionaryEntry/DictionaryEntryTest.php index 5586c84f..1c0c4da9 100644 --- a/tests/Unit/Document/Dictionary/DictionaryEntry/DictionaryEntryTest.php +++ b/tests/Unit/Document/Dictionary/DictionaryEntry/DictionaryEntryTest.php @@ -5,15 +5,15 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryEntry\DictionaryEntry; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\LiteralStringValue; +use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\TextString\NameObjectStringValue; #[CoversClass(DictionaryEntry::class)] class DictionaryEntryTest extends TestCase { public function testConstruct(): void { - $dictionaryEntry = new DictionaryEntry(new ExtendedDictionaryKey('Foo'), new LiteralStringValue('Bar')); + $dictionaryEntry = new DictionaryEntry(new NameObjectStringValue('Foo'), new LiteralStringValue('Bar')); - static::assertEquals(new ExtendedDictionaryKey('Foo'), $dictionaryEntry->key); + static::assertEquals(new NameObjectStringValue('Foo'), $dictionaryEntry->key); static::assertEquals(new LiteralStringValue('Bar'), $dictionaryEntry->value); } } diff --git a/tests/Unit/Document/Dictionary/DictionaryKey/ExtendedDictionaryKeyTest.php b/tests/Unit/Document/Dictionary/DictionaryKey/ExtendedDictionaryKeyTest.php deleted file mode 100644 index e3504f5a..00000000 --- a/tests/Unit/Document/Dictionary/DictionaryKey/ExtendedDictionaryKeyTest.php +++ /dev/null @@ -1,63 +0,0 @@ -getValueTypes(), - ); - } -} diff --git a/tests/Unit/Document/Dictionary/DictionaryParserTest.php b/tests/Unit/Document/Dictionary/DictionaryParserTest.php index b8dbbcc9..f2a9509d 100644 --- a/tests/Unit/Document/Dictionary/DictionaryParserTest.php +++ b/tests/Unit/Document/Dictionary/DictionaryParserTest.php @@ -9,7 +9,6 @@ use PrinsFrank\PdfParser\Document\Dictionary\Dictionary; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryEntry\DictionaryEntry; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryParser; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\ArrayValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\DictionaryArrayValue; @@ -170,7 +169,7 @@ public function testParseFontInfo(): void { static::assertEquals( new Dictionary( new DictionaryEntry(DictionaryKey::TYPE, TypeNameValue::FONT_DESCRIPTOR), - new DictionaryEntry(DictionaryKey::FONT_NAME, new NameObjectStringValue('/TAIPAH+CMR10')), + new DictionaryEntry(DictionaryKey::FONT_NAME, new NameObjectStringValue('TAIPAH+CMR10')), new DictionaryEntry(DictionaryKey::FLAGS, new IntegerValue(4)), new DictionaryEntry(DictionaryKey::FONT_BBOX, new Rectangle(-40, -250, 1009, 750)), new DictionaryEntry(DictionaryKey::ASCENT, new IntegerValue(694)), @@ -229,8 +228,8 @@ public function testIgnoreCommentedLines(): void { static::assertEquals( new Dictionary( new DictionaryEntry(DictionaryKey::PRODUCER, new LiteralStringValue('pdfTeX-1.40.18')), - new DictionaryEntry(new ExtendedDictionaryKey('Foo'), new LiteralStringValue('Bar')), - new DictionaryEntry(new ExtendedDictionaryKey('Bar'), new LiteralStringValue('% this is not a comment but a string literal')), + new DictionaryEntry(new NameObjectStringValue('Foo'), new LiteralStringValue('Bar')), + new DictionaryEntry(new NameObjectStringValue('Bar'), new LiteralStringValue('% this is not a comment but a string literal')), ), DictionaryParser::parse(null, $stream, 0, $stream->getSizeInBytes()), ); @@ -288,10 +287,10 @@ public function testHandlesGraphicStateSubDictionaries(): void { new DictionaryEntry(DictionaryKey::RESOURCES, new Dictionary( new DictionaryEntry(DictionaryKey::PROC_SET, new ArrayValue(['/PDF', '/Text', '/ImageB', '/ImageC', '/ImageI'])), new DictionaryEntry(DictionaryKey::EXT_GSTATE, new Dictionary( - new DictionaryEntry(new ExtendedDictionaryKey('G3'), new ReferenceValue(3, 0)), + new DictionaryEntry(new NameObjectStringValue('G3'), new ReferenceValue(3, 0)), )), new DictionaryEntry(DictionaryKey::FONT, new Dictionary( - new DictionaryEntry(new ExtendedDictionaryKey('F4'), new ReferenceValue(4, 0)), + new DictionaryEntry(new NameObjectStringValue('F4'), new ReferenceValue(4, 0)), )), )), new DictionaryEntry(DictionaryKey::MEDIA_BOX, new Rectangle(0.0, 0.0, 596.0, 842.0)), @@ -381,7 +380,7 @@ public function testHandlesNestedArrays(): void { ), new DictionaryEntry( DictionaryKey::BASE_STATE, - new NameObjectStringValue('/OFF'), + new NameObjectStringValue('OFF'), ), new DictionaryEntry( DictionaryKey::ON, @@ -529,7 +528,7 @@ public function testHandlesComplexNestedObjectsOnSingleLine(): void { DictionaryKey::XOBJECT, new Dictionary( new DictionaryEntry( - new ExtendedDictionaryKey('FRM'), + new NameObjectStringValue('FRM'), new ReferenceValue(31, 0), ), ), @@ -549,14 +548,14 @@ public function testHandlesComplexNestedObjectsOnSingleLine(): void { ), ), new DictionaryEntry( - new ExtendedDictionaryKey('DSS'), + new NameObjectStringValue('DSS'), new ReferenceValue(40, 0), ), new DictionaryEntry( DictionaryKey::EXTENSIONS, new Dictionary( new DictionaryEntry( - new ExtendedDictionaryKey('ADBE'), + new NameObjectStringValue('ADBE'), new Dictionary( new DictionaryEntry( DictionaryKey::BASE_VERSION, diff --git a/tests/Unit/Document/Dictionary/DictionaryValue/Array/DictionaryArrayValueTest.php b/tests/Unit/Document/Dictionary/DictionaryValue/Array/DictionaryArrayValueTest.php index bd1e7345..87d42fbb 100644 --- a/tests/Unit/Document/Dictionary/DictionaryValue/Array/DictionaryArrayValueTest.php +++ b/tests/Unit/Document/Dictionary/DictionaryValue/Array/DictionaryArrayValueTest.php @@ -7,7 +7,6 @@ use PrinsFrank\PdfParser\Document\Dictionary\Dictionary; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryEntry\DictionaryEntry; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey; -use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\ExtendedDictionaryKey; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\ArrayValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Array\DictionaryArrayValue; use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Integer\IntegerValue; @@ -55,11 +54,11 @@ public function testFromValue(): void { new DictionaryArrayValue( new Dictionary( new DictionaryEntry(DictionaryKey::TYPE, TypeNameValue::OUTPUT_INTENT), - new DictionaryEntry(DictionaryKey::S, new NameObjectStringValue('/GTS_PDFA1')), - new DictionaryEntry(new ExtendedDictionaryKey('OutputConditionIdentifier'), new LiteralStringValue('sRGB')), - new DictionaryEntry(new ExtendedDictionaryKey('RegistryName'), new LiteralStringValue('http://www.color.org')), + new DictionaryEntry(DictionaryKey::S, new NameObjectStringValue('GTS_PDFA1')), + new DictionaryEntry(new NameObjectStringValue('OutputConditionIdentifier'), new LiteralStringValue('sRGB')), + new DictionaryEntry(new NameObjectStringValue('RegistryName'), new LiteralStringValue('http://www.color.org')), new DictionaryEntry(DictionaryKey::INFO, new LiteralStringValue('Creator: HP Manufacturer:IEC Model:sRGB')), - new DictionaryEntry(new ExtendedDictionaryKey('DestOutputProfile'), new ReferenceValue(361, 0)), + new DictionaryEntry(new NameObjectStringValue('DestOutputProfile'), new ReferenceValue(361, 0)), ), ), DictionaryArrayValue::fromValue('[<>]'), diff --git a/tests/Unit/Document/Dictionary/DictionaryValue/TextString/NameObjectStringValueTest.php b/tests/Unit/Document/Dictionary/DictionaryValue/TextString/NameObjectStringValueTest.php index 5ca5ff69..927cb68f 100644 --- a/tests/Unit/Document/Dictionary/DictionaryValue/TextString/NameObjectStringValueTest.php +++ b/tests/Unit/Document/Dictionary/DictionaryValue/TextString/NameObjectStringValueTest.php @@ -9,7 +9,7 @@ #[CoversClass(NameObjectStringValue::class)] class NameObjectStringValueTest extends TestCase { public function testFromValue(): void { - static::assertEquals(new NameObjectStringValue('/Foo'), NameObjectStringValue::fromValue('/Foo')); + static::assertEquals(new NameObjectStringValue('Foo'), NameObjectStringValue::fromValue('/Foo')); } /** @see 7.3.5, table 4 */