Skip to content

feat(layout): support fontFeatureSettings in text rendering#3440

Open
manuelmeister wants to merge 2 commits into
diegomura:masterfrom
manuelmeister:feature/font-features
Open

feat(layout): support fontFeatureSettings in text rendering#3440
manuelmeister wants to merge 2 commits into
diegomura:masterfrom
manuelmeister:feature/font-features

Conversation

@manuelmeister

Copy link
Copy Markdown

Implements #2155

Note

This is a up to date version of #2740 by @stefanwittwer with a smaller diff, updated typing, and additional tests.
If Stefan wants to rebase his PR, then I will close this PR.

This PR adds the fontFeatureSettings style property (see MDN for the CSS equivalent). It takes a list of feature tags, which appends to the default set, or an object to turn on/off individual features, as supported by fontkit.

Why it matters

This allows users to apply any font features supported by a given font, such as tabular numbers, fractions, alternate glyphs, control over ligatures, etc.

Usage

const styles = StyleSheet.create({
  numeric: {
    fontFeatureSettings: ['tnum'],
  },
  custom: {
    fontFeatureSettings: {
      liga: 0,
      kern: 1,
    }
  }
});

The numeric style can be used as a workaround for #1664

Example

A full example is provided in the examples package. Here's how it looks like:

Example

Implementation notes

  • Adds fontFeatureSettings to the public style types.
  • Maps fontFeatureSettings to internal textkit features.
  • Converts numeric feature objects to fontkit-compatible boolean feature objects.
  • Preserves feature arrays unchanged.
  • Passes the resolved features to font.layout.
  • Keeps textkit independent from stylesheet-specific types.

@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fb3650b

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

This PR includes changesets to release 12 packages
Name Type
@react-pdf/textkit Minor
@react-pdf/layout Minor
@react-pdf/stylesheet Minor
@react-pdf/types Minor
@react-pdf/render Patch
@react-pdf/renderer Patch
@react-pdf/font 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

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.

2 participants