• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    @classmethod
50    def setUpClass(cls):
51        cls.maxDiff = None
52        cls.font = FakeFont([".notdef", "A", "B", "C", "D", "E", "F", "G"])
53
54    def test_decompile_toXML_format0(self):
55        table = newTable("prop")
56        table.decompile(PROP_FORMAT_0_DATA, self.font)
57        self.assertEqual(getXML(table.toXML), PROP_FORMAT_0_XML)
58
59    def test_compile_fromXML_format0(self):
60        table = newTable("prop")
61        for name, attrs, content in parseXML(PROP_FORMAT_0_XML):
62            table.fromXML(name, attrs, content, font=self.font)
63        self.assertEqual(hexStr(table.compile(self.font)), hexStr(PROP_FORMAT_0_DATA))
64
65    def test_decompile_toXML_format1(self):
66        table = newTable("prop")
67        table.decompile(PROP_FORMAT_1_DATA, self.font)
68        self.assertEqual(getXML(table.toXML), PROP_FORMAT_1_XML)
69
70    def test_compile_fromXML_format1(self):
71        table = newTable("prop")
72        for name, attrs, content in parseXML(PROP_FORMAT_1_XML):
73            table.fromXML(name, attrs, content, font=self.font)
74        self.assertEqual(hexStr(table.compile(self.font)), hexStr(PROP_FORMAT_1_DATA))
75
76
77if __name__ == "__main__":
78    import sys
79
80    sys.exit(unittest.main())
81