-
-
Notifications
You must be signed in to change notification settings - Fork 712
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
Can't load font using local() #1337
Comments
Hello! I can reproduce your problem. Actually, these fonts have their font weights in their fullnames (that WeasyPrint uses to solve |
The Noto Sans JP Regular font name is just "Noto Sans JP" (no "Regular") or at least that what the file's Property dialog told me, so shouldn't my example work then? |
That’s also what my font viewer also says, but this name is the font family. The full name used by Fontconfig is the family name + weight + style + …, so that you can precisely choose the font you need. We could be nicer and have fallbacks for
It does work for me, I hope that it will work for you too 🤞. |
Bad news: After a bunch of testing, here're some of my observation:
So apparently it has something to do with my Windows, but I don't know where to go from here. |
That’s where I got the font too. But… Well, it’s actually useless to only use
It probably means that the font is not installed correctly. How did you install the font?
Adding fonts in the PDF can take some time, but 5 seconds seems to be a little bit too long. Which version of WeasyPrint do you use? |
Version 52.4. Times taken before: 5s. Times taken after adding 7 font-face: 34s. |
Experiment today on Windows with
Even a custom font-face pointing to local("Yu Gothic") doesn't work on Windows. |
(Not a direct answer, but to be clear:
That’s strange. Could you please share your HTML+CSS sample, and the corresponding PDF files?
That’s normal (see above).
That’s normal too (see above). |
Sorry for being so late. I've created a sample HTML file that has the same problem and sent it to your email, guillaume@courtbouillon.org. Since I've remove almost every CSS rule and HTML layout possible, my current guess is that the problem has something to do with the amount of characters WeasyPrint has to draw. If I cut short the amount of different characters in the sample file, or instead of using multiple characters just repeating a few lines for the same amount of characters, the problem would not occur. |
I should have checked the PDF as soon as this issue was reported! The bug you have is actually a duplicate of #1292, that just randomly breaks fonts included in PDF documents 😒. Using a previous version of Cairo will fix your problem (until Cairo releases a new version including the fix). |
How you tell me how to downgrade Cairo on CentOS and Windows (I have 2 separate environments)? I'm not familiar with Yum, and on Windows Cairo comes with the GTK+ package so I'm not sure whether to find an older version of libcairo-2.dll (?) or GTK+. |
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. |
Thanks liZe, characters are now not corrupted randomly anymore!
|
These two should work, because that’s the common use case:
This one should work too because of fuzzy matching:
This one may not work, by design:
If the first ones don’t work, it means that Fontconfig can’t find the installed font. Where is your font installed? If it is in |
Sadly, it's in the usual place, |
Then I really don’t know what’s wrong. Could you please try to launch |
Oh. These interfaces can really be misleading… So, it means that we actually have the same problem as NatronGitHub/Natron@5758f2d. You can try to add If it works, we can open a new issue for tschoonj/GTK-for-Windows-Runtime-Environment-Installer, asking them to include the same fix as NatronGitHub/Natron@5758f2d. |
Thanks, your suggestion works perfectly! As noted in |
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! |
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:
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 oflocal()
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.
The text was updated successfully, but these errors were encountered: