This is a minimal reproduction for a @react-pdf/textkit@6.3.0 text mapping bug.
textkit trusts glyph.codePoints returned by the font layout engine. If a glyph object has codePoints: [], textkit loses the source-character mapping for that glyph.
This repro uses real fontkit@2.0.4 and a real Roboto font from @fontsource/roboto. It first calls font.getGlyph(gid) by glyph id, then calls font.layout("AB"). The first glyph returned by font.layout() has empty codePoints.
No PDF renderer is involved. The failure is isolated to @react-pdf/textkit handling a fontkit glyph run with an empty codePoints entry.
bun install
bun run reproWith unpatched @react-pdf/textkit@6.3.0, this fails because the first glyph still has empty codePoints.
Expected behavior: textkit should repair missing/empty glyph codePoints from the input run string when the glyph sequence remains unambiguous.
fontkit glyph.codePoints after getGlyph(gid): [ [], [ 66 ] ]
Text: AB
Expected codePoints: [ 65, 66 ]
Actual textkit glyph.codePoints: [ [ 66 ] ]
Actual textkit stringIndices: [ 0 ]
Actual textkit glyphIndices: [ 0 ]
AssertionError [ERR_ASSERTION]: textkit should preserve source character mapping when fontkit returns a glyph with empty codePointsThe first character (A, code point 65) is lost from the final glyph mapping.