Skip to content

feat: add font feature settings support#2740

Open
stefanwittwer wants to merge 2 commits into
diegomura:masterfrom
stefanwittwer:master
Open

feat: add font feature settings support#2740
stefanwittwer wants to merge 2 commits into
diegomura:masterfrom
stefanwittwer:master

Conversation

@stefanwittwer

@stefanwittwer stefanwittwer commented May 5, 2024

Copy link
Copy Markdown

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

@changeset-bot

changeset-bot Bot commented May 5, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6430ed1

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

stefanwittwer commented May 5, 2024

Copy link
Copy Markdown
Author

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

bdkopen commented May 5, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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

@samueldrai

Copy link
Copy Markdown

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

@stefanwittwer

Copy link
Copy Markdown
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
Copy Markdown

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

@samueldrai

Copy link
Copy Markdown

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

@bnlb

bnlb commented Dec 5, 2024

Copy link
Copy Markdown

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
Copy Markdown

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

@stefanwittwer

Copy link
Copy Markdown
Author

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

@samueldrai

Copy link
Copy Markdown

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

@samueldrai

Copy link
Copy Markdown

Hi!

Happy new year :)

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

@samueldrai

Copy link
Copy Markdown

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

@samueldrai

Copy link
Copy Markdown

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

@stefanwittwer

stefanwittwer commented Feb 22, 2025

Copy link
Copy Markdown
Author

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
Copy Markdown

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

@samueldrai

Copy link
Copy Markdown

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

@stefanwittwer

stefanwittwer commented Apr 22, 2025

Copy link
Copy Markdown
Author

@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

samueldrai commented Apr 22, 2025

Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown

thank you for this PR!

Added font feature settings to TextStyle

Adapted example to new structure
@stefanwittwer

Copy link
Copy Markdown
Author

I've now brought this older PR up-to-date again by rebasing it onto the current master, to make sure it can be cleanly merged again. I also integrated the nice type-safety improvements that @MendyLanda added in his fork, thanks a lot!

Example is again up and running flawlessly:
Dia 2025-10-20 16 40 50

@wojtekmaj @diegomura - Any pointers on how to get this PR reviewed by maintainers? It's been open for quite a while without any feedback. It certainly seems highly requested by the community judging by the previous comments in this thread :) Happy to help out where I can!

@wojtekmaj wojtekmaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am NOT a maintainer 😂 but LGTM!

@stefanwittwer

Copy link
Copy Markdown
Author

@wojtekmaj Ah sorry😂 I assumed because your GitHub bio says so haha. Thanks for reviewing!

@wojtekmaj

Copy link
Copy Markdown
Contributor

@stefanwittwer It IS true! But please do mind: https://github.com/diegomura/react-pdf#lost

@manuelmeister

Copy link
Copy Markdown

With this PR, the issue #1664 would also be resolved

characterSpacing?: number;
color?: string;
direction?: 'rtl' | 'ltr';
direction?: FontFeatureSettings;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanwittwer I think this change is incorrect.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a PR stefanwittwer#1

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.

7 participants