mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Write the loca table in optimum format
Also update the head and maxp tables when subsetting
This commit is contained in:
parent
7b6dc6eed9
commit
dd5961af10
@ -85,7 +85,10 @@ class GlyfTable(UnknownTable):
|
||||
block = []
|
||||
for glyph_id, glyph in iteritems(sorted_glyph_map):
|
||||
raw = glyph()
|
||||
ans[glyph_id] = (offset, len(raw))
|
||||
pad = 4 - (len(raw) % 4)
|
||||
if pad < 4:
|
||||
raw += b'\0' * pad
|
||||
ans[glyph_id] = offset, len(raw)
|
||||
offset += len(raw)
|
||||
block.append(raw)
|
||||
self.raw = b''.join(block)
|
||||
|
@ -53,8 +53,15 @@ class LocaTable(UnknownTable):
|
||||
self.offset_map[i] = self.offset_map[i-1]
|
||||
|
||||
vals = self.offset_map
|
||||
max_offset = max(vals) if vals else 0
|
||||
max_short_offset = 65535 * 2
|
||||
if self.fmt == 'L' and max_offset <= max_short_offset:
|
||||
self.fmt = 'H'
|
||||
if self.fmt == 'H':
|
||||
vals = [i//2 for i in self.offset_map]
|
||||
if max_offset > max_short_offset:
|
||||
self.fmt = 'L'
|
||||
else:
|
||||
vals = [i//2 for i in vals]
|
||||
|
||||
self.raw = pack(('>%d%s'%(len(vals), self.fmt)).encode('ascii'), *vals)
|
||||
subset = update
|
||||
|
@ -64,6 +64,9 @@ def subset_truetype(sfnt, character_map, extra_glyphs):
|
||||
|
||||
# Update the loca table
|
||||
loca.subset(glyph_offset_map)
|
||||
head.index_to_loc_format = 1 if loca.fmt == 'L' else 0
|
||||
head.update()
|
||||
maxp.num_glyphs = len(glyph_offset_map)
|
||||
|
||||
# }}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user