Skip to content

Commit

Permalink
Allow float values in condition sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Oct 22, 2021
1 parent 870b2a1 commit 0f9ef95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Lib/fontTools/feaLib/parser.py
Expand Up @@ -1881,8 +1881,15 @@ def parse_conditionset_(self):
if axis in conditions:
raise FeatureLibError(f"Repeated condition for axis {axis}", self.cur_token_location_)

min_value = self.expect_number_(variable=False)
max_value = self.expect_number_(variable=False)
if self.next_token_type_ is Lexer.FLOAT:
min_value = self.expect_float_()
elif self.next_token_type_ is Lexer.NUMBER:
min_value = self.expect_number_(variable=False)

if self.next_token_type_ is Lexer.FLOAT:
max_value = self.expect_float_()
elif self.next_token_type_ is Lexer.NUMBER:
max_value = self.expect_number_(variable=False)
self.expect_symbol_(";")

conditions[axis] = (min_value, max_value)
Expand Down
6 changes: 6 additions & 0 deletions Tests/feaLib/parser_test.py
Expand Up @@ -1866,6 +1866,12 @@ def test_conditionset_same_axis(self):
self.parse,
"conditionset heavy { wght 700 900; wght 100 200; } heavy;")

def test_conditionset_float(self):
doc = self.parse("conditionset heavy { wght 700.0 900.0; } heavy;")
value = doc.statements[0]
self.assertEqual(value.conditions["wght"], (700.0, 900.0))
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700.0 900.0;\n} heavy;\n")

def test_variation(self):
doc = self.parse("variation rvrn heavy { sub a by b; } rvrn;")
value = doc.statements[0]
Expand Down

0 comments on commit 0f9ef95

Please sign in to comment.