"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/calibre/utils/fonts/sfnt/merge.py" between
calibre-4.0.0.tar.xz and calibre-4.1.0.tar.xz

About: calibre is an e-book library management application (syncing, converting, viewing,\PKG_DESCR_TTnbsp;...).

merge.py  (calibre-4.0.0.tar.xz):merge.py  (calibre-4.1.0.tar.xz)
#!/usr/bin/env python2 #!/usr/bin/env python2
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import absolute_import, division, print_function, unicode_litera ls from __future__ import absolute_import, division, print_function, unicode_litera ls
from collections import OrderedDict 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 = {}
ans = fonts[0] ans = fonts[0]
for font in fonts: for font in fonts:
loca = font[b'loca'] loca = font[b'loca']
glyf = font[b'glyf'] glyf = font[b'glyf']
loca.load_offsets(font[b'head'], font[b'maxp']) loca.load_offsets(font[b'head'], font[b'maxp'])
for glyph_id in range(len(loca.offset_map) - 1): for glyph_id in range(len(loca.offset_map) - 1):
offset, sz = loca.glyph_location(glyph_id) offset, sz = loca.glyph_location(glyph_id)
if sz > 0: if sz > 0:
prev_glyph_data = all_glyphs.get(glyph_id) prev_glyph_data = all_glyphs.get(glyph_id)
if prev_glyph_data is None: if prev_glyph_data is None:
all_glyphs[glyph_id] = glyf.glyph_data(offset, sz, as_raw=Tr ue) all_glyphs[glyph_id] = glyf.glyph_data(offset, sz, as_raw=Tr ue)
else: else:
if sz != len(prev_glyph_data): if abs(sz - len(prev_glyph_data)) > 4:
raise Exception('Size mismatch for glyph id: {}'.format( raise GlyphSizeMismatch('Size mismatch for glyph id: {}
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']
loca = ans[b'loca'] loca = ans[b'loca']
maxp = ans[b'maxp'] maxp = ans[b'maxp']
advance_widths = advance_heights = (0,) advance_widths = advance_heights = (0,)
hhea = ans.get(b'hhea') hhea = ans.get(b'hhea')
if hhea is not None: if hhea is not None:
hhea.read_data(ans[b'hmtx']) hhea.read_data(ans[b'hmtx'])
advance_widths = tuple(x/head.units_per_em for x in hhea.advance_widths) advance_widths = tuple(x/head.units_per_em for x in hhea.advance_widths)
 End of changes. 2 change blocks. 
3 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)