question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't load font using local()

See original GitHub issue

Running 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: image

If I reduce the amount of CJK characters enough, the PDF will be rendered okay, but with the default system font (Meiryo). image

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. image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
liZecommented, Apr 22, 2021

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.

0reactions
liZecommented, May 6, 2021

Thanks, your suggestion works perfectly! As noted in fonts.conf tho people shouldn’t edit that file since updates will override it

Of course, that was just a workaround to test.

so I put <dir>~/AppData/Local/Microsoft/Windows/Fonts</dir> in etc\fonts\conf.d\51-local.conf instead and it works immediately.

👍🏽

I’m not familiar with the GTK installer so I’ll have to leave the issue creation to you, is that okay?

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.

And if there are any other info you need I’ll try to answer it, else you can close this bug.

Done!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found