remove some unused variables; test empty cmap for format 4

This commit is contained in:
justvanrossum 2019-03-03 11:59:59 +01:00
parent d4a2d935c4
commit 7c319abbec
2 changed files with 11 additions and 4 deletions

View File

@ -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:

View File

@ -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()