Merge pull request #2277 from fonttools/fix-aalt-empty-lookup

fix AttributeError while generating aalt feature with empty lookup
This commit is contained in:
Cosimo Lupo 2021-04-26 14:19:02 +01:00 committed by GitHub
commit 8064028ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 2 deletions

View File

@ -1005,7 +1005,8 @@ class Builder(object):
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

View File

@ -65,7 +65,7 @@ class BuilderTest(unittest.TestCase):
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 @@ class BuilderTest(unittest.TestCase):
"} 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)

View File

@ -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;

View File

@ -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>