[instancer] Don't produce triples outside <-1,0,+1>

Fixes https://github.com/fonttools/fonttools/issues/3350
This commit is contained in:
Behdad Esfahbod 2023-12-06 08:14:03 -07:00
parent 4dbf534bc2
commit 8728789c05
3 changed files with 25 additions and 8 deletions

View File

@ -178,7 +178,9 @@ def _solve(tent, axisLimit, negative=False):
# #
newUpper = peak + (1 - gain) * (upper - peak) newUpper = peak + (1 - gain) * (upper - peak)
assert axisMax <= newUpper # Because outGain > gain 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 upper = newUpper
if not negative and axisDef + (axisMax - axisDef) * MAX_F2DOT14 < upper: if not negative and axisDef + (axisMax - axisDef) * MAX_F2DOT14 < upper:
# we clamp +2.0 to the max F2Dot14 (~1.99994) for convenience # we clamp +2.0 to the max F2Dot14 (~1.99994) for convenience

View File

@ -1986,7 +1986,10 @@ class LimitTupleVariationAxisRangesTest:
TupleVariation({"wght": (0.0, 0.5, 1.0)}, [100, 100]), TupleVariation({"wght": (0.0, 0.5, 1.0)}, [100, 100]),
"wght", "wght",
0.6, 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]), TupleVariation({"wght": (0.0, 0.2, 1.0)}, [100, 100]),
@ -2001,7 +2004,10 @@ class LimitTupleVariationAxisRangesTest:
TupleVariation({"wght": (0.0, 0.2, 1.0)}, [100, 100]), TupleVariation({"wght": (0.0, 0.2, 1.0)}, [100, 100]),
"wght", "wght",
0.5, 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]), TupleVariation({"wght": (0.5, 0.5, 1.0)}, [100, 100]),
@ -2065,7 +2071,10 @@ class LimitTupleVariationAxisRangesTest:
TupleVariation({"wght": (-1.0, -0.5, 0.0)}, [100, 100]), TupleVariation({"wght": (-1.0, -0.5, 0.0)}, [100, 100]),
"wght", "wght",
-0.6, -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]), TupleVariation({"wght": (-1.0, -0.2, 0.0)}, [100, 100]),
@ -2080,7 +2089,10 @@ class LimitTupleVariationAxisRangesTest:
TupleVariation({"wght": (-1.0, -0.2, 0.0)}, [100, 100]), TupleVariation({"wght": (-1.0, -0.2, 0.0)}, [100, 100]),
"wght", "wght",
-0.5, -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]), TupleVariation({"wght": (-1.0, -0.5, -0.5)}, [100, 100]),

View File

@ -43,7 +43,8 @@ class RebaseTentTest(object):
(0, 0.2, 1), (0, 0.2, 1),
(-1, 0, 0.8), (-1, 0, 0.8),
[ [
(1, (0, 0.25, 1.25)), (1, (0, 0.25, 1)),
(0.25, (0.25, 1, 1)),
], ],
), ),
# Case 3 boundary # Case 3 boundary
@ -51,7 +52,8 @@ class RebaseTentTest(object):
(0, 0.4, 1), (0, 0.4, 1),
(-1, 0, 0.5), (-1, 0, 0.5),
[ [
(1, (0, 0.8, 1.99994)), (1, (0, 0.8, 1)),
(2.5 / 3, (0.8, 1, 1)),
], ],
), ),
# Case 4 # Case 4
@ -234,7 +236,8 @@ class RebaseTentTest(object):
(0, 0.2, 1), (0, 0.2, 1),
(0, 0, 0.5), (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 # https://github.com/fonttools/fonttools/issues/3139