PDF Output: Disable subsetting of embedded TrueType fonts to workaround a bug in chromium as of Qt 6.7.2

This commit is contained in:
Kovid Goyal 2024-08-14 19:45:04 +05:30
parent 4232224213
commit 3d477b904c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -843,14 +843,18 @@ def merge_font_files(fonts, log):
descendant_fonts = [f for f in fonts if f['Subtype'] != 'Type0']
total_size = sum(len(f['Data']) for f in descendant_fonts)
merged_sfnt = merge_truetype_fonts_for_pdf(tuple(f['sfnt'] for f in descendant_fonts), log)
w_arrays = tuple(filter(None, (f['W'] for f in descendant_fonts)))
glyph_ids = all_glyph_ids_in_w_arrays(w_arrays, as_set=True)
h_arrays = tuple(filter(None, (f['W2'] for f in descendant_fonts)))
glyph_ids |= all_glyph_ids_in_w_arrays(h_arrays, as_set=True)
try:
pdf_subset(merged_sfnt, glyph_ids)
except NoGlyphs:
log.warn(f'Subsetting of {fonts[0]["BaseFont"]} failed with no glyphs found, ignoring')
if False:
# As of Qt 6.7.2 webengine produces W arrays that do not contain all
# used glyph ids, so we cannot subset. Can be tested by
# echo 'this is a test boulder sentence' > test.txt; ebook-convert test.txt .pdf
w_arrays = tuple(filter(None, (f['W'] for f in descendant_fonts)))
glyph_ids = all_glyph_ids_in_w_arrays(w_arrays, as_set=True)
h_arrays = tuple(filter(None, (f['W2'] for f in descendant_fonts)))
glyph_ids |= all_glyph_ids_in_w_arrays(h_arrays, as_set=True)
try:
pdf_subset(merged_sfnt, glyph_ids)
except NoGlyphs:
log.warn(f'Subsetting of {fonts[0]["BaseFont"]} failed with no glyphs found, ignoring')
font_data = merged_sfnt()[0]
log(f'Merged {len(fonts)} instances of {fonts[0]["BaseFont"]} reducing size from {human_readable(total_size)} to {human_readable(len(font_data))}')
return font_data, tuple(f['Reference'] for f in descendant_fonts)