From 534326bd1ddc97c456a3de27f1471fe449ac00f6 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 27 Oct 2017 21:20:30 +0200 Subject: [PATCH] [feaLib] Fix writing back nested glyph classes Before this change, the following glyph class: @Vowels = [@Vowels.lc @Vowels.uc y Y]; Would be written back as: @Vowels = [@Vowels.lc = [a e i o u]; @Vowels.uc = [A E I O U]; y Y]; Which is clearly invalid. It seems for GlyphClass.asFea() to work correctly here we should be using GlyphClassName not GlyphClass for the nested classes (similar to the code at the beginning of parse_glyphclass_()). --- Lib/fontTools/feaLib/parser.py | 4 ++++ Tests/feaLib/parser_test.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Lib/fontTools/feaLib/parser.py b/Lib/fontTools/feaLib/parser.py index a19554ee4..3f55b85ce 100644 --- a/Lib/fontTools/feaLib/parser.py +++ b/Lib/fontTools/feaLib/parser.py @@ -293,6 +293,10 @@ class Parser(object): raise FeatureLibError( "Unknown glyph class @%s" % self.cur_token_, self.cur_token_location_) + if isinstance(gc, self.ast.MarkClass): + gc = self.ast.MarkClassName(self.cur_token_location_, gc) + else: + gc = self.ast.GlyphClassName(self.cur_token_location_, gc) glyphs.add_class(gc) else: raise FeatureLibError( diff --git a/Tests/feaLib/parser_test.py b/Tests/feaLib/parser_test.py index 86b57f48e..766926f73 100644 --- a/Tests/feaLib/parser_test.py +++ b/Tests/feaLib/parser_test.py @@ -363,6 +363,8 @@ class ParserTest(unittest.TestCase): self.assertEqual(vowels_lc.glyphSet(), tuple("aeiou")) self.assertEqual(vowels_uc.glyphSet(), tuple("AEIOU")) self.assertEqual(vowels.glyphSet(), tuple("aeiouAEIOUyY")) + self.assertEqual(vowels.asFea(), + "@Vowels = [@Vowels.lc @Vowels.uc y Y];") self.assertRaisesRegex( FeatureLibError, "Unknown glyph class @unknown", self.parse, "@bad = [@unknown];")