-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add font-weight and font-style support #535
Conversation
@diegomura Thanks so much for doing this! I’ll look through it tomorrow and let you know my thoughts. (Sorry, I wanted to focus on pull 538 these last couple of days and get it done.) |
Thank you! I'll review also your PR tomorrow 😄 |
In summary, LGTM! I like how you’ve implemented this. I’ve used TypeScript before but I’m not currently using it, so I would like to check your syntax with a TS linter. But without checking, your typings look good. I think there may be an opportunity to optimise data usage by only downloading registered fonts once they are actually used, but this can go in separately somehow. |
Thank you @DuncanMacWeb !!
This actually happens now. We don't download the font when it get's registered, but when it's loaded. This method get's called before rendering the doc only for the font descriptors present on the document What would be cool in the future is creating a font subset only with the used glyphs, but that's something that should be implemented in |
Btw. is there an easy way of running a TS linter? |
@diegomura heads up, there appears to be a bug in this PR that causes fonts to be re-downloaded multiple times. Have you also observed this? |
Oops. No! I'll take a look at it asap. Good thing it's not published in npm yet |
@DuncanMacWeb fixed in #547 |
We haven’t tried it yet — will report back! |
What this PR do
This adds the ability to setup font-styles and font-weights when registering fonts:
When rendering, react-pdf will choose the appropriate font in the same way the web does.
"Bulk" font loading
Since we now support referring to different font files by using the same fontFamily value, IMO would be cool to be able to load one fontFamily in one
register
call:Other options such as
method
,headers
andbody
that we currently support should still work for each font.Change register API
We currently pass the font src in the first argument to
Font.register
, and all other options into the second. To achieve the latter point (and if we want to support CSS@font-face
attribute in the future) it would be cool to have the API like this:We should still support the current API, by showing a deprecated warning
TODO
@DuncanMacWeb inputs?
Fixes #402