[feaLib] don't reference same lookup multiple times within the same feature

Fixes https://github.com/fonttools/fonttools/issues/2946
This commit is contained in:
Cosimo Lupo 2024-05-23 19:00:39 +01:00
parent d757bfac8a
commit 0902d1e482
4 changed files with 88 additions and 2 deletions

View File

@ -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"

View File

@ -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 = [

View File

@ -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;

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<GSUB>
<Version value="0x00010000"/>
<ScriptList>
<!-- ScriptCount=2 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="0"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
<ScriptRecord index="1">
<ScriptTag value="latn"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=1 -->
<FeatureIndex index="0" value="0"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=1 -->
<FeatureRecord index="0">
<FeatureTag value="test"/>
<Feature>
<!-- LookupCount=2 -->
<LookupListIndex index="0" value="0"/>
<LookupListIndex index="1" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="1"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="a" out="A"/>
</SingleSubst>
</Lookup>
<Lookup index="1">
<LookupType value="1"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="b" out="B"/>
</SingleSubst>
</Lookup>
</LookupList>
</GSUB>
</ttFont>