diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 7921a3f17..a91381ddc 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -880,8 +880,13 @@ class Builder(object): # l.lookup_index will be None when a lookup is not needed # for the table under construction. For example, substitution # rules will have no lookup_index while building GPOS tables. + # We also deduplicate lookup indices, as they only get applied once + # within a given feature: + # https://github.com/fonttools/fonttools/issues/2946 lookup_indices = tuple( - [l.lookup_index for l in lookups if l.lookup_index is not None] + dict.fromkeys( + l.lookup_index for l in lookups if l.lookup_index is not None + ) ) size_feature = tag == "GPOS" and feature_tag == "size" diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py index 875223af7..4cb9b4a1d 100644 --- a/Tests/feaLib/builder_test.py +++ b/Tests/feaLib/builder_test.py @@ -81,7 +81,7 @@ class BuilderTest(unittest.TestCase): MultipleLookupsPerGlyph MultipleLookupsPerGlyph2 GSUB_6_formats GSUB_5_formats delete_glyph STAT_test STAT_test_elidedFallbackNameID variable_scalar_valuerecord variable_scalar_anchor variable_conditionset - variable_mark_anchor + variable_mark_anchor duplicate_lookup_reference """.split() VARFONT_AXES = [ diff --git a/Tests/feaLib/data/duplicate_lookup_reference.fea b/Tests/feaLib/data/duplicate_lookup_reference.fea new file mode 100644 index 000000000..f2746520e --- /dev/null +++ b/Tests/feaLib/data/duplicate_lookup_reference.fea @@ -0,0 +1,18 @@ +# https://github.com/fonttools/fonttools/issues/2946 + +languagesystem DFLT dflt; +languagesystem latn dflt; + +feature test { + lookup alt1 { + sub a by A; + } alt1; + lookup alt2 { + sub b by B; + } alt2; + + + script latn; + lookup alt1; + +} test; diff --git a/Tests/feaLib/data/duplicate_lookup_reference.ttx b/Tests/feaLib/data/duplicate_lookup_reference.ttx new file mode 100644 index 000000000..e8be775c5 --- /dev/null +++ b/Tests/feaLib/data/duplicate_lookup_reference.ttx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +