From 2d3610bb6b191a8a9fda9bc4621c2bd27c44468d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 26 Dec 2016 17:26:14 -0500 Subject: [PATCH] Ignore class=0 when reading & writing ClassDef objects class=0 items might be added as an optimization. They have no semantic value. Ignore them. Fixes the last of mtiLib tests. --- .../mtiLib/testdata/mti/gposkernset.ttx.GPOS | 2 -- Lib/fontTools/ttLib/tables/otTables.py | 14 ++++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/fontTools/mtiLib/testdata/mti/gposkernset.ttx.GPOS b/Lib/fontTools/mtiLib/testdata/mti/gposkernset.ttx.GPOS index 1f7db54fe..850129f4c 100644 --- a/Lib/fontTools/mtiLib/testdata/mti/gposkernset.ttx.GPOS +++ b/Lib/fontTools/mtiLib/testdata/mti/gposkernset.ttx.GPOS @@ -54,8 +54,6 @@ - - diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 9e7b3c002..3016db989 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -389,7 +389,8 @@ class ClassDef(FormatSwitchingBaseTable): endID = len(glyphOrder) for glyphID, cls in zip(range(startID, endID), classList): - classDefs[glyphOrder[glyphID]] = cls + if cls: + classDefs[glyphOrder[glyphID]] = cls elif self.Format == 2: records = rawTable["ClassRangeRecord"] @@ -412,7 +413,8 @@ class ClassDef(FormatSwitchingBaseTable): # but none that we have seen in the wild. endID = len(glyphOrder) for glyphID in range(startID, endID): - classDefs[glyphOrder[glyphID]] = cls + if cls: + classDefs[glyphOrder[glyphID]] = cls else: assert 0, "unknown format: %s" % self.Format self.classDefs = classDefs @@ -421,13 +423,13 @@ class ClassDef(FormatSwitchingBaseTable): classDefs = getattr(self, "classDefs", None) if classDefs is None: classDefs = self.classDefs = {} - items = list(classDefs.items()) format = 2 rawTable = {"ClassRangeRecord": []} getGlyphID = font.getGlyphID - for i in range(len(items)): - glyphName, cls = items[i] - items[i] = getGlyphID(glyphName), glyphName, cls + items = [] + for glyphName, cls in classDefs.items(): + if not cls: continue + items.append((getGlyphID(glyphName), glyphName, cls)) items.sort() if items: last, lastName, lastCls = items[0]