Support loading broken Coverage tables
Hit by Google Fonts's font "Cabin" for example and a handful
of others.
diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py
index bd02393..ee94f22 100644
--- a/Lib/fontTools/ttLib/tables/otTables.py
+++ b/Lib/fontTools/ttLib/tables/otTables.py
@@ -7,6 +7,7 @@
import operator
from otBase import BaseTable, FormatSwitchingBaseTable
from types import TupleType
+import warnings
class LookupOrder(BaseTable):
@@ -39,12 +40,20 @@
(r.StartCoverageIndex, len(glyphs))
start = r.Start
end = r.End
- startID = font.getGlyphID(start)
- endID = font.getGlyphID(end)
+ try:
+ startID = font.getGlyphID(start, requireReal=1)
+ except KeyError:
+ warnings.warn("Coverage table has start glyph ID out of range: %s." % start)
+ continue
+ try:
+ endID = font.getGlyphID(end, requireReal=1)
+ except KeyError:
+ warnings.warn("Coverage table has end glyph ID out of range: %s." % end)
+ endID = len(glyphOrder)
glyphs.append(start)
rangeList = [glyphOrder[glyphID] for glyphID in range(startID + 1, endID) ]
glyphs += rangeList
- if start != end:
+ if start != end and endID < len(glyphOrder):
glyphs.append(end)
else:
assert 0, "unknown format: %s" % self.Format