Skip to content

Commit

Permalink
feaLib: Drop glyph and class names length limit
Browse files Browse the repository at this point in the history
These were implemented to follow FEA spec, but makeotf does not seem to
have a length limit on class names, and the glyph names limit (if it
still has it, I didn’t check) seems like an implementation detail we
don’t have to enforce.

Fixes googlefonts/ufo2ft#588
See also googlefonts/ufo2ft#811 (comment)
  • Loading branch information
khaledhosny committed Jan 22, 2024
1 parent 679a5c0 commit c2646b0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
4 changes: 0 additions & 4 deletions Lib/fontTools/feaLib/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ def next_(self):
glyphclass = text[start + 1 : self.pos_]
if len(glyphclass) < 1:
raise FeatureLibError("Expected glyph class name", location)
if len(glyphclass) > 63:
raise FeatureLibError(
"Glyph class names must not be longer than 63 characters", location
)
if not Lexer.RE_GLYPHCLASS.match(glyphclass):
raise FeatureLibError(
"Glyph class names must consist of letters, digits, "
Expand Down
5 changes: 0 additions & 5 deletions Lib/fontTools/feaLib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,11 +2072,6 @@ def expect_glyph_(self):
self.advance_lexer_()
if self.cur_token_type_ is Lexer.NAME:
self.cur_token_ = self.cur_token_.lstrip("\\")
if len(self.cur_token_) > 63:
raise FeatureLibError(
"Glyph names must not be longer than 63 characters",
self.cur_token_location_,
)
return self.cur_token_
elif self.cur_token_type_ is Lexer.CID:
return "cid%05d" % self.cur_token_
Expand Down
4 changes: 1 addition & 3 deletions Tests/feaLib/lexer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def test_glyphclass(self):
self.assertEqual(lex("@Vowel-sc"), [(Lexer.GLYPHCLASS, "Vowel-sc")])
self.assertRaisesRegex(FeatureLibError, "Expected glyph class", lex, "@(a)")
self.assertRaisesRegex(FeatureLibError, "Expected glyph class", lex, "@ A")
self.assertRaisesRegex(
FeatureLibError, "not be longer than 63 characters", lex, "@" + ("A" * 64)
)
self.assertEqual(lex("@" + ("A" * 64)), [(Lexer.GLYPHCLASS, "A" * 64)])
self.assertRaisesRegex(
FeatureLibError, "Glyph class names must consist of", lex, "@Ab:c"
)
Expand Down
11 changes: 5 additions & 6 deletions Tests/feaLib/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def mapping(s):
"""
).split()
+ ["foo.%d" % i for i in range(1, 200)]
+ ["G" * 64]
)


Expand Down Expand Up @@ -327,12 +328,10 @@ def test_glyphclass(self):
self.assertEqual(gc.glyphSet(), ("endash", "emdash", "figuredash"))

def test_glyphclass_glyphNameTooLong(self):
self.assertRaisesRegex(
FeatureLibError,
"must not be longer than 63 characters",
self.parse,
"@GlyphClass = [%s];" % ("G" * 64),
)
gname = "G" * 64
[gc] = self.parse(f"@GlyphClass = [{gname}];").statements
self.assertEqual(gc.name, "GlyphClass")
self.assertEqual(gc.glyphSet(), (gname,))

def test_glyphclass_bad(self):
self.assertRaisesRegex(
Expand Down

0 comments on commit c2646b0

Please sign in to comment.