[feaLib] Further merge inline single substitutions

Fixes https://github.com/fonttools/fonttools/issues/2150 (see the
discussion there).
This commit is contained in:
Khaled Hosny 2023-01-27 21:44:06 +02:00 committed by Behdad Esfahbod
parent 2f1f5e5e7b
commit 253b4f9afc
3 changed files with 5 additions and 5 deletions

View File

@ -1356,8 +1356,9 @@ class Builder(object):
"Empty glyph class in contextual substitution", location
)
# https://github.com/fonttools/fonttools/issues/512
# https://github.com/fonttools/fonttools/issues/2150
chain = self.get_lookup_(location, ChainContextSubstBuilder)
sub = chain.find_chainable_single_subst(set(mapping.keys()))
sub = chain.find_chainable_single_subst(mapping)
if sub is None:
sub = self.get_chained_lookup_(location, SingleSubstBuilder)
sub.mapping.update(mapping)

View File

@ -764,7 +764,7 @@ class ChainContextSubstBuilder(ChainContextualBuilder):
result.setdefault(glyph, set()).update(replacements)
return result
def find_chainable_single_subst(self, glyphs):
def find_chainable_single_subst(self, mapping):
"""Helper for add_single_subst_chained_()"""
res = None
for rule in self.rules[::-1]:
@ -772,7 +772,7 @@ class ChainContextSubstBuilder(ChainContextualBuilder):
return res
for sub in rule.lookups:
if isinstance(sub, SingleSubstBuilder) and not any(
g in glyphs for g in sub.mapping.keys()
g in mapping and mapping[g] != sub.mapping[g] for g in sub.mapping
):
res = sub
return res

View File

@ -73,7 +73,7 @@
<!-- SubstCount=1 -->
<SubstLookupRecord index="0">
<SequenceIndex value="0"/>
<LookupListIndex value="2"/>
<LookupListIndex value="1"/>
</SubstLookupRecord>
</SubRule>
</SubRuleSet>
@ -94,7 +94,6 @@
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="G" out="g"/>
<Substitution in="H" out="H.swash"/>
</SingleSubst>
</Lookup>
</LookupList>