[feaLib] "subtable" in ligature lookups

This commit is contained in:
Khaled Hosny 2019-02-26 00:07:37 +02:00
parent cc1b6baff7
commit 7454a3eb48
5 changed files with 78 additions and 7 deletions

View File

@ -1308,8 +1308,19 @@ class LigatureSubstBuilder(LookupBuilder):
self.ligatures == other.ligatures)
def build(self):
subtable = otl.buildLigatureSubstSubtable(self.ligatures)
return self.buildLookup_([subtable])
subtables = []
ligatures = {}
for key in self.ligatures:
if key[0] == self.SUBTABLE_BREAK_:
subtables.append(otl.buildLigatureSubstSubtable(ligatures))
ligatures = {}
else:
ligatures[key] = self.ligatures[key]
subtables.append(otl.buildLigatureSubstSubtable(ligatures))
return self.buildLookup_(subtables)
def add_subtable_break(self, location):
self.ligatures[(self.SUBTABLE_BREAK_, location)] = self.SUBTABLE_BREAK_
class MultipleSubstBuilder(LookupBuilder):

View File

@ -70,7 +70,7 @@ class BuilderTest(unittest.TestCase):
ZeroValue_SinglePos_horizontal ZeroValue_SinglePos_vertical
ZeroValue_PairPos_horizontal ZeroValue_PairPos_vertical
ZeroValue_ChainSinglePos_horizontal ZeroValue_ChainSinglePos_vertical
PairPosSubtable ChainSubstSubtable ChainPosSubtable
PairPosSubtable ChainSubstSubtable ChainPosSubtable LigatureSubtable
""".split()
def __init__(self, methodName):
@ -517,11 +517,11 @@ class BuilderTest(unittest.TestCase):
FeatureLibError,
'unsupported "subtable" statement for lookup type',
self.build,
"feature liga {"
" sub f f by f_f;"
"feature test {"
" sub a by b;"
" subtable;"
" sub f i by f_i;"
"} liga;"
" sub c by d;"
"} test;"
)
def test_skip_featureNames_if_no_name_table(self):

View File

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

View File

@ -0,0 +1,5 @@
feature test {
sub f f by f_f;
subtable;
sub f i by f_i;
} test;

View File

@ -0,0 +1,50 @@
<?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="4"/>
<LookupFlag value="0"/>
<!-- SubTableCount=2 -->
<LigatureSubst index="0">
<LigatureSet glyph="f">
<Ligature components="f" glyph="f_f"/>
</LigatureSet>
</LigatureSubst>
<LigatureSubst index="1">
<LigatureSet glyph="f">
<Ligature components="i" glyph="f_i"/>
</LigatureSet>
</LigatureSubst>
</Lookup>
</LookupList>
</GSUB>
</ttFont>