def test_format_14(self): subtable = self.makeSubtable(14, 0, 5, 0) subtable.cmap = {} # dummy subtable.uvsDict = { 0xFE00: [(0x0030, "zero.slash")], 0xFE01: [(0x0030, None)], } 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) with open(CMAP_FORMAT_14_BW_COMPAT_TTX) as f: font.importXML(f) self.assertEqual(font["cmap"].getcmap(0, 5).uvsDict, subtable.uvsDict)
def test_format_14(self): subtable = self.makeSubtable(14, 0, 5, 0) subtable.cmap = {} # dummy subtable.uvsDict = { 0xFE00: [(0x0030, "zero.slash")], 0xFE01: [(0x0030, None)], } 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) with open(CMAP_FORMAT_14_BW_COMPAT_TTX) as f: font.importXML(f) self.assertEqual(font["cmap"].getcmap(0, 5).uvsDict, subtable.uvsDict)
def test_buildReversed(self): c4 = self.makeSubtable(4, 3, 1, 0) c4.cmap = {0x0041:'A', 0x0391:'A'} c12 = self.makeSubtable(12, 3, 10, 0) c12.cmap = {0x10314: 'u10314'} cmap = table__c_m_a_p() cmap.tables = [c4, c12] self.assertEqual(cmap.buildReversed(), {'A':{0x0041, 0x0391}, 'u10314':{0x10314}})
def test_buildReversed(self): c4 = self.makeSubtable(4, 3, 1, 0) c4.cmap = {0x0041:'A', 0x0391:'A'} c12 = self.makeSubtable(12, 3, 10, 0) c12.cmap = {0x10314: 'u10314'} cmap = table__c_m_a_p() cmap.tables = [c4, c12] self.assertEqual(cmap.buildReversed(), {'A':{0x0041, 0x0391}, 'u10314':{0x10314}})
def test_getBestCmap(self): c4 = self.makeSubtable(4, 3, 1, 0) c4.cmap = {0x0041:'A', 0x0391:'A'} c12 = self.makeSubtable(12, 3, 10, 0) c12.cmap = {0x10314: 'u10314'} cmap = table__c_m_a_p() cmap.tables = [c4, c12] self.assertEqual(cmap.getBestCmap(), {0x10314: 'u10314'}) self.assertEqual(cmap.getBestCmap(cmapPreferences=[(3, 1)]), {0x0041:'A', 0x0391:'A'}) self.assertEqual(cmap.getBestCmap(cmapPreferences=[(0, 4)]), None)