Skip to content

feat: add font feature settings support #2740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stefanwittwer
Copy link

@stefanwittwer stefanwittwer commented May 5, 2024

Implements #2155.

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'],
  }
});

Example

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

CleanShot 2024-05-05 at 12 05 59@2x

Copy link

changeset-bot bot commented May 5, 2024

🦋 Changeset detected

Latest commit: 3bd1a79

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/types Minor
@react-pdf/render Patch
@react-pdf/renderer Patch
@react-pdf/font Patch
@react-pdf/stylesheet Patch
next-14 Patch
next-15 Patch
@react-pdf/vite-example Patch
@react-pdf/e2e-node-cjs Patch
@react-pdf/e2e-node-esm 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

@stefanwittwer
Copy link
Author

stefanwittwer commented May 5, 2024

I'm of course also happy to extend the documentation site accordingly if this will be merged, I'd just need a pointer as to where I could contribute that.

@bdkopen
Copy link
Contributor

bdkopen commented May 5, 2024

I'm of course also happy to extend the documentation site accordingly if this will be merged, I'd just need a pointer as to where I could contribute that.

The website documentation is kept in the react-pdf-site repository.

@samueldrai
Copy link

Hi!
Any news about this issue? Happy to help if needed :)

@samueldrai
Copy link

Up!
Any update on this? Happy to help :)

@stefanwittwer
Copy link
Author

I'm also happy to change anything needed for this to be merged :) Is there a process for getting this PR reviewed?

@samueldrai
Copy link

If anything can be done to merge this PR, please reach out. :)

@samueldrai
Copy link

Up, is there anything I can do to help this PR being merged? :)

@bnlb
Copy link

bnlb commented Dec 5, 2024

This PR would help my team. Happy to help write documentation or assist where I can if it'd help get this approved.

@samueldrai
Copy link

Same as @bnlb. Happy to help for testing or writing docs :)

@stefanwittwer
Copy link
Author

@diegomura Any pointers on how to get this PR reviewed? :)

@samueldrai
Copy link

Hi!
Any updates on this PR being merged? As usual, feel free to reach out if you need any help :)

@samueldrai
Copy link

Hi!

Happy new year :)

Any updates on this PR? As always, more than happy to help however I can!

@samueldrai
Copy link

Hi!
Any updates on this PR? Happy to contribute or help (docs, tests or anything else)>
@diegomura @stefanwittwer

@samueldrai
Copy link

Hi!
Any updates on this PR? Always happy to help if needed. :)

Added font feature settings to TextStyle

Adapted example to new structure
@stefanwittwer
Copy link
Author

stefanwittwer commented Feb 22, 2025

This PR was a bit out of date by now, so I integrated all latest changes into it and resolved the conflicts.
Everything works again, as can be seen in the associated example.

@diegomura Just let me know there's anything else I can do to help the maintainers out here, or if there are any other blockers before it can be reviewed :)

Support for tabular numbers with this would be extremely useful for use cases where react-pdf is used to generate reports, etc. Worth noting also that everything needed here was already supported out-of-the-box by Fontkit, so this addition should not stand in the way of the goal of merging the PDFKit fork with the original.

@samueldrai
Copy link

Hello there !
Any news regarding this PR? As always, happy to help. :)

@samueldrai
Copy link

Hi!
Any news? As always, please reach out if I can do anything to help :)
Sam

@stefanwittwer
Copy link
Author

stefanwittwer commented Apr 22, 2025

@samueldrai It seems the layout package has been converted to TypeScript now on the main branch in #3092 and subsequent PRs. Would you be willing to help me bring my PR back to speed with all newer changes? I'm currently missing the time to do it unfortunately, but I'll accept your contribution on my fork for this PR. Hopefully that makes a path for this to get merged at some point

@samueldrai
Copy link

samueldrai commented Apr 22, 2025

Of course, I'll get this done this done whenever I can @stefanwittwer :)

MendyLanda added a commit to MendyLanda/react-pdf that referenced this pull request Jun 15, 2025
Implements diegomura#2155. Adds the fontFeatureSettings style property for CSS equivalent support. 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.

Allows users to apply font features like tabular numbers, fractions, alternate glyphs, control over ligatures, etc.
@MendyLanda
Copy link

@samueldrai @stefanwittwer, i needed this and a few other fixes and features. idk why all these PRs are not being merged and I'm tired of waiting, so (for now at least) I forked react-pdf and republished under @rpdf/*
see here https://github.com/MendyLanda/react-pdf

I don't have time for actively improving it, but reviewing and merging PRs is definitely doable.

@MendyLanda
Copy link

thank you for 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.

5 participants