Skip to content

Apply the font /Differences array to every byte of a text segment#453

Merged
PrinsFrank merged 1 commit into
PrinsFrank:mainfrom
cosmocode:utf8
Jul 21, 2026
Merged

Apply the font /Differences array to every byte of a text segment#453
PrinsFrank merged 1 commit into
PrinsFrank:mainfrom
cosmocode:utf8

Conversation

@splitbrain

Copy link
Copy Markdown
Contributor

The /Differences array was only consulted for single byte text segments, so multi-byte strings shown with a font whose encoding is a /Differences array without a base encoding or /ToUnicode CMap fell through to their raw bytes. Non-ASCII glyphs such as umlauts were then emitted as raw single byte codes, producing invalid UTF-8.

Simple fonts are single byte encoded, so the array is now applied per byte for the whole segment, falling back to the base encoding for codes it does not remap, matching the encoding resolution in spec section 9.6.6.1.

I encountered this issue when trying to convert my 20+ year old Latex-generated diploma thesis - the issue seems to be rare for modern PDFs. The commit adds a synthetic test PDF - if you need my thesis for tests, let me know ;-)

@PrinsFrank PrinsFrank left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Thanks for the clear PR including a reproduction PDF!

Unfortunately I'm unable to rebase and fix commits, could you rebase and remove the comments yourself? Apart from that this is ready to merge!

Comment thread src/Document/ContentStream/PositionedText/TextSegment/TextSegment.php Outdated
The /Differences array was only consulted for single byte text segments,
so multi-byte strings shown with a font whose encoding is a /Differences
array without a base encoding or /ToUnicode CMap fell through to their raw
bytes. Non-ASCII glyphs such as umlauts were then emitted as raw single
byte codes, producing invalid UTF-8.

Simple fonts are single byte encoded, so the array is now applied per byte
for the whole segment, falling back to the base encoding for codes it does
not remap, matching the encoding resolution in spec section 9.6.6.1.
@splitbrain

Copy link
Copy Markdown
Contributor Author

rebased and conflict solved. inline comment removed

@PrinsFrank

Copy link
Copy Markdown
Owner

Thank you!!

@PrinsFrank
PrinsFrank merged commit 96dc954 into PrinsFrank:main Jul 21, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants