Skip to content

Commit

Permalink
[instancer] Simplify a couple of things (fonttools#2732)
Browse files Browse the repository at this point in the history
* [instancer] Simplify normalization
  • Loading branch information
behdad authored Aug 15, 2022
1 parent 41e6f60 commit 171670a
Showing 1 changed file with 9 additions and 35 deletions.
44 changes: 9 additions & 35 deletions Lib/fontTools/varLib/instancer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,23 +744,7 @@ def _limitFeatureVariationConditionRange(condition, axisRange):

values = [minValue, maxValue]
for i, value in enumerate(values):
if value < 0:
if axisRange.minimum == 0:
newValue = 0
else:
newValue = value / abs(axisRange.minimum)
if newValue <= -1.0:
newValue = -1.0
elif value > 0:
if axisRange.maximum == 0:
newValue = 0
else:
newValue = value / axisRange.maximum
if newValue >= 1.0:
newValue = 1.0
else:
newValue = 0
values[i] = newValue
values[i] = normalizeValue(value, (axisRange.minimum, 0, axisRange.maximum))

return AxisRange(*values)

Expand Down Expand Up @@ -937,24 +921,14 @@ def instantiateAvar(varfont, axisLimits):
)
newMapping = {}
for fromCoord, toCoord in mapping.items():
if fromCoord < 0:
if axisRange.minimum == 0 or fromCoord < axisRange.minimum:
continue
else:
fromCoord /= abs(axisRange.minimum)
elif fromCoord > 0:
if axisRange.maximum == 0 or fromCoord > axisRange.maximum:
continue
else:
fromCoord /= axisRange.maximum
if toCoord < 0:
assert mappedMin != 0
assert toCoord >= mappedMin
toCoord /= abs(mappedMin)
elif toCoord > 0:
assert mappedMax != 0
assert toCoord <= mappedMax
toCoord /= mappedMax

if fromCoord < axisRange.minimum or fromCoord > axisRange.maximum:
continue
fromCoord = normalizeValue(fromCoord, (axisRange.minimum, 0, axisRange.maximum))

assert mappedMin <= toCoord <= mappedMax
toCoord = normalizeValue(toCoord, (mappedMin, 0, mappedMax))

fromCoord = floatToFixedToFloat(fromCoord, 14)
toCoord = floatToFixedToFloat(toCoord, 14)
newMapping[fromCoord] = toCoord
Expand Down

0 comments on commit 171670a

Please sign in to comment.