[feaLib] "subtable" in alternate lookups

This commit is contained in:
Khaled Hosny 2019-02-26 00:20:44 +02:00
parent 7454a3eb48
commit c87e5cf4ad
4 changed files with 71 additions and 6 deletions

View File

@ -1185,12 +1185,24 @@ class AlternateSubstBuilder(LookupBuilder):
self.alternates == other.alternates)
def build(self):
subtable = otl.buildAlternateSubstSubtable(self.alternates)
return self.buildLookup_([subtable])
subtables = []
alternates = {}
for key in self.alternates:
if key[0] == self.SUBTABLE_BREAK_:
subtables.append(otl.buildAlternateSubstSubtable(alternates))
alternates = {}
else:
alternates[key] = self.alternates[key]
if alternates:
subtables.append(otl.buildAlternateSubstSubtable(alternates))
return self.buildLookup_(subtables)
def getAlternateGlyphs(self):
return self.alternates
def add_subtable_break(self, location):
self.alternates[(self.SUBTABLE_BREAK_, location)] = self.SUBTABLE_BREAK_
class ChainContextPosBuilder(LookupBuilder):
def __init__(self, font, location):

View File

@ -71,6 +71,7 @@ class BuilderTest(unittest.TestCase):
ZeroValue_PairPos_horizontal ZeroValue_PairPos_vertical
ZeroValue_ChainSinglePos_horizontal ZeroValue_ChainSinglePos_vertical
PairPosSubtable ChainSubstSubtable ChainPosSubtable LigatureSubtable
AlternateSubtable
""".split()
def __init__(self, methodName):

View File

@ -1,5 +1,5 @@
feature salt {
feature test {
sub A from [A.alt1 A.alt2];
sub B from [B.alt1 B.alt2 B.alt3];
sub C from [C.alt1];
} salt;
subtable;
sub B from [B.alt1 B.alt2];
} test;

View File

@ -0,0 +1,52 @@
<?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=1 -->
<Lookup index="0">
<LookupType value="3"/>
<LookupFlag value="0"/>
<!-- SubTableCount=2 -->
<AlternateSubst index="0">
<AlternateSet glyph="A">
<Alternate glyph="A.alt1"/>
<Alternate glyph="A.alt2"/>
</AlternateSet>
</AlternateSubst>
<AlternateSubst index="1">
<AlternateSet glyph="B">
<Alternate glyph="B.alt1"/>
<Alternate glyph="B.alt2"/>
</AlternateSet>
</AlternateSubst>
</Lookup>
</LookupList>
</GSUB>
</ttFont>