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

write_pdf crashes during font optimisation when glyphs are missing in 53b2 #1386

Closed
circlingthesun opened this issue Jun 30, 2021 · 2 comments
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@circlingthesun
Copy link

Try create a PDF containing "부산시 " with Open Sans or any other font without korean glyphs. The resulting stack trace is:

  File "/usr/local/lib/python3.8/dist-packages/weasyprint/__init__.py", line 180, in write_pdf
    self.render(
  File "/usr/local/lib/python3.8/dist-packages/weasyprint/document.py", line 1219, in write_pdf
    subsetter.subset(ttfont)
  File "/usr/local/lib/python3.8/dist-packages/fontTools/subset/__init__.py", line 2899, in subset
    self._closure_glyphs(font)
  File "/usr/local/lib/python3.8/dist-packages/fontTools/subset/__init__.py", line 2718, in _closure_glyphs
    raise self.MissingGlyphsSubsettingError(self.glyphs_missing)
fontTools.subset.Subsetter.MissingGlyphsSubsettingError: {268481280, 268483968, 268488896, 268486660, 268490244, 268486180, 268485284, 268480008, 268486565, 268479852, 268484784, 268484913, 268486320, 268486677, 268490296, 268481497, 268485340}

A workaround is to pass write_pdf optimize_size=().

@circlingthesun
Copy link
Author

On version 52.5 I got tofu characters instead of a crash. I managed to get rid of the error by installing the 'fonts-noto-cjk' package on Ubuntu, and at the same time got rid of the tofu characters. I'm assuming the noto font is being used a fallback. The only problem is that my PDF grew to 16mb from the original 67kb in version 52.5. That's without setting the optimize_size parameter to an empty tuple. I'm assuming the whole fallback is being embedded.

@liZe liZe added the crash Problems preventing documents from being rendered label Jul 1, 2021
@liZe liZe added this to the 53.0 milestone Jul 12, 2021
@liZe liZe closed this as completed in 8b8011a Jul 13, 2021
@liZe
Copy link
Member

liZe commented Jul 13, 2021

Hello! Thanks a lot for this report.

It’s not easy to test, because most systems have a fallback font for virtually any character, but it seems to work now. With 52.5, Cairo was probably able to insert a tofu character for missing glyphes.

Feel free to test, I hope that the generated document is valid.

liZe added a commit that referenced this issue Jul 13, 2021
Instead of raising an error, just ignore missing fonts. Also include the notdef
glyph to (hopefully) avoid invalid documents.

Related to #1386.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants