2016-09-20 20:14:53 -07:00
|
|
|
"""cffLib_test.py -- unit test for Adobe CFF fonts."""
|
|
|
|
|
|
|
|
from fontTools.ttLib import TTFont, newTable
|
2021-03-29 11:45:58 +02:00
|
|
|
from io import StringIO
|
2016-11-02 10:05:10 +00:00
|
|
|
import re
|
2016-09-28 18:13:11 +01:00
|
|
|
import os
|
2016-09-20 20:14:53 -07:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
2016-09-28 18:13:11 +01:00
|
|
|
CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
|
2017-01-16 09:36:10 +00:00
|
|
|
DATA_DIR = os.path.join(CURR_DIR, "data")
|
2016-09-20 20:14:53 -07:00
|
|
|
|
2016-09-28 18:13:11 +01:00
|
|
|
CFF_TTX = os.path.join(DATA_DIR, "C_F_F_.ttx")
|
|
|
|
CFF_BIN = os.path.join(DATA_DIR, "C_F_F_.bin")
|
2016-09-20 20:14:53 -07:00
|
|
|
|
|
|
|
|
2016-11-02 10:05:10 +00:00
|
|
|
def strip_ttLibVersion(string):
|
|
|
|
return re.sub(' ttLibVersion=".*"', "", string)
|
|
|
|
|
|
|
|
|
2016-09-28 18:13:11 +01:00
|
|
|
class CFFTableTest(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
with open(CFF_BIN, "rb") as f:
|
|
|
|
cls.cffData = f.read()
|
|
|
|
with open(CFF_TTX, "r") as f:
|
2016-11-02 10:05:10 +00:00
|
|
|
cls.cffXML = strip_ttLibVersion(f.read()).splitlines()
|
2016-09-20 20:14:53 -07:00
|
|
|
|
|
|
|
def test_toXML(self):
|
2016-09-28 18:13:11 +01:00
|
|
|
font = TTFont(sfntVersion="OTTO")
|
|
|
|
cffTable = font["CFF "] = newTable("CFF ")
|
|
|
|
cffTable.decompile(self.cffData, font)
|
2021-03-29 11:45:58 +02:00
|
|
|
out = StringIO()
|
2016-09-28 18:13:11 +01:00
|
|
|
font.saveXML(out)
|
2016-11-02 10:05:10 +00:00
|
|
|
cffXML = strip_ttLibVersion(out.getvalue()).splitlines()
|
2016-09-28 18:13:11 +01:00
|
|
|
self.assertEqual(cffXML, self.cffXML)
|
2016-09-20 20:14:53 -07:00
|
|
|
|
|
|
|
def test_fromXML(self):
|
2016-09-28 18:13:11 +01:00
|
|
|
font = TTFont(sfntVersion="OTTO")
|
|
|
|
font.importXML(CFF_TTX)
|
|
|
|
cffTable = font["CFF "]
|
2016-09-20 20:14:53 -07:00
|
|
|
cffData = cffTable.compile(font)
|
2016-09-28 18:13:11 +01:00
|
|
|
self.assertEqual(cffData, self.cffData)
|
2016-09-20 20:14:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-01-11 13:05:35 +00:00
|
|
|
import sys
|
2022-12-13 11:26:36 +00:00
|
|
|
|
2017-01-11 13:05:35 +00:00
|
|
|
sys.exit(unittest.main())
|