• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""cffLib_test.py -- unit test for Adobe CFF fonts."""
2
3from __future__ import print_function, division, absolute_import
4from __future__ import unicode_literals
5from fontTools.misc.py23 import *
6from fontTools.ttLib import TTFont, newTable
7import re
8import os
9import unittest
10
11
12CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
13DATA_DIR = os.path.join(CURR_DIR, 'data')
14
15CFF_TTX = os.path.join(DATA_DIR, "C_F_F_.ttx")
16CFF_BIN = os.path.join(DATA_DIR, "C_F_F_.bin")
17
18
19def strip_ttLibVersion(string):
20    return re.sub(' ttLibVersion=".*"', '', string)
21
22
23class CFFTableTest(unittest.TestCase):
24
25    @classmethod
26    def setUpClass(cls):
27        with open(CFF_BIN, 'rb') as f:
28            cls.cffData = f.read()
29        with open(CFF_TTX, 'r') as f:
30            cls.cffXML = strip_ttLibVersion(f.read()).splitlines()
31
32    def test_toXML(self):
33        font = TTFont(sfntVersion='OTTO')
34        cffTable = font['CFF '] = newTable('CFF ')
35        cffTable.decompile(self.cffData, font)
36        out = UnicodeIO()
37        font.saveXML(out)
38        cffXML = strip_ttLibVersion(out.getvalue()).splitlines()
39        self.assertEqual(cffXML, self.cffXML)
40
41    def test_fromXML(self):
42        font = TTFont(sfntVersion='OTTO')
43        font.importXML(CFF_TTX)
44        cffTable = font['CFF ']
45        cffData = cffTable.compile(font)
46        self.assertEqual(cffData, self.cffData)
47
48
49if __name__ == "__main__":
50    import sys
51    sys.exit(unittest.main())
52