From 41c7760be3af3bbe6b1455861dc78734b71b7446 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Fri, 3 May 2019 00:53:09 +0200 Subject: [PATCH] =?UTF-8?q?[feaLib]=20don=E2=80=99t=20write=20None=20in=20?= =?UTF-8?q?ast.ValueRecord.asFea()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code tries to write the short format when some values as None, but when writing the long format it would write any None value as is which is invalid, use 0 for None values instead. --- Lib/fontTools/feaLib/ast.py | 6 ++++++ Tests/feaLib/ast_test.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Lib/fontTools/feaLib/ast.py b/Lib/fontTools/feaLib/ast.py index 39dc4bcf8..1994fc08c 100644 --- a/Lib/fontTools/feaLib/ast.py +++ b/Lib/fontTools/feaLib/ast.py @@ -1143,6 +1143,12 @@ class ValueRecord(Expression): elif yAdvance is None and not vertical: return str(xAdvance) + # Make any remaining None value 0 to avoid generating invalid records. + x = x or 0 + y = y or 0 + xAdvance = xAdvance or 0 + yAdvance = yAdvance or 0 + # Try format B, if possible. if (xPlaDevice is None and yPlaDevice is None and xAdvDevice is None and yAdvDevice is None): diff --git a/Tests/feaLib/ast_test.py b/Tests/feaLib/ast_test.py index 7a43d7bf2..54bd5b3e2 100644 --- a/Tests/feaLib/ast_test.py +++ b/Tests/feaLib/ast_test.py @@ -11,6 +11,10 @@ class AstTest(unittest.TestCase): statement.append(ast.GlyphName(name)) self.assertEqual(statement.asFea(), r"[\BASE \NULL foo a]") + def test_valuerecord_none(self): + statement = ast.ValueRecord(xPlacement=10, xAdvance=20) + self.assertEqual(statement.asFea(), "<10 0 20 0>") + if __name__ == "__main__": import sys