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

Missing style and weight definition when using custom fonts #565

Merged
merged 5 commits into from
Feb 19, 2023

Conversation

goatyeahh
Copy link
Contributor

Goal

Allow to define custom font style and weight.

Example

<ReactToPrint
  fonts={[
    { family: "Inter", style: "normal", weight: 200, source: `url("https://rsms.me/inter/font-files/Inter-ExtraLight.woff2?v=3.19") format("woff2")` },
    { family: "Inter", style: "italic", weight: 300, source: `url("https://rsms.me/inter/font-files/Inter-LightItalic.woff2?v=3.19") format("woff2")` },
  ]}
  trigger={() => (
    <button>Print</button>
  )}
  content={() => componentRef.current}
/>

Documentation: https://developer.mozilla.org/en-US/docs/Web/API/FontFace

@MatthewHerbst
Copy link
Owner

Hi, thanks for the PR! Would you mind also updating the examples to show using this? I use the examples as both a way to show people how to use things, and also as tests to ensure everything is working properly. Otherwise everything looks good!

Copy link
Owner

@MatthewHerbst MatthewHerbst left a comment

Choose a reason for hiding this comment

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

Could you please add the font files to the project so an internet connection isn't needed to test the feature?

Also, I tested your code in Chrome 107. Is this what the text is meant to look like? (Ignore the different image sizes)

Before print:
Screen Shot 2022-12-08 at 10 40 04 AM

During print:
Screen Shot 2022-12-08 at 10 40 45 AM

examples/fonts.ts Outdated Show resolved Hide resolved
@goatyeahh
Copy link
Contributor Author

It should look something like this

CleanShot 2022-12-08 at 21 04 58

Copy link
Owner

@MatthewHerbst MatthewHerbst left a comment

Choose a reason for hiding this comment

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

Hey, happy new year! Apologies for not getting this merged sooner, I had to do some other things in the final weeks of last year. I looked at this locally, and it exposed a bug in the underlying code, which I have fixed and is now available as v2.14.11. If you rebase on that it should work.

I have a few improvements I'd like to see to the Webpack stuff here. I'll make a PR into your fork tomorrow hopefully to show what I'm getting at. I do want to get this merged. Thanks!

examples/ComponentToPrint/index.tsx Show resolved Hide resolved
examples/index.html Outdated Show resolved Hide resolved
webpack.dev.config.js Outdated Show resolved Hide resolved
examples/fonts.ts Outdated Show resolved Hide resolved
examples/fonts.ts Outdated Show resolved Hide resolved
examples/styles/index.css Show resolved Hide resolved
@goatyeahh
Copy link
Contributor Author

Sorry, I missed review the notification. I have rebase and adapted the code based on your comments. I tested locally and it works great now!

@tandrasi
Copy link

Hi, any progress of merging this into master? We could really use the functionality of this PR :).

@MatthewHerbst
Copy link
Owner

Ah, my bad guys, I had the tab open here but it got buried. Thanks for the reminder, and for fixing this up!

@MatthewHerbst MatthewHerbst merged commit 36b61df into MatthewHerbst:master Feb 19, 2023
@MatthewHerbst
Copy link
Owner

Published in v2.14.12 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants