Can't load font using local()
See original GitHub issueRunning from the default terminal on Windows 10, if I, after installing a custom font like Google’s Noto Sans JP, use this CSS in my HTML:
@font-face{ font-family: "Noto Sans JP"; src: local("Noto Sans JP") }
WeasyPrint will throw a “WARNING: Font-face “Noto Sans JP” cannot be loaded.”, and if there are a large number of CJK characters, produce a PDF with mojibake like these:
If I reduce the amount of CJK characters enough, the PDF will be rendered okay, but with the default system font (Meiryo).
But if I put url()
instead of local()
and update my CSS to:
@font-face{ font-family: "Noto Sans JP"; src: url("NotoSansJP-Regular.otf") }
Then the HTML is rendered as it should be, with the custom font.
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Unable to load fonts - Stack Overflow
Check that your web server has permission to read the folder containing the fonts and the font files themselves.
Read more >How To Load and Use Custom Fonts with CSS | DigitalOcean
In this tutorial, you will try out examples of loading fonts onto your website. You will use the font stack, a rank ordering...
Read more >The Best Font Loading Strategies and How to Execute Them
Zach Leatherman wrote up a comprehensive list of font loading strategies that have been widely shared in the web development field.
Read more >How to load web fonts to avoid performance issues and speed ...
The local() function allows users to use their local copy of the font if present (e.g. think about the Roboto fonts that are...
Read more >Using Local Fonts | Gatsby
When you downloaded your font file(s), e.g. from Inter you fill most likely have a bunch of different files available (this can differ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
On CentOS, I think that the fix has been packported into the cairo-1.17.4-3 package. Updating to this latest version will fix the problem.
On Windows, you can use a previous version of GTK+. Version 2020-11-22 includes Cairo 1.17.2 that doesn’t have this bug.
Of course, that was just a workaround to test.
👍🏽
Hmmm… After some time spent on GitHub, I now think that it’s a bug in Fontconfig. And actually, it’s already reported: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/144. I’ve added a comment.
Done!