Better error message when there is a glyph mismatch

This commit is contained in:
Kovid Goyal 2019-10-07 06:41:14 +05:30
parent c668fec87b
commit 2207a86ea7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,6 +8,10 @@ from collections import OrderedDict
from functools import partial from functools import partial
class GlyphSizeMismatch(ValueError):
pass
def merge_truetype_fonts_for_pdf(*fonts): def merge_truetype_fonts_for_pdf(*fonts):
# only merges the glyf and loca tables, ignoring all other tables # only merges the glyf and loca tables, ignoring all other tables
all_glyphs = {} all_glyphs = {}
@ -24,7 +28,7 @@ def merge_truetype_fonts_for_pdf(*fonts):
all_glyphs[glyph_id] = glyf.glyph_data(offset, sz, as_raw=True) all_glyphs[glyph_id] = glyf.glyph_data(offset, sz, as_raw=True)
else: else:
if sz != len(prev_glyph_data): if sz != len(prev_glyph_data):
raise Exception('Size mismatch for glyph id: {}'.format(glyph_id)) raise GlyphSizeMismatch('Size mismatch for glyph id: {} prev_sz: {} sz: {}'.format(glyph_id, len(prev_glyph_data), sz))
glyf = ans[b'glyf'] glyf = ans[b'glyf']
head = ans[b'head'] head = ans[b'head']