From fd854d70d81fb2e1922d799dd31f8fdc44dc19ea Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sat, 27 May 2023 02:50:15 +0300 Subject: [PATCH] =?UTF-8?q?[feaLib]=20Simplify=20variable=20scalars=20that?= =?UTF-8?q?=20don=E2=80=99t=20vary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a variable scalar does not vary (i.e. all values are the same), we can simplify it and use a simple value instead. Arguably users shouldn’t be using variable scalar in this case, but it helps when the feature code is auto generated so each feaLib users doesn’t have to do the check done here themselves. --- Lib/fontTools/feaLib/builder.py | 3 +++ Tests/feaLib/data/variable_scalar_valuerecord.fea | 1 + Tests/feaLib/data/variable_scalar_valuerecord.ttx | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 6eaff843a..e0e102864 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -1613,6 +1613,9 @@ class Builder(object): ) varscalar.axes = self.axes + if not varscalar.does_vary: + return varscalar.default, None + default, index = varscalar.add_to_variation_store( self.varstorebuilder, self.model_cache, self.font.get("avar") ) diff --git a/Tests/feaLib/data/variable_scalar_valuerecord.fea b/Tests/feaLib/data/variable_scalar_valuerecord.fea index bf9a26b7d..0b4026544 100644 --- a/Tests/feaLib/data/variable_scalar_valuerecord.fea +++ b/Tests/feaLib/data/variable_scalar_valuerecord.fea @@ -2,4 +2,5 @@ languagesystem DFLT dflt; feature kern { pos one 1; pos two <0 (wght=200:12 wght=900:22 wdth=150,wght=900:42) 0 0>; + pos three <0 (wght=200:12 wght=900:12 wdth=150,wght=900:12) 0 0>; } kern; diff --git a/Tests/feaLib/data/variable_scalar_valuerecord.ttx b/Tests/feaLib/data/variable_scalar_valuerecord.ttx index 338b72213..e3251f691 100644 --- a/Tests/feaLib/data/variable_scalar_valuerecord.ttx +++ b/Tests/feaLib/data/variable_scalar_valuerecord.ttx @@ -76,7 +76,7 @@ - + @@ -97,6 +97,13 @@ + + + + + + +