Write the loca table in optimum format

Also update the head and maxp tables when subsetting
This commit is contained in:
Kovid Goyal 2019-07-28 15:39:19 +05:30
parent 7b6dc6eed9
commit dd5961af10
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)
# }}}