[feaLib] Also handle feature aalt without any custom lookups

Before this change, feaLib did not handle feature files that specified
`feature aalt` whose block just was referring to other features without
defining any lookups on its own. After this change, we can handle it.

Resolves https://github.com/behdad/fonttools/issues/441
This commit is contained in:
Sascha Brawer 2016-01-11 18:12:23 +01:00
parent 38f4ee7908
commit 67686691c4
4 changed files with 225 additions and 2 deletions

View File

@ -110,7 +110,8 @@ class Builder(object):
for (script, lang, feature), lookups
in self.features_.items()
if feature == name]
if not feature:
# "aalt" does not have to specify its own lookups, but it might.
if not feature and name != "aalt":
raise FeatureLibError("Feature %s has not been defined" % name,
location)
for script, lang, feature, lookups in feature:

View File

@ -149,7 +149,7 @@ class BuilderTest(unittest.TestCase):
def test_constructs(self):
for name in ("Attach enum markClass language_required "
"GlyphClassDef LigatureCaretByIndex LigatureCaretByPos "
"lookup lookupflag").split():
"lookup lookupflag feature_aalt").split():
font = makeTTFont()
addOpenTypeFeatures(self.getpath("%s.fea" % name), font)
self.expect_ttx(font, self.getpath("%s.ttx" % name))

View File

@ -0,0 +1,31 @@
languagesystem DFLT dflt;
feature aalt {
feature sups;
feature frac;
feature ordn;
} aalt;
feature sups {
sub one by onesuperior;
sub two by twosuperior;
sub three by threesuperior;
} sups;
feature frac {
sub one slash four by onequarter;
sub one slash two by onehalf;
sub three slash four by threequarters;
} frac;
feature ordn {
sub [zero one two three four five six seven eight nine] [A a]'
by ordfeminine;
sub [zero one two three four five six seven eight nine] [O o]'
by ordmasculine;
} ordn;
feature liga {
sub f i by fi;
sub f l by fl;
} liga;

View File

@ -0,0 +1,191 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont>
<GSUB>
<Version value="1.0"/>
<ScriptList>
<!-- ScriptCount=1 -->
<ScriptRecord index="0">
<ScriptTag value="DFLT"/>
<Script>
<DefaultLangSys>
<ReqFeatureIndex value="65535"/>
<!-- FeatureCount=5 -->
<FeatureIndex index="0" value="0"/>
<FeatureIndex index="1" value="1"/>
<FeatureIndex index="2" value="2"/>
<FeatureIndex index="3" value="3"/>
<FeatureIndex index="4" value="4"/>
</DefaultLangSys>
<!-- LangSysCount=0 -->
</Script>
</ScriptRecord>
</ScriptList>
<FeatureList>
<!-- FeatureCount=5 -->
<FeatureRecord index="0">
<FeatureTag value="aalt"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="0"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="1">
<FeatureTag value="frac"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="2"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="2">
<FeatureTag value="liga"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="6"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="3">
<FeatureTag value="ordn"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="4"/>
</Feature>
</FeatureRecord>
<FeatureRecord index="4">
<FeatureTag value="sups"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=7 -->
<Lookup index="0">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="A" out="ordfeminine"/>
<Substitution in="O" out="ordmasculine"/>
<Substitution in="a" out="ordfeminine"/>
<Substitution in="o" out="ordmasculine"/>
<Substitution in="one" out="onesuperior"/>
<Substitution in="three" out="threesuperior"/>
<Substitution in="two" out="twosuperior"/>
</SingleSubst>
</Lookup>
<Lookup index="1">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="one" out="onesuperior"/>
<Substitution in="three" out="threesuperior"/>
<Substitution in="two" out="twosuperior"/>
</SingleSubst>
</Lookup>
<Lookup index="2">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="one">
<Ligature components="slash,four" glyph="onequarter"/>
<Ligature components="slash,two" glyph="onehalf"/>
</LigatureSet>
<LigatureSet glyph="three">
<Ligature components="slash,four" glyph="threequarters"/>
</LigatureSet>
</LigatureSubst>
</Lookup>
<Lookup index="3">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="A" out="ordfeminine"/>
<Substitution in="a" out="ordfeminine"/>
</SingleSubst>
</Lookup>
<Lookup index="4">
<!-- LookupType=6 -->
<LookupFlag value="0"/>
<!-- SubTableCount=2 -->
<ChainContextSubst index="0" Format="3">
<!-- BacktrackGlyphCount=1 -->
<BacktrackCoverage index="0">
<Glyph value="zero"/>
<Glyph value="one"/>
<Glyph value="two"/>
<Glyph value="three"/>
<Glyph value="four"/>
<Glyph value="five"/>
<Glyph value="six"/>
<Glyph value="seven"/>
<Glyph value="eight"/>
<Glyph value="nine"/>
</BacktrackCoverage>
<!-- InputGlyphCount=1 -->
<InputCoverage index="0">
<Glyph value="A"/>
<Glyph value="a"/>
</InputCoverage>
<!-- LookAheadGlyphCount=0 -->
<!-- SubstCount=1 -->
<SubstLookupRecord index="0">
<SequenceIndex value="0"/>
<LookupListIndex value="3"/>
</SubstLookupRecord>
</ChainContextSubst>
<ChainContextSubst index="1" Format="3">
<!-- BacktrackGlyphCount=1 -->
<BacktrackCoverage index="0">
<Glyph value="zero"/>
<Glyph value="one"/>
<Glyph value="two"/>
<Glyph value="three"/>
<Glyph value="four"/>
<Glyph value="five"/>
<Glyph value="six"/>
<Glyph value="seven"/>
<Glyph value="eight"/>
<Glyph value="nine"/>
</BacktrackCoverage>
<!-- InputGlyphCount=1 -->
<InputCoverage index="0">
<Glyph value="O"/>
<Glyph value="o"/>
</InputCoverage>
<!-- LookAheadGlyphCount=0 -->
<!-- SubstCount=1 -->
<SubstLookupRecord index="0">
<SequenceIndex value="0"/>
<LookupListIndex value="None"/>
</SubstLookupRecord>
</ChainContextSubst>
</Lookup>
<Lookup index="5">
<!-- LookupType=1 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<SingleSubst index="0">
<Substitution in="O" out="ordmasculine"/>
<Substitution in="o" out="ordmasculine"/>
</SingleSubst>
</Lookup>
<Lookup index="6">
<!-- LookupType=4 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<LigatureSubst index="0" Format="1">
<LigatureSet glyph="f">
<Ligature components="i" glyph="fi"/>
<Ligature components="l" glyph="fl"/>
</LigatureSet>
</LigatureSubst>
</Lookup>
</LookupList>
</GSUB>
</ttFont>