refactoring + TODO/FIXME check/unreachable_glyphs
(issue
@@ -1101,51 +1101,79 @@ def com_google_fonts_check_rupee(ttFont):
)
def com_google_fonts_check_unreachable_glyphs(ttFont):
"""Check font contains no unreachable glyphs"""
- all_glyphs = set(ttFont.getGlyphOrder())
- # Exclude cmapped glyphs
- all_glyphs -= set(ttFont.getBestCmap().values())
- all_glyphs.discard(".notdef")
def remove_lookup_outputs(all_glyphs, lookup):
- if lookup.LookupType == 1:
+ if lookup.LookupType == 1: # Single:
+ # Replace one glyph with one glyph
for sub in lookup.SubTable:
all_glyphs -= set(sub.mapping.values())
- if lookup.LookupType == 2:
+
+ if lookup.LookupType == 2: # Multiple:
+ # Replace one glyph with more than one glyph
for sub in lookup.SubTable:
for slot in sub.mapping.values():
all_glyphs -= set(slot)
- if lookup.LookupType == 3:
+ if lookup.LookupType == 3: # Alternate:
+ # Replace one glyph with one of many glyphs
for sub in lookup.SubTable:
for slot in sub.alternates.values():
all_glyphs -= set(slot)
- if lookup.LookupType == 4:
+ if lookup.LookupType == 4: # Ligature:
+ # Replace multiple glyphs with one glyph
for sub in lookup.SubTable:
for ligatures in sub.ligatures.values():
all_glyphs -= set(lig.LigGlyph for lig in ligatures)
- if lookup.LookupType == 7:
+ # TODO: Review lookupTypes 5 and 6
+ # Either handle them or add a comment
+ # explaining why that might not be necessary.
+ #
+ # if lookup.LookupType in [5, 6]:
+ # import ipdb; ipdb.set_trace()
+
+ if lookup.LookupType == 5: # Context:
+ # Replace one or more glyphs in context
+ pass # FIXME
+
+ if lookup.LookupType == 6: # Chaining Context
+ # Replace one or more glyphs in chained context
+ pass # FIXME
+
+ if lookup.LookupType == 7: # Extension Substitution:
+ # Extension mechanism for other substitutions
for xt in lookup.SubTable:
xt.SubTable = [xt.ExtSubTable]
xt.LookupType = xt.ExtSubTable.LookupType
remove_lookup_outputs(all_glyphs, xt)
- if lookup.LookupType == 8:
+ if lookup.LookupType == 8: # Reverse chaining context single:
+ # Applied in reverse order,
+ # replace single glyph in chaining context
for sub in lookup.SubTable:
all_glyphs -= set(sub.Substitute)
+
+ all_glyphs = set(ttFont.getGlyphOrder())
+
+ # Exclude cmapped glyphs
+ all_glyphs -= set(ttFont.getBestCmap().values())
+ all_glyphs.discard(".notdef")
+
if "GSUB" in ttFont and ttFont["GSUB"].table.LookupList:
lookups = ttFont["GSUB"].table.LookupList.Lookup
+
for lookup in lookups:
remove_lookup_outputs(all_glyphs, lookup)
if all_glyphs:
- unreachable = "\n\t - " + "\n\t - ".join(all_glyphs)
+ from fontbakery.utils import bullet_list
yield WARN,\
Message("unreachable-glyphs",
- f'The following glyphs could not be reached by codepoint or substitution rules:\n'
- f'{unreachable}\n')
+ f"The following glyphs could not be reached"
+ f" by codepoint or substitution rules:\n"
+ f"{bullet_list(all_glyphs)}\n")
else:
yield PASS, "Font did not contain any unreachable glyphs"
