Skip to content
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

WOFF font not included in PDF #1237

Closed
schettino72 opened this issue Oct 15, 2020 · 5 comments
Closed

WOFF font not included in PDF #1237

schettino72 opened this issue Oct 15, 2020 · 5 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@schettino72
Copy link

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)
@grewn0uille
Copy link
Member

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) :)

@schettino72
Copy link
Author

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.

@liZe
Copy link
Member

liZe commented Oct 21, 2020

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

@liZe liZe added the bug Existing features not working as expected label Oct 21, 2020
@liZe
Copy link
Member

liZe commented Oct 27, 2020

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

@liZe liZe added this to the 52 milestone Oct 27, 2020
@liZe liZe closed this as completed in 18010a1 Oct 27, 2020
@liZe
Copy link
Member

liZe commented Oct 27, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants