[instancer.solver] Fix case where axisDef < lower and upper < axisMax

Fixes https://github.com/fonttools/fonttools/issues/3291
This commit is contained in:
Behdad Esfahbod 2023-10-16 13:46:39 -06:00
parent 27932c525b
commit f1e56cd757
2 changed files with 13 additions and 3 deletions

View File

@ -99,11 +99,13 @@ def _solve(tent, axisLimit, negative=False):
# axisDef | axisMax
# |
# crossing
if gain > outGain:
if gain >= outGain:
# Note that this is the branch taken if both gain and outGain are 0.
# Crossing point on the axis.
crossing = peak + (1 - gain) * (upper - peak)
loc = (axisDef, peak, crossing)
loc = (max(lower, axisDef), peak, crossing)
scalar = 1
# The part before the crossing point.
@ -175,7 +177,7 @@ def _solve(tent, axisLimit, negative=False):
# axisDef axisMax
#
newUpper = peak + (1 - gain) * (upper - peak)
assert axisMax <= newUpper # Because outGain >= gain
assert axisMax <= newUpper # Because outGain > gain
if newUpper <= axisDef + (axisMax - axisDef) * 2:
upper = newUpper
if not negative and axisDef + (axisMax - axisDef) * MAX_F2DOT14 < upper:

View File

@ -276,6 +276,14 @@ class RebaseTentTest(object):
(1.0, (0.5, 1.0, 1.0)),
],
),
# https://github.com/fonttools/fonttools/issues/3291
pytest.param(
(0.6, 0.7, 0.8),
(-1, 0.2, +1, 1, 1),
[
(1.0, (0.5, 0.625, 0.75)),
],
),
],
)
def test_rebaseTent(self, tent, axisRange, expected):