From f80b341977349f22b7586f7c34003a11733ed69f Mon Sep 17 00:00:00 2001 From: Sascha Brawer Date: Thu, 31 Aug 2017 14:44:24 +0200 Subject: [PATCH] [AAT] Another unit test for decoding the `ankr` anchor points table --- Tests/ttLib/tables/_a_n_k_r_test.py | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/Tests/ttLib/tables/_a_n_k_r_test.py b/Tests/ttLib/tables/_a_n_k_r_test.py index a5cbbc4f5..0327e46bc 100644 --- a/Tests/ttLib/tables/_a_n_k_r_test.py +++ b/Tests/ttLib/tables/_a_n_k_r_test.py @@ -20,9 +20,9 @@ ANKR_FORMAT_0_DATA = deHexStr( '0000 0024 ' # 8: GlyphDataTableOffset=36 '0006 0004 0002 ' # 12: LookupFormat=6, UnitSize=4, NUnits=2 '0008 0001 0000 ' # 18: SearchRange=8, EntrySelector=1, RangeShift=0 - '0001 0000 ' # 24: Glyph=A, GlyphDataOffset=0 (+GlyphDataOffset=36) - '0003 0008 ' # 28: Glyph=C, GlyphDataOffset=8 (+GlyphDataOffset=44) - 'FFFF 0000 ' # 32: Glyph=, GlyphDataOffset= + '0001 0000 ' # 24: Glyph=A, Offset=0 (+GlyphDataTableOffset=36) + '0003 0008 ' # 28: Glyph=C, Offset=8 (+GlyphDataTableOffset=44) + 'FFFF 0000 ' # 32: Glyph=, Offset= '0000 0001 ' # 36: GlyphData[A].NumPoints=1 '0235 045E ' # 40: GlyphData[A].Points[0].X=565, .Y=1118 '0000 0001 ' # 44: GlyphData[C].NumPoints=1 @@ -54,6 +54,28 @@ ANKR_FORMAT_0_XML = [ ] +# Same data as ANKR_FORMAT_0_DATA, but with chunks of unused data +# whose presence should not stop us from decompiling the table. +ANKR_FORMAT_0_STRAY_DATA = deHexStr( + '0000 0000 ' # 0: Format=0, Flags=0 + '0000 0018 ' # 4: LookupTableOffset=24 + '0000 0034 ' # 8: GlyphDataTableOffset=52 + 'DEAD BEEF CAFE ' # 12: + 'DEAD BEEF CAFE ' # 18: + '0006 0004 0002 ' # 24: LookupFormat=6, UnitSize=4, NUnits=2 + '0008 0001 0000 ' # 30: SearchRange=8, EntrySelector=1, RangeShift=0 + '0001 0000 ' # 36: Glyph=A, Offset=0 (+GlyphDataTableOffset=52) + '0003 0008 ' # 40: Glyph=C, Offset=8 (+GlyphDataTableOffset=60) + 'FFFF 0000 ' # 44: Glyph=, Offset= + 'BEEF F00D ' # 48: + '0000 0001 ' # 52: GlyphData[A].NumPoints=1 + '0235 045E ' # 56: GlyphData[A].Points[0].X=565, .Y=1118 + '0000 0001 ' # 60: GlyphData[C].NumPoints=1 + 'FED2 045E ' # 64: GlyphData[C].Points[0].X=-302, .Y=1118 +) # 68: +assert len(ANKR_FORMAT_0_STRAY_DATA) == 68 + + # Constructed test case where glyphs A and D share the same anchor data. ANKR_FORMAT_0_SHARING_DATA = deHexStr( '0000 0000 ' # 0: Format=0, Flags=0 @@ -61,10 +83,10 @@ ANKR_FORMAT_0_SHARING_DATA = deHexStr( '0000 0028 ' # 8: GlyphDataTableOffset=40 '0006 0004 0003 ' # 12: LookupFormat=6, UnitSize=4, NUnits=3 '0008 0001 0004 ' # 18: SearchRange=8, EntrySelector=1, RangeShift=4 - '0001 0000 ' # 24: Glyph=A, GlyphDataOffset=0 (+GlyphDataOffset=36) - '0003 0008 ' # 28: Glyph=C, GlyphDataOffset=8 (+GlyphDataOffset=44) - '0004 0000 ' # 32: Glyph=D, GlyphDataOffset=0 (+GlyphDataOffset=36) - 'FFFF 0000 ' # 36: Glyph=, GlyphDataOffset= + '0001 0000 ' # 24: Glyph=A, Offset=0 (+GlyphDataTableOffset=36) + '0003 0008 ' # 28: Glyph=C, Offset=8 (+GlyphDataTableOffset=44) + '0004 0000 ' # 32: Glyph=D, Offset=0 (+GlyphDataTableOffset=36) + 'FFFF 0000 ' # 36: Glyph=, Offset= '0000 0001 ' # 40: GlyphData[A].NumPoints=1 '0235 045E ' # 44: GlyphData[A].Points[0].X=565, .Y=1118 '0000 0002 ' # 48: GlyphData[C].NumPoints=2 @@ -133,6 +155,9 @@ class ANKRTest(unittest.TestCase): def testFormat0(self): self.roundtrip(ANKR_FORMAT_0_DATA, ANKR_FORMAT_0_XML) + def testFormat0_stray(self): + self.decompileToXML(ANKR_FORMAT_0_STRAY_DATA, ANKR_FORMAT_0_XML) + def testFormat0_sharing(self): self.roundtrip(ANKR_FORMAT_0_SHARING_DATA, ANKR_FORMAT_0_SHARING_XML)