* Revert "load_masters: actually assign font attributes"
This reverts commit ef1d4cd02d1e46f5dac3914f547a6e4275cf3077, which caused a
crash in `interpolate_layout()` when `deepcopy`ing OTFs.
Amend code and tests while I work on a real fix.
in a designspace document, the sources' filename attribute can now contain
a relative path to a .TTX file for that master, in addition to .TTF or .UFO
(the latter, resolved through a master_finder callable as before).
Added interpolation of glyph advance width, from HVAR/hmtx, and derivation of new LSB.
Updated tests to match.
Needed to cherrypick from another branch an update for psCharstrings to allow the CFFSubr.draw() method to work.
varStore.py. Commit the correct function references.
psCharstrings.py. Add decompiler class specifically for flattening subroutinized charstrings.
mutator.py. Flatten the subroutinized charstrings, delete the Subrs.
TestCFF2VF.otf, Updated to version with subroutinization. Updated expected ttx output.
varLib.py. restore import of 'fontTools.misc.py23 import *'
varStore.py. Rename 'applyScalar' to 'interpolateFromDeltasAndScalars', and refactor common code with __git__item to a static method.
mutator.py. Update to reflect function name change to interpolateFromDeltasAndScalars. Changed some logic from one line to several lines for readability, and i to avoid flake8 warnings about line too long.
Fix syntax error reported by build system: can't mix string string types when doing literal concatenation
Fix local import reference - doesn't work in Python3.
Addressed issues raised by @msousa for PR 1345 yesterday.
Will change cff2_merge_funcs.py and cff2mergePen.py from tab to space indentations after the current comments are resolved.
Add various improvements from comments:
- do not edit the post table under varLib.build(). Setting post table format 2 or 3 is now expected to be managed by whatever calls varLib.build().
- In the t2CharStringPen module, rename closure _round() nested in makeRoundFunc to an exportable function, and use it in cff2mergePen.
- remove TypeSupply copyright from cff2mergePen.
- use modulo function to convert float to int when it is meant to be 0 in cff2mergePen.
cff2_merge_funcs.py:merge_PrivateDicts() should only be blending the hint related fields in the PrivateDict. This oversight that was surfaced by @madig reporting an error building his Cantrell font. The bug appeared when the font was subroutinized, as the pen draw method then has to interpret the Subr field in order to access T2Charstring subroutines.
Fix expected ttx output file. When I removed the logic to add glyph names to the post table, glyph names in the ttx file changed.
Miguel prefers a simple list for readability in cff2_merge_funs.py:138.
Add test for building CFF2 variable font with a call to varLib.build().
The 'dollar' glyph in the test font is deliberately slightly malformed, with flat curves, in order to exercise the code for dealing with some of the differences in masters designs that can arise from T2 charstring optimization.
this is the mapping between the half of each percentage intervals and
the associated usWidthClass:
{56.25: 1,
68.75: 2,
81.25: 3,
93.75: 4,
106.25: 5,
118.75: 6,
137.5: 7,
175.0: 8}
Notice how wdth=80 (in the adjusted test case) will fall in width class
3, instead of 4, because it is < 81.25, thus closer to the nominal 75
than to 87.5.
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
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.