Skip to content

Commit

Permalink
Ignore missing glyphs when subsetting fonts
Browse files Browse the repository at this point in the history
Instead of raising an error, just ignore missing fonts. Also include the notdef
glyph to (hopefully) avoid invalid documents.

Related to #1386.
  • Loading branch information
liZe committed Jul 13, 2021
1 parent 8b8011a commit 5fe7ef6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions weasyprint/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,13 +1227,14 @@ def write_pdf(self, target=None, zoom=1, attachments=None, finisher=None):
try:
ttfont = TTFont(full_font)
options = subset.Options(
retain_gids=True, passthrough_tables=True)
retain_gids=True, passthrough_tables=True,
ignore_missing_glyphs=True, notdef_glyph=True)
subsetter = subset.Subsetter(options)
subsetter.populate(gids=cmap)
subsetter.subset(ttfont)
ttfont.save(optimized_font)
content = optimized_font.getvalue()
except (TTLibError, subset.Subsetter.SubsettingError):
except TTLibError:
LOGGER.warning('Unable to optimize font')
content = fonts[0].file_content
else:
Expand Down

0 comments on commit 5fe7ef6

Please sign in to comment.