If I follow the example below but use a WOFF font.
font-face is parsed correctly but the actual font file is NOT included in the PDF,
resulting in output with "missing unicode characters" blocks...
Documentation claims any FreeType font format should be supported.
from weasyprint import HTML, CSS
from weasyprint.fonts import FontConfiguration
font_config = FontConfiguration()
html = HTML(string='<h1>The title</h1>')
css = CSS(string='''
@font-face {
font-family: Gentium;
src: url(http://example.com/fonts/Gentium.otf);
}
h1 { font-family: Gentium }''', font_config=font_config)
html.write_pdf(
'/tmp/example.pdf', stylesheets=[css],
font_config=font_config)
Hi @schettino72!
WOFF is not FreeType, and so it’s currently not supported.
But when we’ll get rid of Cairo, it’ll be! (work in progress) :)
Thanks for quick answer:
Documentation links to this Wikipedia page: https://en.wikipedia.org/wiki/FreeType#File_formats
Support of WOFF font format was added in 2.5.1.
Anyway even if not supported I guess it should display an error message, and maybe use a fallback font instead of generating gibberish PDF output.
As far as I can remember, WOFF (and now WOFF2) fonts are supported by FreeType, but for some reason they’re not included in the PDF, probably because of Cairo. It’s sad because FreeType doesn’t complain, Cairo doesn’t complain, and everything works as if the font could be embedded. At least when the format is not supported we have a warning and we can get another fallback format if possible…
This will be solved when Cairo is replaced by another library (you can follow #1232 for more news about this topic).
This will be solved when Cairo is replaced by another library (you can follow #1232 for more news about this topic).
It is. Woff support is quite slow but works very well.
We have to fix this issue in master too before the next version (with Cairo).
WOFF and WOFF2 support has been disabled for the next release (52), with a clean fallback to other formats if possible. Documentation has been fixed too. Unless someone finds a better solution, we’ll have to wait for version 53 (without Cairo) to have WOFF fonts supported by WeasyPrint.
Most helpful comment
As far as I can remember, WOFF (and now WOFF2) fonts are supported by FreeType, but for some reason they’re not included in the PDF, probably because of Cairo. It’s sad because FreeType doesn’t complain, Cairo doesn’t complain, and everything works as if the font could be embedded. At least when the format is not supported we have a warning and we can get another fallback format if possible…
This will be solved when Cairo is replaced by another library (you can follow #1232 for more news about this topic).