Repository navigation
fix(font): keep glyph code points across documents - #3601
Open
iliev-blnk wants to merge 1 commit into
Open
iliev-blnk wants to merge 1 commit into
iliev-blnk wants to merge 1 commit into
Conversation
fontkit caches glyphs by id with the code points of their first lookup. Embedding a font subset looks up the components of composite glyphs by id only, so after a document that used e.g. Ö, the O glyph has empty code points for every later layout of the shared font instance. textkit resolves string and glyph indices from those code points, which drops glyphs from later documents and leaves empty ToUnicode entries. Fill in the code points on the next lookup that provides them. Fixes diegomura#3589
|
@iliev-blnk is attempting to deploy a commit to the diegomura Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: ad16843 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3589
Cause
fontkit caches glyph objects by id, with the code points of the first lookup (
getGlyph(id, characters = [])). When a document ends, pdfkit embeds the font subset, andTTFSubset._addGlyphlooks up the components of composite glyphs by id only. So after a document that usedÖ(Roboto:O+ diaeresis), theOglyph on the shared, cached font instance hascodePoints: [], and every laterfont.layout('…O…')returns it that way.Since #3357 and #3358, textkit resolves string and glyph indices from
glyph.codePoints, so later documents lose glyphs. In the repro below, boldWOrenders as nothing.encodeGlyphsalso writes those empty code points to the ToUnicode map (the<>entries mentioned in the issue). Rendering the same document first, or in a fresh process, hides the problem, because the subset is only encoded at the end of a document.Fix
FontSourcewrapsgetGlyphon the fontkit fonts it loads: if a cached glyph has no code points and the current lookup provides them, they're filled in. Glyphs that already have code points are left alone.Repro
With this change, B rendered after other documents is pixel-identical to B rendered alone, and its ToUnicode map has no empty entries.
Tests
packages/font/tests/glyph-code-points.test.tssubsets a composite glyph and then lays outWO. It fails on master and passes with the fix.vitest run: 248 files, 3667 tests passing.