1from fontTools.misc.testTools import FakeFont, getXML, parseXML 2from fontTools.misc.textTools import deHexStr, hexStr 3from fontTools.ttLib import newTable 4import unittest 5 6 7PROP_FORMAT_0_DATA = deHexStr( 8 '0001 0000 0000 ' # 0: Version=1.0, Format=0 9 '0005 ' # 6: DefaultProperties=European number terminator 10) # 8: <end> 11assert(len(PROP_FORMAT_0_DATA) == 8) 12 13 14PROP_FORMAT_0_XML = [ 15 '<Version value="1.0"/>', 16 '<GlyphProperties Format="0">', 17 ' <DefaultProperties value="5"/>', 18 '</GlyphProperties>', 19] 20 21 22PROP_FORMAT_1_DATA = deHexStr( 23 '0003 0000 0001 ' # 0: Version=3.0, Format=1 24 '0000 ' # 6: DefaultProperties=left-to-right; non-whitespace 25 '0008 0003 0004 ' # 8: LookupFormat=8, FirstGlyph=3, GlyphCount=4 26 '000B ' # 14: Properties[C]=other neutral 27 '000A ' # 16: Properties[D]=whitespace 28 '600B ' # 18: Properties[E]=other neutral; hanging punct 29 '0005 ' # 20: Properties[F]=European number terminator 30) # 22: <end> 31assert(len(PROP_FORMAT_1_DATA) == 22) 32 33 34PROP_FORMAT_1_XML = [ 35 '<Version value="3.0"/>', 36 '<GlyphProperties Format="1">', 37 ' <DefaultProperties value="0"/>', 38 ' <Properties>', 39 ' <Lookup glyph="C" value="11"/>', 40 ' <Lookup glyph="D" value="10"/>', 41 ' <Lookup glyph="E" value="24587"/>', 42 ' <Lookup glyph="F" value="5"/>', 43 ' </Properties>', 44 '</GlyphProperties>', 45] 46 47 48class PROPTest(unittest.TestCase): 49 50 @classmethod 51 def setUpClass(cls): 52 cls.maxDiff = None 53 cls.font = FakeFont(['.notdef', 'A', 'B', 'C', 'D', 'E', 'F', 'G']) 54 55 def test_decompile_toXML_format0(self): 56 table = newTable('prop') 57 table.decompile(PROP_FORMAT_0_DATA, self.font) 58 self.assertEqual(getXML(table.toXML), PROP_FORMAT_0_XML) 59 60 def test_compile_fromXML_format0(self): 61 table = newTable('prop') 62 for name, attrs, content in parseXML(PROP_FORMAT_0_XML): 63 table.fromXML(name, attrs, content, font=self.font) 64 self.assertEqual(hexStr(table.compile(self.font)), 65 hexStr(PROP_FORMAT_0_DATA)) 66 67 def test_decompile_toXML_format1(self): 68 table = newTable('prop') 69 table.decompile(PROP_FORMAT_1_DATA, self.font) 70 self.assertEqual(getXML(table.toXML), PROP_FORMAT_1_XML) 71 72 def test_compile_fromXML_format1(self): 73 table = newTable('prop') 74 for name, attrs, content in parseXML(PROP_FORMAT_1_XML): 75 table.fromXML(name, attrs, content, font=self.font) 76 self.assertEqual(hexStr(table.compile(self.font)), 77 hexStr(PROP_FORMAT_1_DATA)) 78 79 80if __name__ == '__main__': 81 import sys 82 sys.exit(unittest.main()) 83