[varLib] Update supportScalar() to allow for OpenType-specific contraints
Part of https://github.com/fonttools/fonttools/issues/1020
This commit is contained in:
parent
18fa7ccec0
commit
a1629fa52b
@ -68,9 +68,11 @@ def normalizeLocation(location, axes):
|
|||||||
out[tag] = normalizeValue(v, triple)
|
out[tag] = normalizeValue(v, triple)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def supportScalar(location, support):
|
def supportScalar(location, support, ot=False):
|
||||||
"""Returns the scalar multiplier at location, for a master
|
"""Returns the scalar multiplier at location, for a master
|
||||||
with support.
|
with support. If ot is True, then a peak value of zero
|
||||||
|
for support of an axis means "axis does not participate". That
|
||||||
|
is how OpenType Variation Font technology works.
|
||||||
>>> supportScalar({}, {})
|
>>> supportScalar({}, {})
|
||||||
1.0
|
1.0
|
||||||
>>> supportScalar({'wght':.2}, {})
|
>>> supportScalar({'wght':.2}, {})
|
||||||
@ -79,17 +81,29 @@ def supportScalar(location, support):
|
|||||||
0.1
|
0.1
|
||||||
>>> supportScalar({'wght':2.5}, {'wght':(0,2,4)})
|
>>> supportScalar({'wght':2.5}, {'wght':(0,2,4)})
|
||||||
0.75
|
0.75
|
||||||
|
>>> supportScalar({'wght':2.5, 'wdth':0}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
|
||||||
|
0.75
|
||||||
|
>>> supportScalar({'wght':2.5, 'wdth':.5}, {'wght':(0,2,4), 'wdth':(-1,0,+1)})
|
||||||
|
0.375
|
||||||
|
>>> supportScalar({'wght':2.5, 'wdth':0}, {'wght':(0,2,4), 'wdth':(-1,0,+1)}, ot=True)
|
||||||
|
0.75
|
||||||
|
>>> supportScalar({'wght':2.5, 'wdth':.5}, {'wght':(0,2,4), 'wdth':(-1,0,+1)}, ot=True)
|
||||||
|
0.75
|
||||||
"""
|
"""
|
||||||
scalar = 1.
|
scalar = 1.
|
||||||
for axis,(lower,peak,upper) in support.items():
|
for axis,(lower,peak,upper) in support.items():
|
||||||
if axis not in location:
|
if ot:
|
||||||
scalar = 0.
|
# OpenType-specific case handling
|
||||||
break
|
if peak == 0.:
|
||||||
if peak == 0.0:
|
continue
|
||||||
# Special case: peak is at zero, meaning this axis should not
|
if lower > peak or peak > upper:
|
||||||
# factor into the scalar calculation
|
continue
|
||||||
continue
|
if lower < 0. and upper > 0.:
|
||||||
v = location[axis]
|
continue
|
||||||
|
v = location.get(axis, 0.)
|
||||||
|
else:
|
||||||
|
assert axis in location
|
||||||
|
v = location[axis]
|
||||||
if v == peak:
|
if v == peak:
|
||||||
continue
|
continue
|
||||||
if v <= lower or upper <= v:
|
if v <= lower or upper <= v:
|
||||||
@ -249,7 +263,7 @@ class VariationModel(object):
|
|||||||
deltaWeight = {}
|
deltaWeight = {}
|
||||||
# Walk over previous masters now, populate deltaWeight
|
# Walk over previous masters now, populate deltaWeight
|
||||||
for j,m in enumerate(locations[:i]):
|
for j,m in enumerate(locations[:i]):
|
||||||
scalar = supportScalar(loc, supports[j])
|
scalar = supportScalar(loc, supports[j], ot=True)
|
||||||
if scalar:
|
if scalar:
|
||||||
deltaWeight[j] = scalar
|
deltaWeight[j] = scalar
|
||||||
deltaWeights.append(deltaWeight)
|
deltaWeights.append(deltaWeight)
|
||||||
|
@ -141,7 +141,7 @@ def main(args=None):
|
|||||||
coordinates,_ = _GetCoordinates(varfont, glyphname)
|
coordinates,_ = _GetCoordinates(varfont, glyphname)
|
||||||
origCoords, endPts = None, None
|
origCoords, endPts = None, None
|
||||||
for var in variations:
|
for var in variations:
|
||||||
scalar = supportScalar(loc, var.axes)
|
scalar = supportScalar(loc, var.axes, ot=True)
|
||||||
if not scalar: continue
|
if not scalar: continue
|
||||||
delta = var.coordinates
|
delta = var.coordinates
|
||||||
if None in delta:
|
if None in delta:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user