Repository navigation
fix(afm): treat UTF-16 surrogate pairs as single code points - #1854
Merged
blikblum merged 1 commit intoNov 2, 2026
Merged
Conversation
juancarlosmorato-aircury
force-pushed
the
fix/afm-surrogate-pairs
branch
from
November 2, 2026 08:31
56645c3 to
c29317c
Compare
AFMFont.encodeText/glyphsForString walked strings with charCodeAt, so supplementary-plane characters were encoded as two WinAnsi halves and rendered as garbage (e.g. U+1D465 → "5e", U+1F16A/B → "<j<k"). Iterate with codePointAt instead. Fixes the remaining half of diegomura/react-pdf#3127 after textkit's #3423, now that react-pdf depends on upstream pdfkit (#3509). Supersedes the AFM portion of diegomura/react-pdf#3133.
juancarlosmorato-aircury
force-pushed
the
fix/afm-surrogate-pairs
branch
from
November 2, 2026 08:31
c29317c to
535a1eb
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.
What kind of change does this PR introduce?
Bug fix for UTF-16 surrogate pairs in standard (AFM) fonts.
Minimal reproduction (latest
@react-pdf/renderer@4.9.0)Rendering
𝑥(U+1D465) or🅪🅫(U+1F16A/U+1F16B) with Helvetica produces garbage such as5e/<j<k>instead of a single.notdef(or the real glyph when a supporting font is used).What is still needed after diegomura/react-pdf#3423 and #3509?
codePointAt)encodeText/glyphsForStringpdfkit@0.20.1, which still usescharCodeAtUpstream repo for the remaining fix:
foliojs/pdfkit(this PR).encodeText/glyphsForStringnow iterate withcodePointAtand advance by 1 or 2 so each supplementary-plane character is one unit.Related: diegomura/react-pdf#3127, diegomura/react-pdf#3133 (AFM portion superseded here).
Checklist: