fix(textkit): preserve empty glyph codepoints#3405
Open
brandon-julio-t wants to merge 1 commit intodiegomura:masterfrom
Open
fix(textkit): preserve empty glyph codepoints#3405brandon-julio-t wants to merge 1 commit intodiegomura:masterfrom
brandon-julio-t wants to merge 1 commit intodiegomura:masterfrom
Conversation
🦋 Changeset detectedLatest commit: c093c78 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 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 |
64ac337 to
c093c78
Compare
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.
Summary
codePointsfrom the original run string before resolving textkit glyph/string indices.isLigature,isMark) on cloned glyphs so downstream layout does not see stale fontkit cache metadata.Fixes #3404.
Why Not Only Check for an Empty Array?
An empty
glyph.codePointsarray shows that the source-character mapping is missing, but it does not tell textkit which source code point or code points belong to that glyph.A simple same-index repair would work for the minimal
洗水case, but text shaping is not always one glyph per character. Ligatures, combining marks, glyphs with no source character, bidi/script shaping, repeated characters, adjacent empty mappings, and partial glyph runs can make glyph index and source-codepoint index diverge.This patch uses existing non-empty glyph mappings as anchors and fills only unambiguous gaps between those anchors. One empty glyph can receive a multi-codepoint gap, but multiple empty glyphs are only repaired when each can receive exactly one code point. If the full glyph sequence no longer aligns with the original run string, or the gap is ambiguous, it stops repairing rather than guessing. Repaired glyphs are cloned so fontkit's cached glyph objects are not mutated.
Testing
npx yarn@1.22.19 install --frozen-lockfilenpx yarn@1.22.19 vitest packages/textkit/tests/layout/generateGlyphs.test.tsnpx yarn@1.22.19 workspace @react-pdf/textkit typechecknpx yarn@1.22.19 vitest packages/textkit/tests./node_modules/.bin/prettier --check ".changeset/sharp-mugs-repair.md" "packages/textkit/src/layout/generateGlyphs.ts" "packages/textkit/tests/layout/generateGlyphs.test.ts"AI Assistance
This PR was prepared with assistance from GPT-5.5 Fast (xhigh reasoning). I reviewed the repro, implementation, and test results before submitting.