Merge pull request #2277 from fonttools/fix-aalt-empty-lookup
fix AttributeError while generating aalt feature with empty lookup
diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py
index 4a7d957..989f05e 100644
--- a/Lib/fontTools/feaLib/builder.py
+++ b/Lib/fontTools/feaLib/builder.py
@@ -1005,7 +1005,8 @@
assert lookup_name in self.named_lookups_, lookup_name
self.cur_lookup_ = None
lookup = self.named_lookups_[lookup_name]
- self.add_lookup_to_feature_(lookup, self.cur_feature_name_)
+ if lookup is not None: # skip empty named lookup
+ self.add_lookup_to_feature_(lookup, self.cur_feature_name_)
def set_font_revision(self, location, revision):
self.fontRevision_ = revision
diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py
index 0a55239..951a360 100644
--- a/Tests/feaLib/builder_test.py
+++ b/Tests/feaLib/builder_test.py
@@ -65,7 +65,7 @@
spec9a spec9b spec9c1 spec9c2 spec9c3 spec9d spec9e spec9f spec9g
spec10
bug453 bug457 bug463 bug501 bug502 bug504 bug505 bug506 bug509
- bug512 bug514 bug568 bug633 bug1307 bug1459
+ bug512 bug514 bug568 bug633 bug1307 bug1459 bug2276
name size size2 multiple_feature_blocks omitted_GlyphClassDef
ZeroValue_SinglePos_horizontal ZeroValue_SinglePos_vertical
ZeroValue_PairPos_horizontal ZeroValue_PairPos_vertical
@@ -829,6 +829,15 @@
"} test;")
captor.assertRegex('Already defined position for pair A V at')
+ def test_ignore_empty_lookup_block(self):
+ # https://github.com/fonttools/fonttools/pull/2277
+ font = self.build(
+ "lookup EMPTY { ; } EMPTY;"
+ "feature ss01 { lookup EMPTY; } ss01;"
+ )
+ assert "GPOS" not in font
+ assert "GSUB" not in font
+
def generate_feature_file_test(name):
return lambda self: self.check_feature_file(name)
diff --git a/Tests/feaLib/data/bug2276.fea b/Tests/feaLib/data/bug2276.fea
new file mode 100644
index 0000000..96f9885
--- /dev/null
+++ b/Tests/feaLib/data/bug2276.fea
@@ -0,0 +1,11 @@
+# https://github.com/fonttools/fonttools/issues/2276
+lookup EMPTY {
+ # pass
+} EMPTY;
+feature ss01 {
+ sub a by a.alt1;
+ lookup EMPTY;
+} ss01;
+feature aalt {
+ feature ss01;
+} aalt;
diff --git a/Tests/feaLib/data/bug2276.ttx b/Tests/feaLib/data/bug2276.ttx
new file mode 100644
index 0000000..57902da
--- /dev/null
+++ b/Tests/feaLib/data/bug2276.ttx
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.22">
+
+ <GSUB>
+ <Version value="0x00010000"/>
+ <ScriptList>
+ <!-- ScriptCount=1 -->
+ <ScriptRecord index="0">
+ <ScriptTag value="DFLT"/>
+ <Script>
+ <DefaultLangSys>
+ <ReqFeatureIndex value="65535"/>
+ <!-- FeatureCount=2 -->
+ <FeatureIndex index="0" value="0"/>
+ <FeatureIndex index="1" value="1"/>
+ </DefaultLangSys>
+ <!-- LangSysCount=0 -->
+ </Script>
+ </ScriptRecord>
+ </ScriptList>
+ <FeatureList>
+ <!-- FeatureCount=2 -->
+ <FeatureRecord index="0">
+ <FeatureTag value="aalt"/>
+ <Feature>
+ <!-- LookupCount=1 -->
+ <LookupListIndex index="0" value="0"/>
+ </Feature>
+ </FeatureRecord>
+ <FeatureRecord index="1">
+ <FeatureTag value="ss01"/>
+ <Feature>
+ <!-- LookupCount=1 -->
+ <LookupListIndex index="0" value="1"/>
+ </Feature>
+ </FeatureRecord>
+ </FeatureList>
+ <LookupList>
+ <!-- LookupCount=2 -->
+ <Lookup index="0">
+ <LookupType value="1"/>
+ <LookupFlag value="0"/>
+ <!-- SubTableCount=1 -->
+ <SingleSubst index="0">
+ <Substitution in="a" out="a.alt1"/>
+ </SingleSubst>
+ </Lookup>
+ <Lookup index="1">
+ <LookupType value="1"/>
+ <LookupFlag value="0"/>
+ <!-- SubTableCount=1 -->
+ <SingleSubst index="0">
+ <Substitution in="a" out="a.alt1"/>
+ </SingleSubst>
+ </Lookup>
+ </LookupList>
+ </GSUB>
+
+</ttFont>