Skip to content

Commit

Permalink
my_ttFont = deepcopy(ttFont)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Sep 16, 2024
1 parent 315cfda commit 8958834
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
60 changes: 32 additions & 28 deletions Lib/fontbakery/checks/glyphset.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def unreachable_glyphs(ttFont, config):
# remove_lookup_outputs() mutates the TTF; deep copy to avoid this, and so
# avoid issues with concurrent tests that also use ttFont.
# See https://github.com/fonttools/fontbakery/issues/4834
ttFont = deepcopy(ttFont)
my_ttFont = deepcopy(ttFont)

def remove_lookup_outputs(all_glyphs, lookup):
if lookup.LookupType == 1: # Single:
Expand Down Expand Up @@ -422,14 +422,14 @@ def remove_lookup_outputs(all_glyphs, lookup):
for sub in lookup.SubTable:
all_glyphs -= set(sub.Substitute)

all_glyphs = set(ttFont.getGlyphOrder())
all_glyphs = set(my_ttFont.getGlyphOrder())

# Exclude cmapped glyphs
all_glyphs -= set(ttFont.getBestCmap().values())
all_glyphs -= set(my_ttFont.getBestCmap().values())

# Exclude glyphs referenced by cmap format 14 variation sequences
# (as discussed at https://github.com/fonttools/fontbakery/issues/3915):
for table in ttFont["cmap"].tables:
for table in my_ttFont["cmap"].tables:
if table.format == 14:
for values in table.uvsDict.values():
for v in list(values):
Expand All @@ -443,14 +443,14 @@ def remove_lookup_outputs(all_glyphs, lookup):
# Glyphs identified in the Extender Glyph Table within JSTF table,
# such as kashidas, are not included in the check output:
# https://github.com/fonttools/fontbakery/issues/4773
if "JSTF" in ttFont:
for subtable in ttFont["JSTF"].table.iterSubTables():
if "JSTF" in my_ttFont:
for subtable in my_ttFont["JSTF"].table.iterSubTables():
for extender_glyph in subtable.value.JstfScript.ExtenderGlyph.ExtenderGlyph:
all_glyphs.discard(extender_glyph)

if "MATH" in ttFont:
glyphinfo = ttFont["MATH"].table.MathGlyphInfo
mathvariants = ttFont["MATH"].table.MathVariants
if "MATH" in my_ttFont:
glyphinfo = my_ttFont["MATH"].table.MathGlyphInfo
mathvariants = my_ttFont["MATH"].table.MathVariants

for glyphname in glyphinfo.MathTopAccentAttachment.TopAccentCoverage.glyphs:
all_glyphs.discard(glyphname)
Expand Down Expand Up @@ -480,50 +480,54 @@ def remove_lookup_outputs(all_glyphs, lookup):
for rec in hgc.MathGlyphVariantRecord:
all_glyphs.discard(rec.VariantGlyph)

if "COLR" in ttFont:
if ttFont["COLR"].version == 0:
for glyphname, colorlayers in ttFont["COLR"].ColorLayers.items():
if "COLR" in my_ttFont:
if my_ttFont["COLR"].version == 0:
for glyphname, colorlayers in my_ttFont["COLR"].ColorLayers.items():
for layer in colorlayers:
all_glyphs.discard(layer.name)

elif ttFont["COLR"].version == 1:
elif my_ttFont["COLR"].version == 1:
if (
hasattr(ttFont["COLR"].table, "BaseGlyphRecordArray")
and ttFont["COLR"].table.BaseGlyphRecordArray is not None
hasattr(my_ttFont["COLR"].table, "BaseGlyphRecordArray")
and my_ttFont["COLR"].table.BaseGlyphRecordArray is not None
):
for baseglyph_record in ttFont[
for baseglyph_record in my_ttFont[
"COLR"
].table.BaseGlyphRecordArray.BaseGlyphRecord:
all_glyphs.discard(baseglyph_record.BaseGlyph)

if (
hasattr(ttFont["COLR"].table, "LayerRecordArray")
and ttFont["COLR"].table.LayerRecordArray is not None
hasattr(my_ttFont["COLR"].table, "LayerRecordArray")
and my_ttFont["COLR"].table.LayerRecordArray is not None
):
for layer_record in ttFont["COLR"].table.LayerRecordArray.LayerRecord:
for layer_record in my_ttFont[
"COLR"
].table.LayerRecordArray.LayerRecord:
all_glyphs.discard(layer_record.LayerGlyph)

for paint_record in ttFont["COLR"].table.BaseGlyphList.BaseGlyphPaintRecord:
for paint_record in my_ttFont[
"COLR"
].table.BaseGlyphList.BaseGlyphPaintRecord:
if hasattr(paint_record.Paint, "Glyph"):
all_glyphs.discard(paint_record.Paint.Glyph)

if ttFont["COLR"].table.LayerList:
for paint in ttFont["COLR"].table.LayerList.Paint:
if my_ttFont["COLR"].table.LayerList:
for paint in my_ttFont["COLR"].table.LayerList.Paint:
if hasattr(paint, "Glyph"):
all_glyphs.discard(paint.Glyph)

if "GSUB" in ttFont and ttFont["GSUB"].table.LookupList:
lookups = ttFont["GSUB"].table.LookupList.Lookup
if "GSUB" in my_ttFont and my_ttFont["GSUB"].table.LookupList:
lookups = my_ttFont["GSUB"].table.LookupList.Lookup

for lookup in lookups:
remove_lookup_outputs(all_glyphs, lookup)

# Remove components used in TrueType table
if "glyf" in ttFont:
for glyph_name in ttFont["glyf"].keys():
base_glyph = ttFont["glyf"][glyph_name]
if "glyf" in my_ttFont:
for glyph_name in my_ttFont["glyf"].keys():
base_glyph = my_ttFont["glyf"][glyph_name]
if base_glyph.isComposite() and glyph_name not in all_glyphs:
all_glyphs -= set(base_glyph.getComponentNames(ttFont["glyf"]))
all_glyphs -= set(base_glyph.getComponentNames(my_ttFont["glyf"]))

if all_glyphs:
yield WARN, Message(
Expand Down
4 changes: 2 additions & 2 deletions Lib/fontbakery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,11 @@ def iterate_lookup_list_with_extensions(ttFont, table, callback, *args):
# This function mutates the TTF; deep copy to avoid this, and so avoid
# issues with concurrent tests that also use ttFont.
# See https://github.com/fonttools/fontbakery/issues/4834
ttFont = deepcopy(ttFont)
my_ttFont = deepcopy(ttFont)

extension_type = 9 if table == "GPOS" else 7

for lookup in ttFont[table].table.LookupList.Lookup:
for lookup in my_ttFont[table].table.LookupList.Lookup:
if lookup.LookupType == extension_type:
for xt in lookup.SubTable:
xt.SubTable = [xt.ExtSubTable]
Expand Down

0 comments on commit 8958834

Please sign in to comment.