Merge pull request #3104 from fonttools/multiple-subst-classes-2

feaLib: handle singleton class as a single glyph in multiple subst
This commit is contained in:
خالد حسني (Khaled Hosny) 2023-05-10 17:57:43 +03:00 committed by GitHub
commit fbb30dc6a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -935,9 +935,9 @@ class Parser(object):
for n in new:
if not list(n.glyphSet()):
raise FeatureLibError("Empty class in replacement", location)
if not isinstance(n, self.ast.GlyphName) and len(n.glyphSet()) != count:
if len(n.glyphSet()) != 1 and len(n.glyphSet()) != count:
raise FeatureLibError(
f'Expected a glyph class with {count} elements after "by", '
f'Expected a glyph class with 1 or {count} elements after "by", '
f"but found a glyph class with {len(n.glyphSet())} elements",
location,
)

View File

@ -1642,13 +1642,20 @@ class ParserTest(unittest.TestCase):
self.assertEqual(glyphstr([sub.glyph]), "[f_i f_l]")
self.assertEqual(glyphstr(sub.replacement), "f [i l]")
def test_substitute_multiple_classes_mixed_singleton(self):
doc = self.parse("lookup Look {substitute [f_i f_l] by [f] [i l];} Look;")
sub = doc.statements[0].statements[0]
self.assertIsInstance(sub, ast.MultipleSubstStatement)
self.assertEqual(glyphstr([sub.glyph]), "[f_i f_l]")
self.assertEqual(glyphstr(sub.replacement), "f [i l]")
def test_substitute_multiple_classes_mismatch(self):
self.assertRaisesRegex(
FeatureLibError,
'Expected a glyph class with 2 elements after "by", '
"but found a glyph class with 1 elements",
'Expected a glyph class with 1 or 3 elements after "by", '
"but found a glyph class with 2 elements",
self.parse,
"lookup Look {substitute [f_i f_l] by [f] [i l];} Look;",
"lookup Look {substitute [f_i f_l f_f_i] by [f f_f] [i l i];} Look;",
)
def test_substitute_multiple_by_mutliple(self):