2017-01-17 13:13:37 +00:00
|
|
|
from __future__ import print_function, division, absolute_import
|
|
|
|
from fontTools.misc.py23 import *
|
|
|
|
from fontTools.varLib.models import (
|
|
|
|
normalizeLocation, supportScalar, VariationModel)
|
|
|
|
|
|
|
|
|
|
|
|
def test_normalizeLocation():
|
|
|
|
axes = {"wght": (100, 400, 900)}
|
2017-04-12 21:52:29 -07:00
|
|
|
assert normalizeLocation({"wght": 400}, axes) == {'wght': 0.0}
|
2017-01-17 13:13:37 +00:00
|
|
|
assert normalizeLocation({"wght": 100}, axes) == {'wght': -1.0}
|
|
|
|
assert normalizeLocation({"wght": 900}, axes) == {'wght': 1.0}
|
|
|
|
assert normalizeLocation({"wght": 650}, axes) == {'wght': 0.5}
|
|
|
|
assert normalizeLocation({"wght": 1000}, axes) == {'wght': 1.0}
|
|
|
|
assert normalizeLocation({"wght": 0}, axes) == {'wght': -1.0}
|
|
|
|
|
|
|
|
axes = {"wght": (0, 0, 1000)}
|
2017-04-12 21:52:29 -07:00
|
|
|
assert normalizeLocation({"wght": 0}, axes) == {'wght': 0.0}
|
|
|
|
assert normalizeLocation({"wght": -1}, axes) == {'wght': 0.0}
|
2017-01-17 13:13:37 +00:00
|
|
|
assert normalizeLocation({"wght": 1000}, axes) == {'wght': 1.0}
|
|
|
|
assert normalizeLocation({"wght": 500}, axes) == {'wght': 0.5}
|
|
|
|
assert normalizeLocation({"wght": 1001}, axes) == {'wght': 1.0}
|
|
|
|
|
|
|
|
axes = {"wght": (0, 1000, 1000)}
|
|
|
|
assert normalizeLocation({"wght": 0}, axes) == {'wght': -1.0}
|
|
|
|
assert normalizeLocation({"wght": -1}, axes) == {'wght': -1.0}
|
|
|
|
assert normalizeLocation({"wght": 500}, axes) == {'wght': -0.5}
|
2017-04-12 21:52:29 -07:00
|
|
|
assert normalizeLocation({"wght": 1000}, axes) == {'wght': 0.0}
|
|
|
|
assert normalizeLocation({"wght": 1001}, axes) == {'wght': 0.0}
|
2017-01-17 13:13:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_supportScalar():
|
|
|
|
assert supportScalar({}, {}) == 1.0
|
|
|
|
assert supportScalar({'wght':.2}, {}) == 1.0
|
|
|
|
assert supportScalar({'wght':.2}, {'wght':(0,2,3)}) == 0.1
|
|
|
|
assert supportScalar({'wght':2.5}, {'wght':(0,2,4)}) == 0.75
|
|
|
|
|
|
|
|
|
|
|
|
def test_VariationModel():
|
|
|
|
locations = [
|
|
|
|
{'wght':100},
|
|
|
|
{'wght':-100},
|
|
|
|
{'wght':-180},
|
|
|
|
{'wdth':+.3},
|
|
|
|
{'wght':+120,'wdth':.3},
|
|
|
|
{'wght':+120,'wdth':.2},
|
|
|
|
{},
|
|
|
|
{'wght':+180,'wdth':.3},
|
|
|
|
{'wght':+180},
|
|
|
|
]
|
|
|
|
model = VariationModel(locations, axisOrder=['wght'])
|
|
|
|
|
|
|
|
assert model.locations == [
|
|
|
|
{},
|
|
|
|
{'wght': -100},
|
|
|
|
{'wght': -180},
|
|
|
|
{'wght': 100},
|
|
|
|
{'wght': 180},
|
|
|
|
{'wdth': 0.3},
|
|
|
|
{'wdth': 0.3, 'wght': 180},
|
|
|
|
{'wdth': 0.3, 'wght': 120},
|
|
|
|
{'wdth': 0.2, 'wght': 120}]
|
|
|
|
|
|
|
|
assert model.deltaWeights == [
|
|
|
|
{},
|
|
|
|
{0: 1.0},
|
|
|
|
{0: 1.0},
|
|
|
|
{0: 1.0},
|
|
|
|
{0: 1.0},
|
|
|
|
{0: 1.0},
|
|
|
|
{0: 1.0, 4: 1.0, 5: 1.0},
|
[varLib] Tweak support-resolution algorithm
Improve varLib model algorithm.
This, basically means any varfont built that had an unusual master
configuration will change when rebuilt.
Here's a good test: a two-axis with 8 masters at unusual locations:
2-----------------5----------3
| |
| 7 |
| |
| 6 |
| |
| |
| |
0-----------4----------------1
Previously, the reach of master 3 (Black Extended) would
have started from A=.4, ie, the A position of master 4.
It now correctly starts from 0. Same thing with masters
after it. Ie, master 5 gets a span on the A axis from
0 to 1, whereas before it was getting from .4 to 1.
Previously, the on-axis masters always cut the space. They
don't anymore. That's more consistent, and fixes the main
issue Erik showed at TYPO Labs 2017. Same issue was also
causing the reach of master 3 to be limited, which I think
is the issue being discussed in the linked issue. Both should
be fixed.
It's hard to describe exactly what happened before / after.
Best to read the actual support values:
Before:
Sorted locations:
$ ./fonttools varLib.models 0,0 0,1 1,0 1,1 .4,0 .6,1 .5,.5 .7,.7
[{},
{'A': 0.4},
{'A': 1.0},
{'B': 1.0},
{'A': 1.0, 'B': 1.0},
{'A': 0.6, 'B': 1.0},
{'A': 0.5, 'B': 0.5},
{'A': 0.7, 'B': 0.7}]
Supports:
[{},
{'A': (0.0, 0.4, 1.0)},
{'A': (0.4, 1.0, 1.0)},
{'B': (0.0, 1.0, 1.0)},
{'A': (0.4, 1.0, 1.0), 'B': (0.0, 1.0, 1.0)},
{'A': (0.4, 0.6, 1.0), 'B': (0.0, 1.0, 1.0)},
{'A': (0.4, 0.5, 1.0), 'B': (0.0, 0.5, 1.0)},
{'A': (0.5, 0.7, 1.0), 'B': (0.5, 0.7, 1.0)}]
After:
$ ./fonttools varLib.models 0,0 0,1 1,0 1,1 .4,0 .6,1 .5,.5 .7,.7
Sorted locations:
[{},
{'A': 0.4},
{'A': 1.0},
{'B': 1.0},
{'A': 1.0, 'B': 1.0},
{'A': 0.6, 'B': 1.0},
{'A': 0.5, 'B': 0.5},
{'A': 0.7, 'B': 0.7}]
Supports:
[{},
{'A': (0, 0.4, 1.0)},
{'A': (0.4, 1.0, 1.0)},
{'B': (0, 1.0, 1.0)},
{'A': (0, 1.0, 1.0), 'B': (0, 1.0, 1.0)},
{'A': (0, 0.6, 1.0), 'B': (0, 1.0, 1.0)},
{'A': (0, 0.5, 1.0), 'B': (0, 0.5, 1.0)},
{'A': (0.5, 0.7, 1.0), 'B': (0.5, 0.7, 1.0)}]
TODO: We should add this as a test case.
There's another improvement I want to make, but that's separate.
2018-03-26 20:31:06 -07:00
|
|
|
{0: 1.0, 3: 0.75, 4: 0.25, 5: 1.0, 6: 0.6666666666666666},
|
2017-01-17 13:13:37 +00:00
|
|
|
{0: 1.0,
|
|
|
|
3: 0.75,
|
|
|
|
4: 0.25,
|
|
|
|
5: 0.6666666666666667,
|
[varLib] Tweak support-resolution algorithm
Improve varLib model algorithm.
This, basically means any varfont built that had an unusual master
configuration will change when rebuilt.
Here's a good test: a two-axis with 8 masters at unusual locations:
2-----------------5----------3
| |
| 7 |
| |
| 6 |
| |
| |
| |
0-----------4----------------1
Previously, the reach of master 3 (Black Extended) would
have started from A=.4, ie, the A position of master 4.
It now correctly starts from 0. Same thing with masters
after it. Ie, master 5 gets a span on the A axis from
0 to 1, whereas before it was getting from .4 to 1.
Previously, the on-axis masters always cut the space. They
don't anymore. That's more consistent, and fixes the main
issue Erik showed at TYPO Labs 2017. Same issue was also
causing the reach of master 3 to be limited, which I think
is the issue being discussed in the linked issue. Both should
be fixed.
It's hard to describe exactly what happened before / after.
Best to read the actual support values:
Before:
Sorted locations:
$ ./fonttools varLib.models 0,0 0,1 1,0 1,1 .4,0 .6,1 .5,.5 .7,.7
[{},
{'A': 0.4},
{'A': 1.0},
{'B': 1.0},
{'A': 1.0, 'B': 1.0},
{'A': 0.6, 'B': 1.0},
{'A': 0.5, 'B': 0.5},
{'A': 0.7, 'B': 0.7}]
Supports:
[{},
{'A': (0.0, 0.4, 1.0)},
{'A': (0.4, 1.0, 1.0)},
{'B': (0.0, 1.0, 1.0)},
{'A': (0.4, 1.0, 1.0), 'B': (0.0, 1.0, 1.0)},
{'A': (0.4, 0.6, 1.0), 'B': (0.0, 1.0, 1.0)},
{'A': (0.4, 0.5, 1.0), 'B': (0.0, 0.5, 1.0)},
{'A': (0.5, 0.7, 1.0), 'B': (0.5, 0.7, 1.0)}]
After:
$ ./fonttools varLib.models 0,0 0,1 1,0 1,1 .4,0 .6,1 .5,.5 .7,.7
Sorted locations:
[{},
{'A': 0.4},
{'A': 1.0},
{'B': 1.0},
{'A': 1.0, 'B': 1.0},
{'A': 0.6, 'B': 1.0},
{'A': 0.5, 'B': 0.5},
{'A': 0.7, 'B': 0.7}]
Supports:
[{},
{'A': (0, 0.4, 1.0)},
{'A': (0.4, 1.0, 1.0)},
{'B': (0, 1.0, 1.0)},
{'A': (0, 1.0, 1.0), 'B': (0, 1.0, 1.0)},
{'A': (0, 0.6, 1.0), 'B': (0, 1.0, 1.0)},
{'A': (0, 0.5, 1.0), 'B': (0, 0.5, 1.0)},
{'A': (0.5, 0.7, 1.0), 'B': (0.5, 0.7, 1.0)}]
TODO: We should add this as a test case.
There's another improvement I want to make, but that's separate.
2018-03-26 20:31:06 -07:00
|
|
|
6: 0.4444444444444445,
|
2017-01-17 13:13:37 +00:00
|
|
|
7: 0.6666666666666667}]
|
2018-06-16 14:07:18 -04:00
|
|
|
|
|
|
|
def test_VariationModel():
|
|
|
|
locations = [
|
|
|
|
{},
|
|
|
|
{'bar': 0.5},
|
|
|
|
{'bar': 1.0},
|
|
|
|
{'foo': 1.0},
|
|
|
|
{'bar': 0.5, 'foo': 1.0},
|
|
|
|
{'bar': 1.0, 'foo': 1.0},
|
|
|
|
]
|
|
|
|
model = VariationModel(locations)
|
|
|
|
|
|
|
|
assert model.locations == locations
|
|
|
|
|
|
|
|
assert model.supports == [
|
|
|
|
{},
|
|
|
|
{'bar': (0, 0.5, 1.0)},
|
|
|
|
{'bar': (0.5, 1.0, 1.0)},
|
|
|
|
{'foo': (0, 1.0, 1.0)},
|
|
|
|
{'bar': (0, 0.5, 1.0), 'foo': (0, 1.0, 1.0)},
|
|
|
|
{'bar': (0.5, 1.0, 1.0), 'foo': (0, 1.0, 1.0)},
|
|
|
|
]
|