From bd618d01178961e971ba9dd4cb9f3d808c3446e6 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 22 Apr 2021 12:21:30 +0100 Subject: [PATCH 1/3] add test to repro AttributeError when getAlternateGlyphs for empty lookups https://github.com/fonttools/fonttools/issues/2276 --- Tests/feaLib/builder_test.py | 2 +- Tests/feaLib/data/bug2276.fea | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Tests/feaLib/data/bug2276.fea diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py index 0a55239c9..f53f28284 100644 --- a/Tests/feaLib/builder_test.py +++ b/Tests/feaLib/builder_test.py @@ -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 diff --git a/Tests/feaLib/data/bug2276.fea b/Tests/feaLib/data/bug2276.fea new file mode 100644 index 000000000..96f988597 --- /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; From 9b5bc9e18bcd0b9243e944e0a6a882fa24bd1c47 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 22 Apr 2021 13:11:57 +0100 Subject: [PATCH 2/3] feaLib: ignore empty named lookup reference Fixes #2276 --- Lib/fontTools/feaLib/builder.py | 3 +- Tests/feaLib/data/bug2276.ttx | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Tests/feaLib/data/bug2276.ttx diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 4a7d95758..989f05e20 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -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 diff --git a/Tests/feaLib/data/bug2276.ttx b/Tests/feaLib/data/bug2276.ttx new file mode 100644 index 000000000..57902dafa --- /dev/null +++ b/Tests/feaLib/data/bug2276.ttx @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2830260a01e6908be52817b3eccda8437467c559 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 26 Apr 2021 10:07:36 +0100 Subject: [PATCH 3/3] another test to check that empty lookups blocks are skipped --- Tests/feaLib/builder_test.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/feaLib/builder_test.py b/Tests/feaLib/builder_test.py index f53f28284..951a360fc 100644 --- a/Tests/feaLib/builder_test.py +++ b/Tests/feaLib/builder_test.py @@ -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)