Skip to content

Commit

Permalink
Avoid mutation of TTFont to fix issues with concurrent tests
Browse files Browse the repository at this point in the history
Although this mutation is reversed, it could still interfere with TTFont
instances being used concurrently by other tests.

Possible fix for #4834
  • Loading branch information
Hoolean authored and felipesanches committed Sep 17, 2024
1 parent 4afa3df commit 7f440d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions Lib/fontbakery/checks/glyphset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import deepcopy

from fontbakery.constants import (
NameID,
PlatformID,
Expand Down Expand Up @@ -370,6 +372,11 @@ def check_soft_hyphen(ttFont):
def unreachable_glyphs(ttFont, config):
"""Check font contains no unreachable glyphs"""

# 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)

def remove_lookup_outputs(all_glyphs, lookup):
if lookup.LookupType == 1: # Single:
# Replace one glyph with one glyph
Expand Down
17 changes: 9 additions & 8 deletions Lib/fontbakery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import subprocess
import sys
from typing import Text, Optional
from copy import deepcopy

from fontTools.pens.basePen import BasePen
from fontTools.ttLib import TTFont
Expand Down Expand Up @@ -537,19 +538,19 @@ def iterate_lookup_list_with_extensions(ttFont, table, callback, *args):
if table not in ttFont or not ttFont[table].table.LookupList:
return

# 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)

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

for lookup in ttFont[table].table.LookupList.Lookup:
if lookup.LookupType == extension_type:
for xt in lookup.SubTable:
original_LookupType = xt.LookupType
try:
xt.SubTable = [xt.ExtSubTable]
xt.LookupType = xt.ExtSubTable.LookupType
callback(xt, *args)
finally:
del xt.SubTable
xt.LookupType = original_LookupType
xt.SubTable = [xt.ExtSubTable]
xt.LookupType = xt.ExtSubTable.LookupType
callback(xt, *args)
else:
callback(lookup, *args)

Expand Down

0 comments on commit 7f440d7

Please sign in to comment.