[feaLib] Fix building chained alt substitutions

Support was added in db49f20d6b2629e1ba25c4afd3fb60817387f3d6, but there
was only a parser test and no builder test, fix the build and add a
builder test based on the existing parser one.

Fixes https://github.com/fonttools/fonttools/issues/1901
This commit is contained in:
Khaled Hosny 2020-04-28 14:28:16 +02:00
parent 1d2d5b345b
commit d24fd71934
4 changed files with 83 additions and 2 deletions

View File

@ -828,7 +828,7 @@ class Builder(object):
if prefix or suffix:
chain = self.get_lookup_(location, ChainContextSubstBuilder)
lookup = self.get_chained_lookup_(location, AlternateSubstBuilder)
chain.substitutions.append((prefix, [glyph], suffix, [lookup]))
chain.substitutions.append((prefix, [{glyph}], suffix, [lookup]))
else:
lookup = self.get_lookup_(location, AlternateSubstBuilder)
if glyph in lookup.alternates:

View File

@ -71,7 +71,7 @@ class BuilderTest(unittest.TestCase):
ZeroValue_ChainSinglePos_horizontal ZeroValue_ChainSinglePos_vertical
PairPosSubtable ChainSubstSubtable ChainPosSubtable LigatureSubtable
AlternateSubtable MultipleSubstSubtable SingleSubstSubtable
aalt_chain_contextual_subst
aalt_chain_contextual_subst AlternateChained
""".split()
def __init__(self, methodName):

View File

@ -0,0 +1,3 @@
feature test {
sub A B a' [Y y] Z from [a.alt1 a.alt2 a.alt3];
} test;

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<GSUB>
<Version value="0x00010000"/>
<ScriptList>
<!-- ScriptCount=1 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<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=1 -->
<LookupListIndex index="0" value="0"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=2 -->
<Lookup index="0">
<LookupType value="6"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<ChainContextSubst index="0" Format="3">
<!-- BacktrackGlyphCount=2 -->
<BacktrackCoverage index="0">
<Glyph value="B"/>
</BacktrackCoverage>
<BacktrackCoverage index="1">
<Glyph value="A"/>
</BacktrackCoverage>
<!-- InputGlyphCount=1 -->
<InputCoverage index="0">
<Glyph value="a"/>
</InputCoverage>
<!-- LookAheadGlyphCount=2 -->
<LookAheadCoverage index="0">
<Glyph value="Y"/>
<Glyph value="y"/>
</LookAheadCoverage>
<LookAheadCoverage index="1">
<Glyph value="Z"/>
</LookAheadCoverage>
<!-- SubstCount=1 -->
<SubstLookupRecord index="0">
<SequenceIndex value="0"/>
<LookupListIndex value="1"/>
</SubstLookupRecord>
</ChainContextSubst>
</Lookup>
<Lookup index="1">
<LookupType value="3"/>
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<AlternateSubst index="0">
<AlternateSet glyph="a">
<Alternate glyph="a.alt1"/>
<Alternate glyph="a.alt2"/>
<Alternate glyph="a.alt3"/>
</AlternateSet>
</AlternateSubst>
</Lookup>
</LookupList>
</GSUB>
</ttFont>