[feaLib] Further merge inline single substitutions
Fixes https://github.com/fonttools/fonttools/issues/2150 (see the discussion there).
This commit is contained in:
parent
2f1f5e5e7b
commit
253b4f9afc
@ -1356,8 +1356,9 @@ class Builder(object):
|
|||||||
"Empty glyph class in contextual substitution", location
|
"Empty glyph class in contextual substitution", location
|
||||||
)
|
)
|
||||||
# https://github.com/fonttools/fonttools/issues/512
|
# https://github.com/fonttools/fonttools/issues/512
|
||||||
|
# https://github.com/fonttools/fonttools/issues/2150
|
||||||
chain = self.get_lookup_(location, ChainContextSubstBuilder)
|
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:
|
if sub is None:
|
||||||
sub = self.get_chained_lookup_(location, SingleSubstBuilder)
|
sub = self.get_chained_lookup_(location, SingleSubstBuilder)
|
||||||
sub.mapping.update(mapping)
|
sub.mapping.update(mapping)
|
||||||
|
@ -764,7 +764,7 @@ class ChainContextSubstBuilder(ChainContextualBuilder):
|
|||||||
result.setdefault(glyph, set()).update(replacements)
|
result.setdefault(glyph, set()).update(replacements)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def find_chainable_single_subst(self, glyphs):
|
def find_chainable_single_subst(self, mapping):
|
||||||
"""Helper for add_single_subst_chained_()"""
|
"""Helper for add_single_subst_chained_()"""
|
||||||
res = None
|
res = None
|
||||||
for rule in self.rules[::-1]:
|
for rule in self.rules[::-1]:
|
||||||
@ -772,7 +772,7 @@ class ChainContextSubstBuilder(ChainContextualBuilder):
|
|||||||
return res
|
return res
|
||||||
for sub in rule.lookups:
|
for sub in rule.lookups:
|
||||||
if isinstance(sub, SingleSubstBuilder) and not any(
|
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
|
res = sub
|
||||||
return res
|
return res
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
<!-- SubstCount=1 -->
|
<!-- SubstCount=1 -->
|
||||||
<SubstLookupRecord index="0">
|
<SubstLookupRecord index="0">
|
||||||
<SequenceIndex value="0"/>
|
<SequenceIndex value="0"/>
|
||||||
<LookupListIndex value="2"/>
|
<LookupListIndex value="1"/>
|
||||||
</SubstLookupRecord>
|
</SubstLookupRecord>
|
||||||
</SubRule>
|
</SubRule>
|
||||||
</SubRuleSet>
|
</SubRuleSet>
|
||||||
@ -94,7 +94,6 @@
|
|||||||
<!-- SubTableCount=1 -->
|
<!-- SubTableCount=1 -->
|
||||||
<SingleSubst index="0">
|
<SingleSubst index="0">
|
||||||
<Substitution in="G" out="g"/>
|
<Substitution in="G" out="g"/>
|
||||||
<Substitution in="H" out="H.swash"/>
|
|
||||||
</SingleSubst>
|
</SingleSubst>
|
||||||
</Lookup>
|
</Lookup>
|
||||||
</LookupList>
|
</LookupList>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user