Merge pull request #3132 from fonttools/fealib-simplify-variablescaler
[feaLib] Simplify variable scalars that don’t vary
This commit is contained in:
commit
96bede39e7
@ -1606,6 +1606,26 @@ class Builder(object):
|
||||
|
||||
self.conditionsets_[key] = value
|
||||
|
||||
def makeVariablePos(self, location, varscalar):
|
||||
if not self.varstorebuilder:
|
||||
raise FeatureLibError(
|
||||
"Can't define a variable scalar in a non-variable font", location
|
||||
)
|
||||
|
||||
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")
|
||||
)
|
||||
|
||||
device = None
|
||||
if index is not None and index != 0xFFFFFFFF:
|
||||
device = buildVarDevTable(index)
|
||||
|
||||
return default, device
|
||||
|
||||
def makeOpenTypeAnchor(self, location, anchor):
|
||||
"""ast.Anchor --> otTables.Anchor"""
|
||||
if anchor is None:
|
||||
@ -1616,7 +1636,6 @@ class Builder(object):
|
||||
deviceX = otl.buildDevice(dict(anchor.xDeviceTable))
|
||||
if anchor.yDeviceTable is not None:
|
||||
deviceY = otl.buildDevice(dict(anchor.yDeviceTable))
|
||||
avar = self.font.get("avar")
|
||||
for dim in ("x", "y"):
|
||||
varscalar = getattr(anchor, dim)
|
||||
if not isinstance(varscalar, VariableScalar):
|
||||
@ -1625,20 +1644,13 @@ class Builder(object):
|
||||
raise FeatureLibError(
|
||||
"Can't define a device coordinate and variable scalar", location
|
||||
)
|
||||
if not self.varstorebuilder:
|
||||
raise FeatureLibError(
|
||||
"Can't define a variable scalar in a non-variable font", location
|
||||
)
|
||||
varscalar.axes = self.axes
|
||||
default, index = varscalar.add_to_variation_store(
|
||||
self.varstorebuilder, self.model_cache, avar
|
||||
)
|
||||
default, device = self.makeVariablePos(location, varscalar)
|
||||
setattr(anchor, dim, default)
|
||||
if index is not None and index != 0xFFFFFFFF:
|
||||
if device is not None:
|
||||
if dim == "x":
|
||||
deviceX = buildVarDevTable(index)
|
||||
deviceX = device
|
||||
else:
|
||||
deviceY = buildVarDevTable(index)
|
||||
deviceY = device
|
||||
variable = True
|
||||
|
||||
otlanchor = otl.buildAnchor(
|
||||
@ -1659,7 +1671,6 @@ class Builder(object):
|
||||
if not v:
|
||||
return None
|
||||
|
||||
avar = self.font.get("avar")
|
||||
vr = {}
|
||||
for astName, (otName, isDevice) in self._VALUEREC_ATTRS.items():
|
||||
val = getattr(v, astName, None)
|
||||
@ -1674,18 +1685,9 @@ class Builder(object):
|
||||
raise FeatureLibError(
|
||||
"Can't define a device coordinate and variable scalar", location
|
||||
)
|
||||
if not self.varstorebuilder:
|
||||
raise FeatureLibError(
|
||||
"Can't define a variable scalar in a non-variable font",
|
||||
location,
|
||||
)
|
||||
val.axes = self.axes
|
||||
default, index = val.add_to_variation_store(
|
||||
self.varstorebuilder, self.model_cache, avar
|
||||
)
|
||||
vr[otName] = default
|
||||
if index is not None and index != 0xFFFFFFFF:
|
||||
vr[otDeviceName] = buildVarDevTable(index)
|
||||
vr[otName], device = self.makeVariablePos(location, val)
|
||||
if device is not None:
|
||||
vr[otDeviceName] = device
|
||||
else:
|
||||
vr[otName] = val
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user