[AAT] Fix decompilation of AppleChancery and other AAT fonts

Fixes https://github.com/fonttools/fonttools/issues/1031.
This commit is contained in:
Sascha Brawer 2017-08-19 02:31:30 +02:00
parent cc645c4396
commit 2f69d2959c
2 changed files with 68 additions and 1 deletions

View File

@ -749,7 +749,9 @@ class AATLookup(BaseConverter):
first = reader.readUShort()
offset = reader.readUShort()
if last != 0xFFFF:
dataReader = reader.getSubReader(pos + offset)
# https://github.com/fonttools/fonttools/issues/1031
dataReader = reader.getSubReader(0)
dataReader.seek(pos + offset)
data = self.converter.readArray(
dataReader, font, tableDict=None,
count=last - first + 1)

View File

@ -78,6 +78,64 @@ OPBD_FORMAT_1_XML = [
]
# This is the content of the Optical Bounds table in AppleChancery.ttf,
# font version 8.0d1e1 of 2013-02-06. An early version of fontTools
# was crashing when trying to decompile this table.
# https://github.com/fonttools/fonttools/issues/1031
OPBD_APPLE_CHANCERY_DATA = deHexStr(
'0001 0000 0000 ' # 0: Version=1.0, Format=0
'0004 0006 0011 ' # 6: LookupFormat=4, UnitSize=6, NUnits=17
'0060 0004 0006 ' # 12: SearchRange=96, EntrySelector=4, RangeShift=6
'017d 017d 0072 ' # 18: Seg[0].LastGlyph=381, FirstGlyph=381, Off=114(+6)
'0183 0180 0074 ' # 24: Seg[1].LastGlyph=387, FirstGlyph=384, Off=116(+6)
'0186 0185 007c ' # 30: Seg[2].LastGlyph=390, FirstGlyph=389, Off=124(+6)
'018f 018b 0080 ' # 36: Seg[3].LastGlyph=399, FirstGlyph=395, Off=128(+6)
'01a0 0196 008a ' # 42: Seg[4].LastGlyph=416, FirstGlyph=406, Off=138(+6)
'01a5 01a3 00a0 ' # 48: Seg[5].LastGlyph=421, FirstGlyph=419, Off=160(+6)
'01aa 01aa 00a6 ' # 54: Seg[6].LastGlyph=426, FirstGlyph=426, Off=166(+6)
'01ac 01ac 00a8 ' # 60: Seg[7].LastGlyph=428, FirstGlyph=428, Off=168(+6)
'01fb 01f1 00aa ' # 66: Seg[8].LastGlyph=507, FirstGlyph=497, Off=170(+6)
'0214 0209 00c0 ' # 72: Seg[9].LastGlyph=532, FirstGlyph=521, Off=192(+6)
'021d 0216 00d8 ' # 78: Seg[10].LastGlyph=541, FirstGlyph=534, Off=216(+6)
'0222 0220 00e8 ' # 84: Seg[11].LastGlyph=546, FirstGlyph=544, Off=232(+6)
'0227 0225 00ee ' # 90: Seg[12].LastGlyph=551, FirstGlyph=549, Off=238(+6)
'0229 0229 00f4 ' # 96: Seg[13].LastGlyph=553, FirstGlyph=553, Off=244(+6)
'023b 023b 00f6 ' # 102: Seg[14].LastGlyph=571, FirstGlyph=571, Off=246(+6)
'023e 023e 00f8 ' # 108: Seg[15].LastGlyph=574, FirstGlyph=574, Off=248(+6)
'ffff ffff 00fa ' # 114: Seg[16]=<end>
'0100 0108 0110 0118 0120 0128 0130 0138 0140 0148 0150 0158 '
'0160 0168 0170 0178 0180 0188 0190 0198 01a0 01a8 01b0 01b8 '
'01c0 01c8 01d0 01d8 01e0 01e8 01f0 01f8 0200 0208 0210 0218 '
'0220 0228 0230 0238 0240 0248 0250 0258 0260 0268 0270 0278 '
'0280 0288 0290 0298 02a0 02a8 02b0 02b8 02c0 02c8 02d0 02d8 '
'02e0 02e8 02f0 02f8 0300 0308 0310 0318 fd98 0000 0000 0000 '
'fdbc 0000 0000 0000 fdbc 0000 0000 0000 fdbf 0000 0000 0000 '
'fdbc 0000 0000 0000 fd98 0000 0000 0000 fda9 0000 0000 0000 '
'fd98 0000 0000 0000 fd98 0000 0000 0000 fd98 0000 0000 0000 '
'0000 0000 0205 0000 0000 0000 0205 0000 0000 0000 02a4 0000 '
'0000 0000 027e 0000 0000 0000 02f4 0000 0000 0000 02a4 0000 '
'0000 0000 0365 0000 0000 0000 0291 0000 0000 0000 0291 0000 '
'0000 0000 026a 0000 0000 0000 02b8 0000 0000 0000 02cb 0000 '
'0000 0000 02a4 0000 0000 0000 01a9 0000 0000 0000 0244 0000 '
'0000 0000 02a4 0000 0000 0000 02cb 0000 0000 0000 0244 0000 '
'0000 0000 0307 0000 0000 0000 0307 0000 0000 0000 037f 0000 '
'0000 0000 0307 0000 0000 0000 0307 0000 0000 0000 0307 0000 '
'0000 0000 0307 0000 0000 0000 0307 0000 0000 0000 03e3 0000 '
'0000 0000 030c 0000 0000 0000 0307 0000 fe30 0000 0000 0000 '
'fe7e 0000 0000 0000 fe91 0000 0000 0000 fe6a 0000 0000 0000 '
'fe6a 0000 0000 0000 fecb 0000 0000 0000 fe6a 0000 0000 0000 '
'fe7e 0000 0000 0000 fea4 0000 0000 0000 fe7e 0000 0000 0000 '
'fe44 0000 0000 0000 fea4 0000 0000 0000 feb8 0000 0000 0000 '
'fe7e 0000 0000 0000 fe5e 0000 0000 0000 fe37 0000 0000 0000 '
'fe37 0000 0000 0000 fcbd 0000 0000 0000 fd84 0000 0000 0000 '
'fd98 0000 0000 0000 fd82 0000 0000 0000 fcbd 0000 0000 0000 '
'fd84 0000 0000 0000 fcbd 0000 0000 0000 fcbd 0000 0000 0000 '
'fe72 0000 0000 0000 ff9d 0000 0000 0000 0000 0000 032f 0000 '
'0000 0000 03ba 0000 '
)
assert len(OPBD_APPLE_CHANCERY_DATA) == 800
class OPBDTest(unittest.TestCase):
@classmethod
@ -112,6 +170,13 @@ class OPBDTest(unittest.TestCase):
self.assertEqual(hexStr(table.compile(self.font)),
hexStr(OPBD_FORMAT_1_DATA))
def test_decompile_AppleChancery(self):
# Make sure we do not crash when decompiling the 'opbd' table of
# AppleChancery.ttf. https://github.com/fonttools/fonttools/issues/1031
table = newTable('opbd')
table.decompile(OPBD_APPLE_CHANCERY_DATA, self.font)
self.assertIn('<OpticalBounds Format="0">', getXML(table.toXML))
if __name__ == '__main__':
import sys