PDF Output: Fix error when input document contains multiple instances of a font some with vertical metric and some without. Fixes #2023041 [Private bug](https://bugs.launchpad.net/calibre/+bug/2023041)

This commit is contained in:
Kovid Goyal 2023-06-07 19:52:04 +05:30
parent f2b8bc9dd3
commit 2c89d50fb8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -50,11 +50,17 @@ def merge_truetype_fonts_for_pdf(fonts, log=None):
log(f'Size mismatch for glyph id: {glyph_id} prev_sz: {len(prev_glyph_data)} sz: {sz}') log(f'Size mismatch for glyph id: {glyph_id} prev_sz: {len(prev_glyph_data)} sz: {sz}')
if hhea is not None: if hhea is not None:
m = hhea.metrics_for(glyph_id) m = hhea.metrics_for(glyph_id)
if m != hmetrics_map[glyph_id]: old_val = hmetrics_map.get(glyph_id)
if old_val is None:
hmetrics_map[glyph_id] = m
elif m != old_val:
log(f'Metrics mismatch for glyph id: {glyph_id} prev: {hmetrics_map[glyph_id]} cur: {m}') log(f'Metrics mismatch for glyph id: {glyph_id} prev: {hmetrics_map[glyph_id]} cur: {m}')
if vhea is not None: if vhea is not None:
m = vhea.metrics_for(glyph_id) m = vhea.metrics_for(glyph_id)
if m != vmetrics_map[glyph_id]: old_val = vmetrics_map.get(glyph_id)
if old_val is None:
vmetrics_map[glyph_id] = m
elif m != vmetrics_map[glyph_id]:
log(f'Metrics mismatch for glyph id: {glyph_id} prev: {vmetrics_map[glyph_id]} cur: {m}') log(f'Metrics mismatch for glyph id: {glyph_id} prev: {vmetrics_map[glyph_id]} cur: {m}')
glyf = ans[b'glyf'] glyf = ans[b'glyf']
@ -71,9 +77,9 @@ def merge_truetype_fonts_for_pdf(fonts, log=None):
head.update() head.update()
maxp.num_glyphs = len(loca.offset_map) - 1 maxp.num_glyphs = len(loca.offset_map) - 1
maxp.update() maxp.update()
if hmetrics_map: if hmetrics_map and b'hhea' in ans:
ans[b'hhea'].update(hmetrics_map, ans[b'hmtx']) ans[b'hhea'].update(hmetrics_map, ans[b'hmtx'])
if vmetrics_map: if vmetrics_map and b'vhea' in ans:
ans[b'vhea'].update(vmetrics_map, ans[b'vmtx']) ans[b'vhea'].update(vmetrics_map, ans[b'vmtx'])
for name in 'hdmx GPOS GSUB'.split(): for name in 'hdmx GPOS GSUB'.split():