From 7c319abbec21d964b6e439cafe88e7c8899741b5 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Sun, 3 Mar 2019 11:59:59 +0100 Subject: [PATCH] remove some unused variables; test empty cmap for format 4 --- Lib/fontTools/ttLib/tables/_c_m_a_p.py | 5 +---- Tests/ttLib/tables/_c_m_a_p_test.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py index 9923a1645..45cdc4a2b 100644 --- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py +++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py @@ -442,7 +442,6 @@ class cmap_format_2(CmapSubtable): charCodes = [item[0] for item in items] names = [item[1] for item in items] nameMap = ttFont.getReverseGlyphMap() - lenCharCodes = len(charCodes) try: gids = [nameMap[name] for name in names] except KeyError: @@ -744,8 +743,7 @@ class cmap_format_4(CmapSubtable): return struct.pack(">HHH", self.format, self.length, self.language) + self.data charCodes = list(self.cmap.keys()) - lenCharCodes = len(charCodes) - if lenCharCodes == 0: + if not charCodes: startCode = [0xffff] endCode = [0xffff] else: @@ -956,7 +954,6 @@ class cmap_format_12_or_13(CmapSubtable): if self.data: return struct.pack(">HHLLL", self.format, self.reserved, self.length, self.language, self.nGroups) + self.data charCodes = list(self.cmap.keys()) - lenCharCodes = len(charCodes) names = list(self.cmap.values()) nameMap = ttFont.getReverseGlyphMap() try: diff --git a/Tests/ttLib/tables/_c_m_a_p_test.py b/Tests/ttLib/tables/_c_m_a_p_test.py index 0d055a13a..233cd14fe 100644 --- a/Tests/ttLib/tables/_c_m_a_p_test.py +++ b/Tests/ttLib/tables/_c_m_a_p_test.py @@ -82,6 +82,16 @@ class CmapSubtableTest(unittest.TestCase): font.setGlyphOrder([".notdef"]) data = subtable.compile(font) + def test_compile_decompile_4_empty(self): + subtable = self.makeSubtable(4, 3, 1, 0) + subtable.cmap = {} + font = ttLib.TTFont() + font.setGlyphOrder([]) + data = subtable.compile(font) + subtable2 = CmapSubtable.newSubtable(4) + subtable2.decompile(data, font) + self.assertEqual(subtable2.cmap, {}) + def test_decompile_4(self): subtable = CmapSubtable.newSubtable(4) font = ttLib.TTFont()