diff --git a/Tests/ttLib/tables/_c_m_a_p_test.py b/Tests/ttLib/tables/_c_m_a_p_test.py index 664734580..bceec9e27 100644 --- a/Tests/ttLib/tables/_c_m_a_p_test.py +++ b/Tests/ttLib/tables/_c_m_a_p_test.py @@ -1,9 +1,22 @@ from __future__ import print_function, division, absolute_import, unicode_literals +import io +import os +import re from fontTools.misc.py23 import * from fontTools import ttLib +from fontTools.fontBuilder import FontBuilder import unittest from fontTools.ttLib.tables._c_m_a_p import CmapSubtable, table__c_m_a_p +CURR_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) +DATA_DIR = os.path.join(CURR_DIR, 'data') +CMAP_FORMAT_14_TTX = os.path.join(DATA_DIR, "_c_m_a_p_format_14.ttx") + +def strip_VariableItems(string): + # ttlib changes with the fontTools version + string = re.sub(' ttLibVersion=".*"', '', string) + return string + class CmapSubtableTest(unittest.TestCase): def makeSubtable(self, cmapFormat, platformID, platEncID, langID): @@ -82,6 +95,34 @@ class CmapSubtableTest(unittest.TestCase): self.assertEqual(font.getBestCmap(cmapPreferences=[(3, 1)]), {0x0041:'A', 0x0391:'A'}) self.assertEqual(font.getBestCmap(cmapPreferences=[(0, 4)]), None) + def test_format_14(self): + subtable = self.makeSubtable(14, 0, 5, 0) + subtable.cmap = {} # dummy + subtable.uvsDict = { + 0xFE00: [[0x0030, "zero.slash"]], + 0xFE01: [(0x0030, None)], # yes, tuple here, list above, to match decompile + } + fb = FontBuilder(1024, isTTF=True) + font = fb.font + fb.setupGlyphOrder([".notdef", "zero.slash"]) + fb.setupMaxp() + fb.setupPost() + cmap = table__c_m_a_p() + cmap.tableVersion = 0 + cmap.tables = [subtable] + font["cmap"] = cmap + f = io.BytesIO() + font.save(f) + f.seek(0) + font = ttLib.TTFont(f) + self.assertEqual(font["cmap"].getcmap(0, 5).uvsDict, subtable.uvsDict) + f = io.StringIO(newline=None) + font.saveXML(f, tables=["cmap"]) + ttx = strip_VariableItems(f.getvalue()) + with open(CMAP_FORMAT_14_TTX) as f: + expected = strip_VariableItems(f.read()) + self.assertEqual(ttx, expected) + if __name__ == "__main__": import sys diff --git a/Tests/ttLib/tables/data/_c_m_a_p_format_14.ttx b/Tests/ttLib/tables/data/_c_m_a_p_format_14.ttx new file mode 100644 index 000000000..fa91f6d91 --- /dev/null +++ b/Tests/ttLib/tables/data/_c_m_a_p_format_14.ttx @@ -0,0 +1,12 @@ + + + + + + + + + + + +