From e5bf2a7f1a064b095d51bcad061a547b4c9f0ae7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Aug 2021 04:09:29 -0600 Subject: [PATCH] [ttFont] Apply review comments --- Lib/fontTools/ttLib/tables/_c_m_a_p.py | 1 - Lib/fontTools/ttLib/tables/otConverters.py | 2 +- Lib/fontTools/ttLib/tables/otTables.py | 9 +++++---- Lib/fontTools/ttLib/ttFont.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py index d129391ee..6f1d81d5b 100644 --- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py +++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py @@ -16,7 +16,6 @@ def _make_map(font, chars, gids): assert len(chars) == len(gids) glyphNames = font.getGlyphNameMany(gids) cmap = {} - glyphOrder = font.getGlyphOrder() for char,gid,name in zip(chars,gids,glyphNames): if gid == 0: continue diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py index 6c8024292..44fcd0ab3 100644 --- a/Lib/fontTools/ttLib/tables/otConverters.py +++ b/Lib/fontTools/ttLib/tables/otConverters.py @@ -1209,7 +1209,7 @@ class STXHeader(BaseConverter): def _readLigatures(self, reader, font): limit = len(reader.data) numLigatureGlyphs = (limit - reader.pos) // 2 - return font.getGlyphNameMany (reader.readUShortArray(numLigatureGlyphs)) + return font.getGlyphNameMany(reader.readUShortArray(numLigatureGlyphs)) def _countPerGlyphLookups(self, table): # Somewhat annoyingly, the morx table does not encode diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index 5b7ddcce9..1955ceb41 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -920,15 +920,16 @@ class ClassDef(FormatSwitchingBaseTable): elif self.Format == 2: records = rawTable["ClassRangeRecord"] for rec in records: + cls = rec.Class + if not cls: + continue start = rec.Start end = rec.End - cls = rec.Class startID = font.getGlyphID(start) endID = font.getGlyphID(end) + 1 glyphNames = font.getGlyphNameMany(range(startID, endID)) - if cls: - for glyphName in glyphNames: - classDefs[glyphName] = cls + for glyphName in glyphNames: + classDefs[glyphName] = cls else: log.warning("Unknown ClassDef format: %s", self.Format) self.classDefs = classDefs diff --git a/Lib/fontTools/ttLib/ttFont.py b/Lib/fontTools/ttLib/ttFont.py index 45bc4966f..65f319359 100644 --- a/Lib/fontTools/ttLib/ttFont.py +++ b/Lib/fontTools/ttLib/ttFont.py @@ -569,6 +569,7 @@ class TTFont(object): glyphIDs = [d.get(glyphName) for glyphName in lst] if any(glyphID is None for glyphID in glyphIDs): + # TODO Add something faster getGlyphID = self.getGlyphID return [getGlyphID(glyphName) for glyphName in lst] @@ -581,7 +582,6 @@ class TTFont(object): def _buildReverseGlyphOrderDict(self): self._reverseGlyphOrderDict = d = {} - glyphOrder = self.getGlyphOrder() for glyphID,glyphName in enumerate(self.getGlyphOrder()): d[glyphName] = glyphID return d