[feaLib] Simplify variable scalars that don’t vary

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.
This commit is contained in:
Khaled Hosny 2023-05-27 02:50:15 +03:00
parent f8abda4570
commit fd854d70d8
3 changed files with 12 additions and 1 deletions

View File

@ -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")
)

View File

@ -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;

View File

@ -76,7 +76,7 @@
<Lookup index="0">
<LookupType value="1"/>
<LookupFlag value="0"/>
<!-- SubTableCount=2 -->
<!-- SubTableCount=3 -->
<SinglePos index="0" Format="1">
<Coverage>
<Glyph value="one"/>
@ -97,6 +97,13 @@
</YPlaDevice>
</Value>
</SinglePos>
<SinglePos index="2" Format="1">
<Coverage>
<Glyph value="three"/>
</Coverage>
<ValueFormat value="2"/>
<Value YPlacement="12"/>
</SinglePos>
</Lookup>
</LookupList>
</GPOS>