4 Commits

Author SHA1 Message Date
Behdad Esfahbod
1801248938 [varLib.models] Fix model resolution
Oops.  Was introduced when I last changed modeling.

The problem was, for checking that a previous master m is outside the current
influence box of the current master, I was doing "not (lower < m[loc] < upper)".
This is wrong, where lower,peak,upper is the support of previous master.
This fails if lower == peak == m[loc], or m[loc] == peak == upper.

Fixes https://github.com/fonttools/fonttools/issues/1269#issuecomment-397655016
2018-06-16 14:07:18 -04:00
Behdad Esfahbod
42bef176a3 [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:32:27 -07:00
Behdad Esfahbod
968c25dd7f [varLib] Generate avar table
Fixes https://github.com/fonttools/fonttools/issues/916
2017-04-12 21:54:43 -07:00
Cosimo Lupo
a79bb0fa01
[Tests] convert varLib/models.py doctests into models_test.py 2017-01-17 13:39:38 +00:00