Skip to content

fix(textkit): preserve variation selector font runs#3454

Open
to-na wants to merge 1 commit into
diegomura:masterfrom
to-na:to-na/fix-variation-selector-font-substitution
Open

fix(textkit): preserve variation selector font runs#3454
to-na wants to merge 1 commit into
diegomura:masterfrom
to-na:to-na/fix-variation-selector-font-substitution

Conversation

@to-na

@to-na to-na commented Jul 16, 2026

Copy link
Copy Markdown

What changed

  • Keep Unicode variation selectors in the same font run as their preceding character during font substitution.
  • Iterate strings by Unicode code point while preserving UTF-16 run indices.
  • Cover all Unicode Variation_Selector property ranges with regression tests.
  • Add a patch changeset for @react-pdf/textkit.

Why

A variation selector modifies the glyph selection of its preceding character and should not be assigned a fallback font independently. Splitting the sequence across font runs prevents the font layout engine from receiving the base character and selector together, and an unsupported selector can consequently appear as a visible fallback glyph.

Observable behavior

When a font supports the base character but not the following variation selector as a standalone glyph, font substitution can assign the selector to a fallback font. This splits the variation sequence across two font runs.

As a result, text such as 漢\uFE00 or 手\u{E0100} can display an extra fallback glyph—such as an @-like mark—over or next to the base character.

After this change, the base character and variation selector remain in the same font run. This allows the font shaping engine to process them as a single variation sequence, or to render the default form of the base character when the requested variation is unsupported.

Verification

  • yarn vitest packages/textkit/tests --run (92 files, 787 tests)
  • yarn workspace @react-pdf/textkit typecheck
  • yarn workspace @react-pdf/textkit build
  • yarn eslint packages/textkit/src/engines/fontSubstitution/index.ts packages/textkit/tests/engines/fontSubstitution.test.ts

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 01d97f1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@react-pdf/textkit Patch
@react-pdf/layout Patch
@react-pdf/render Patch
@react-pdf/renderer Patch
@react-pdf/math Patch
@react-pdf/mermaid Patch
next-14 Patch
next-15 Patch
@react-pdf/vite-example Patch

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

@to-na
to-na marked this pull request as ready for review July 16, 2026 08:42
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.

1 participant