Use alphabetical order in the sfnt header as per the spec

This commit is contained in:
Kovid Goyal 2012-11-09 16:58:31 +05:30
parent 1d9398e009
commit bd9fd5485b

View File

@ -58,16 +58,21 @@ class Sfnt(object):
del self.tables[key]
def __iter__(self):
'''Iterate over the table tags in optimal order as per
http://partners.adobe.com/public/developer/opentype/index_recs.html'''
keys = list(self.tables.keys())
order = {x:i for i, x in enumerate((b'head', b'hhea', b'maxp', b'OS/2',
b'hmtx', b'LTSH', b'VDMX', b'hdmx', b'cmap', b'fpgm', b'prep',
b'cvt ', b'loca', b'glyf', b'CFF ', b'kern', b'name', b'post',
b'gasp', b'PCLT', b'DSIG'))}
keys.sort(key=lambda x:order.get(x, 1000))
for x in keys:
'''Iterate over the table tags in order.'''
for x in sorted(self.tables.iterkeys()):
yield x
# Although the optimal order is not alphabetical, the OTF spec says
# they should be alphabetical, so we stick with that. See
# http://partners.adobe.com/public/developer/opentype/index_recs.html
# for optimal order.
# keys = list(self.tables.iterkeys())
# order = {x:i for i, x in enumerate((b'head', b'hhea', b'maxp', b'OS/2',
# b'hmtx', b'LTSH', b'VDMX', b'hdmx', b'cmap', b'fpgm', b'prep',
# b'cvt ', b'loca', b'glyf', b'CFF ', b'kern', b'name', b'post',
# b'gasp', b'PCLT', b'DSIG'))}
# keys.sort(key=lambda x:order.get(x, 1000))
# for x in keys:
# yield x
def pop(self, key, default=None):
return self.tables.pop(key, default)