Skip to content
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

patch: force render standard fonts #2827

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

Conversation

mrjeanp
Copy link

@mrjeanp mrjeanp commented Jul 22, 2024

This is a follow up fix to my issue #2818

Problem:
When styling <Text/> with standard fontFamily such font doesn't render and instead it falls back to Helvetica which is the currently configured default font.

Fix:
I copied the following code and included a condition inside pickFontFromFontStack to force selecting the font that the user actually picked.

var standard = ['Courier', 'Courier-Bold', 'Courier-Oblique', 'Courier-BoldOblique', 'Helvetica', 'Helvetica-Bold', 'Helvetica-Oblique', 'Helvetica-BoldOblique', 'Times-Roman', 'Times-Bold', 'Times-Italic', 'Times-BoldItalic'];

Please review @diegomura 🙏

Copy link

changeset-bot bot commented Jul 22, 2024

⚠️ No Changeset found

Latest commit: a31f8f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mrjeanp mrjeanp changed the title fix: standard fonts not rendering patch: standard fonts not rendering Jul 22, 2024
@theskillwithin
Copy link

Will this also fix custom fonts loaded via Font.register?

@mrjeanp
Copy link
Author

mrjeanp commented Jul 30, 2024

@theskillwithin i never experienced issues with Font.register so i never attempted to fix it, this will most likely not fix your issue. Out of curiosity, what is your setup?

@theskillwithin
Copy link

theskillwithin commented Jul 30, 2024

@theskillwithin i never experienced issues with Font.register so i never attempted to fix it, this will most likely not fix your issue. Out of curiosity, what is your setup?

@mrjeanp For some reason the Font.register only works with external fonts. (I am using the words internal and external here to mean local path or external url path)

as soon as i try to use an internal font path by module loading or pointing to relative path /fonts/foo.ttf it does not work

oddly if I point to the same font like: https://mysite.com/fonts/foo.ttf this does work

using Remix (loaded via vite)

@mrjeanp
Copy link
Author

mrjeanp commented Jul 31, 2024

Taken from https://react-pdf.org/fonts#register
image

Try using an absolute path, maybe use something like path.join(__dirname, '../fonts/foo.ttf')

@mrjeanp mrjeanp changed the title patch: standard fonts not rendering patch: force render standard fonts Aug 12, 2024
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