aboutsummaryrefslogtreecommitdiff
path: root/Tests/ttLib/tables/_c_i_d_g_test.py
blob: 11c1fc0f22344016e265a0e66f250ba243537338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from fontTools.misc.testTools import FakeFont, getXML, parseXML
from fontTools.misc.textTools import deHexStr, hexStr
from fontTools.ttLib import newTable
import unittest


# On macOS X 10.12.6, the first font in /System/Library/Fonts/PingFang.ttc
# has a ‘cidg’ table with a similar structure as this test data, just larger.
CIDG_DATA = deHexStr(
    "0000 0000 "          #   0: Format=0, Flags=0
    "0000 0098 "          #   4: StructLength=152
    "0000 "               #   8: Registry=0
    "41 64 6F 62 65 "     #  10: RegistryName="Adobe"
    + ("00" * 59) +       #  15: <padding>
    "0002 "               #  74: Order=2
    "43 4E 53 31 "        #  76: Order="CNS1"
    + ("00" * 60) +       #  80: <padding>
    "0000 "               # 140: SupplementVersion=0
    "0004 "               # 142: Count
    "0000 "               # 144: GlyphID[0]=.notdef
    "FFFF "               # 146: CIDs[1]=<None>
    "0003 "               # 148: CIDs[2]=C
    "0001 "               # 150: CIDs[3]=A
)                         # 152: <end>
assert len(CIDG_DATA) == 152, len(CIDG_DATA)


CIDG_XML = [
   '<CIDGlyphMapping Format="0">',
   '  <DataFormat value="0"/>',
   '  <!-- StructLength=152 -->',
   '  <Registry value="0"/>',
   '  <RegistryName value="Adobe"/>',
   '  <Order value="2"/>',
   '  <OrderName value="CNS1"/>',
   '  <SupplementVersion value="0"/>',
   '  <Mapping>',
   '    <CID cid="0" glyph=".notdef"/>',
   '    <CID cid="2" glyph="C"/>',
   '    <CID cid="3" glyph="A"/>',
   '  </Mapping>',
   '</CIDGlyphMapping>',
]


class GCIDTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.maxDiff = None
        cls.font = FakeFont(['.notdef', 'A', 'B', 'C', 'D'])

    def testDecompileToXML(self):
        table = newTable('cidg')
        table.decompile(CIDG_DATA, self.font)
        self.assertEqual(getXML(table.toXML, self.font), CIDG_XML)

    def testCompileFromXML(self):
        table = newTable('cidg')
        for name, attrs, content in parseXML(CIDG_XML):
            table.fromXML(name, attrs, content, font=self.font)
        self.assertEqual(hexStr(table.compile(self.font)),
                         hexStr(CIDG_DATA))


if __name__ == '__main__':
    import sys
    sys.exit(unittest.main())