Skip to content

Commit

Permalink
[instancer] Don't produce triples outside <-1,0,+1>
Browse files Browse the repository at this point in the history
Fixes #3350
  • Loading branch information
behdad committed Dec 6, 2023
1 parent 4dbf534 commit 8728789
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Lib/fontTools/varLib/instancer/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ def _solve(tent, axisLimit, negative=False):
#
newUpper = peak + (1 - gain) * (upper - peak)
assert axisMax <= newUpper # Because outGain > gain
if newUpper <= axisDef + (axisMax - axisDef) * 2:
# Disabled because ots doesn't like us:
# https://github.com/fonttools/fonttools/issues/3350
if False and newUpper <= axisDef + (axisMax - axisDef) * 2:
upper = newUpper
if not negative and axisDef + (axisMax - axisDef) * MAX_F2DOT14 < upper:
# we clamp +2.0 to the max F2Dot14 (~1.99994) for convenience
Expand Down
20 changes: 16 additions & 4 deletions Tests/varLib/instancer/instancer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,10 @@ def check_limit_single_var_axis_range(self, var, axisTag, axisRange, expected):
TupleVariation({"wght": (0.0, 0.5, 1.0)}, [100, 100]),
"wght",
0.6,
[TupleVariation({"wght": (0.0, 0.833334, 1.666667)}, [100, 100])],
[
TupleVariation({"wght": (0.0, 0.833334, 1.0)}, [100, 100]),
TupleVariation({"wght": (0.833334, 1.0, 1.0)}, [80, 80]),
],
),
(
TupleVariation({"wght": (0.0, 0.2, 1.0)}, [100, 100]),
Expand All @@ -2001,7 +2004,10 @@ def check_limit_single_var_axis_range(self, var, axisTag, axisRange, expected):
TupleVariation({"wght": (0.0, 0.2, 1.0)}, [100, 100]),
"wght",
0.5,
[TupleVariation({"wght": (0.0, 0.4, 1.99994)}, [100, 100])],
[
TupleVariation({"wght": (0.0, 0.4, 1)}, [100, 100]),
TupleVariation({"wght": (0.4, 1, 1)}, [62.5, 62.5]),
],
),
(
TupleVariation({"wght": (0.5, 0.5, 1.0)}, [100, 100]),
Expand Down Expand Up @@ -2065,7 +2071,10 @@ def test_positive_var(self, var, axisTag, newMax, expected):
TupleVariation({"wght": (-1.0, -0.5, 0.0)}, [100, 100]),
"wght",
-0.6,
[TupleVariation({"wght": (-1.666667, -0.833334, 0.0)}, [100, 100])],
[
TupleVariation({"wght": (-1.0, -0.833334, 0.0)}, [100, 100]),
TupleVariation({"wght": (-1.0, -1.0, -0.833334)}, [80, 80]),
],
),
(
TupleVariation({"wght": (-1.0, -0.2, 0.0)}, [100, 100]),
Expand All @@ -2080,7 +2089,10 @@ def test_positive_var(self, var, axisTag, newMax, expected):
TupleVariation({"wght": (-1.0, -0.2, 0.0)}, [100, 100]),
"wght",
-0.5,
[TupleVariation({"wght": (-2.0, -0.4, 0.0)}, [100, 100])],
[
TupleVariation({"wght": (-1.0, -0.4, 0.0)}, [100, 100]),
TupleVariation({"wght": (-1.0, -1.0, -0.4)}, [62.5, 62.5]),
],
),
(
TupleVariation({"wght": (-1.0, -0.5, -0.5)}, [100, 100]),
Expand Down
9 changes: 6 additions & 3 deletions Tests/varLib/instancer/solver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ class RebaseTentTest(object):
(0, 0.2, 1),
(-1, 0, 0.8),
[
(1, (0, 0.25, 1.25)),
(1, (0, 0.25, 1)),
(0.25, (0.25, 1, 1)),
],
),
# Case 3 boundary
pytest.param(
(0, 0.4, 1),
(-1, 0, 0.5),
[
(1, (0, 0.8, 1.99994)),
(1, (0, 0.8, 1)),
(2.5 / 3, (0.8, 1, 1)),
],
),
# Case 4
Expand Down Expand Up @@ -234,7 +236,8 @@ class RebaseTentTest(object):
(0, 0.2, 1),
(0, 0, 0.5),
[
(1, (0, 0.4, 1.99994)),
(1, (0, 0.4, 1)),
(0.625, (0.4, 1, 1)),
],
),
# https://github.com/fonttools/fonttools/issues/3139
Expand Down

0 comments on commit 8728789

Please sign in to comment.