From 5fe7ef6b22ae1265a52dee422e1c3b6777519ca3 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 13 Jul 2021 20:16:20 +0200 Subject: [PATCH] Ignore missing glyphs when subsetting fonts Instead of raising an error, just ignore missing fonts. Also include the notdef glyph to (hopefully) avoid invalid documents. Related to #1386. --- weasyprint/document.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weasyprint/document.py b/weasyprint/document.py index 87d5755bee..5caf991add 100644 --- a/weasyprint/document.py +++ b/weasyprint/document.py @@ -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: