[otTables] Allow virtual GIDs in Coverage/ClassDef reader
Fixes https://github.com/fonttools/fonttools/issues/2334#issuecomment-901885598
This commit is contained in:
parent
0398d8aa54
commit
d0d082e76e
@ -521,12 +521,10 @@ class Coverage(FormatSwitchingBaseTable):
|
|||||||
|
|
||||||
def postRead(self, rawTable, font):
|
def postRead(self, rawTable, font):
|
||||||
if self.Format == 1:
|
if self.Format == 1:
|
||||||
# TODO only allow glyphs that are valid?
|
|
||||||
self.glyphs = rawTable["GlyphArray"]
|
self.glyphs = rawTable["GlyphArray"]
|
||||||
elif self.Format == 2:
|
elif self.Format == 2:
|
||||||
glyphs = self.glyphs = []
|
glyphs = self.glyphs = []
|
||||||
ranges = rawTable["RangeRecord"]
|
ranges = rawTable["RangeRecord"]
|
||||||
glyphOrder = font.getGlyphOrder()
|
|
||||||
# Some SIL fonts have coverage entries that don't have sorted
|
# Some SIL fonts have coverage entries that don't have sorted
|
||||||
# StartCoverageIndex. If it is so, fixup and warn. We undo
|
# StartCoverageIndex. If it is so, fixup and warn. We undo
|
||||||
# this when writing font out.
|
# this when writing font out.
|
||||||
@ -536,25 +534,12 @@ class Coverage(FormatSwitchingBaseTable):
|
|||||||
ranges = sorted_ranges
|
ranges = sorted_ranges
|
||||||
del sorted_ranges
|
del sorted_ranges
|
||||||
for r in ranges:
|
for r in ranges:
|
||||||
assert r.StartCoverageIndex == len(glyphs), \
|
|
||||||
(r.StartCoverageIndex, len(glyphs))
|
|
||||||
start = r.Start
|
start = r.Start
|
||||||
end = r.End
|
end = r.End
|
||||||
try:
|
startID = font.getGlyphID(start)
|
||||||
startID = font.getGlyphID(start, requireReal=True)
|
endID = font.getGlyphID(end) + 1
|
||||||
except KeyError:
|
for glyphID in range(startID, endID):
|
||||||
log.warning("Coverage table has start glyph ID out of range: %s.", start)
|
glyphs.append(font.getGlyphName(glyphID))
|
||||||
continue
|
|
||||||
try:
|
|
||||||
endID = font.getGlyphID(end, requireReal=True) + 1
|
|
||||||
except KeyError:
|
|
||||||
# Apparently some tools use 65535 to "match all" the range
|
|
||||||
if end != 'glyph65535':
|
|
||||||
log.warning("Coverage table has end glyph ID out of range: %s.", end)
|
|
||||||
# NOTE: We clobber out-of-range things here. There are legit uses for those,
|
|
||||||
# but none that we have seen in the wild.
|
|
||||||
endID = len(glyphOrder)
|
|
||||||
glyphs.extend(glyphOrder[glyphID] for glyphID in range(startID, endID))
|
|
||||||
else:
|
else:
|
||||||
self.glyphs = []
|
self.glyphs = []
|
||||||
log.warning("Unknown Coverage format: %s", self.Format)
|
log.warning("Unknown Coverage format: %s", self.Format)
|
||||||
@ -924,27 +909,15 @@ class ClassDef(FormatSwitchingBaseTable):
|
|||||||
|
|
||||||
def postRead(self, rawTable, font):
|
def postRead(self, rawTable, font):
|
||||||
classDefs = {}
|
classDefs = {}
|
||||||
glyphOrder = font.getGlyphOrder()
|
|
||||||
|
|
||||||
if self.Format == 1:
|
if self.Format == 1:
|
||||||
start = rawTable["StartGlyph"]
|
start = rawTable["StartGlyph"]
|
||||||
classList = rawTable["ClassValueArray"]
|
classList = rawTable["ClassValueArray"]
|
||||||
try:
|
startID = font.getGlyphID(start)
|
||||||
startID = font.getGlyphID(start, requireReal=True)
|
|
||||||
except KeyError:
|
|
||||||
log.warning("ClassDef table has start glyph ID out of range: %s.", start)
|
|
||||||
startID = len(glyphOrder)
|
|
||||||
endID = startID + len(classList)
|
endID = startID + len(classList)
|
||||||
if endID > len(glyphOrder):
|
|
||||||
log.warning("ClassDef table has entries for out of range glyph IDs: %s,%s.",
|
|
||||||
start, len(classList))
|
|
||||||
# NOTE: We clobber out-of-range things here. There are legit uses for those,
|
|
||||||
# but none that we have seen in the wild.
|
|
||||||
endID = len(glyphOrder)
|
|
||||||
|
|
||||||
for glyphID, cls in zip(range(startID, endID), classList):
|
for glyphID, cls in zip(range(startID, endID), classList):
|
||||||
if cls:
|
if cls:
|
||||||
classDefs[glyphOrder[glyphID]] = cls
|
classDefs[font.getGlyphName(glyphID)] = cls
|
||||||
|
|
||||||
elif self.Format == 2:
|
elif self.Format == 2:
|
||||||
records = rawTable["ClassRangeRecord"]
|
records = rawTable["ClassRangeRecord"]
|
||||||
@ -952,23 +925,11 @@ class ClassDef(FormatSwitchingBaseTable):
|
|||||||
start = rec.Start
|
start = rec.Start
|
||||||
end = rec.End
|
end = rec.End
|
||||||
cls = rec.Class
|
cls = rec.Class
|
||||||
try:
|
startID = font.getGlyphID(start)
|
||||||
startID = font.getGlyphID(start, requireReal=True)
|
endID = font.getGlyphID(end) + 1
|
||||||
except KeyError:
|
|
||||||
log.warning("ClassDef table has start glyph ID out of range: %s.", start)
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
endID = font.getGlyphID(end, requireReal=True) + 1
|
|
||||||
except KeyError:
|
|
||||||
# Apparently some tools use 65535 to "match all" the range
|
|
||||||
if end != 'glyph65535':
|
|
||||||
log.warning("ClassDef table has end glyph ID out of range: %s.", end)
|
|
||||||
# NOTE: We clobber out-of-range things here. There are legit uses for those,
|
|
||||||
# but none that we have seen in the wild.
|
|
||||||
endID = len(glyphOrder)
|
|
||||||
for glyphID in range(startID, endID):
|
for glyphID in range(startID, endID):
|
||||||
if cls:
|
if cls:
|
||||||
classDefs[glyphOrder[glyphID]] = cls
|
classDefs[font.getGlyphName(glyphID)] = cls
|
||||||
else:
|
else:
|
||||||
log.warning("Unknown ClassDef format: %s", self.Format)
|
log.warning("Unknown ClassDef format: %s", self.Format)
|
||||||
self.classDefs = classDefs
|
self.classDefs = classDefs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user