Skip to content

Commit 9054217

Browse files
authored
Don't prioritize simple encoding when font has differences (#395)
1 parent 7797442 commit 9054217

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Document/ContentStream/PositionedText/PositionedTextElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getText(Document $document, Page $page): string {
4242
$chars = $glyph->getChar();
4343
} elseif (strlen($unescapedChars) === 1 && ($glyph = $font->getDifferences()?->getGlyph(ord($unescapedChars))) !== null) {
4444
$chars = $glyph->getChar();
45-
} elseif (in_array($encoding = $font->getEncoding(), [EncodingNameValue::MacExpertEncoding, EncodingNameValue::WinAnsiEncoding], true)) {
45+
} elseif (in_array($encoding = $font->getEncoding(), [EncodingNameValue::MacExpertEncoding, EncodingNameValue::WinAnsiEncoding], true) && $font->getDifferences() === null) {
4646
$chars = $encoding->decodeString($unescapedChars);
4747
} elseif (($toUnicodeCMap = $font->getToUnicodeCMap() ?? $font->getToUnicodeCMapDescendantFont()) !== null) {
4848
$chars = $toUnicodeCMap->textToUnicode(bin2hex($unescapedChars));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# yaml-language-server: $schema=../../schema.json
2+
version: '1.6'
3+
userPassword: null
4+
ownerPassword: null
5+
fileEncryptionKey: null
6+
title: 'Custom encoding extraction reproducer (control-char range)'
7+
producer: 'GPL Ghostscript 10.07.1'
8+
author: null
9+
creator: 'synthetic reproducer for PDF parser CFF/Custom encoding extraction'
10+
creationDate: 2026-06-04T11:31:22-05:00
11+
modificationDate: 2026-06-04T11:31:22-05:00
12+
pages:
13+
-
14+
content: |-
15+
HELLO PDF WORLD.
16+
THIS PDF USES CUSTOM ENCODING.
17+
VISIBLE TEXT IS WHAT YOU READ ABOVE.
18+
NAIVE PARSERS THAT IGNORE THE
19+
DIFFERENCES ARRAY AND TOUNICODE CMAP
20+
WILL OUTPUT GARBAGE FOR EVERY LINE.
21+
EVERY VISIBLE CHARACTER MAPS THROUGH A
22+
DIFFERENCES ARRAY AT WINANSI CONTROL
23+
POSITIONS, FORCING TOUNICODE LOOKUP.
5.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)