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.
So we now round towards +Infinity in:
- floatToFixed (which fully examplify that quotes from OT spec)
- psCharStrings: when packing floats as fixed 16.16
- t2CharStringPen: when rounding coordinates and advance widths
- subset: when rounding advance widths to compute average
- TupleVariation: rounding gvar deltas
- _g_l_y_f: when rounding coordinates: both in GlyphComponent.{x,y}
and for GlyphCoordinates.toInt()
- _h_m_t_x: for rounding horiz/vert metrics
- varLib: rounding horiz metrics and deltas
This reverts commit fe2e897d13aab383d03b7759a15787ed2db99c77.
ufo2ft tests are failing with fonttools master with this error:
fontTools/cffLib/specializer.py:497:
> commands[i-1] = (new_op, args1+args2)
TypeError: can only concatenate list (not "tuple") to list
In the docstring of programToCommands, it says that:
> Each command is a two-tuple of commandname,arg-list
Previously the T2CharStringPen was passing command args as tuples instead
of lists to the specializeCommands function with option generalizeFirst=False,
which would only make a shallow copy of the input commands to modify them
in place. The problem is that it attempted to call list-only methods, leading
to errors like:
File "fontTools/cffLib/specializer.py", line 432, in specializeCommands
args.insert(pos, 0)
AttributeError: 'tuple' object has no attribute 'insert'
Since the expectation of the code here and elsewhere is that args is a
list, it makes sense that the T2 pen passes lists instead of tuples to the
specializeCommands function.
Tests are failing now, as cffLib.specializer combines operations whereas
previous pen didn't. I checked all failures and they all look like the
expectation needs to be updated to me.
Fixes https://github.com/fonttools/fonttools/issues/403
Rounding of coordinates is now disabled by default.
The pen now accepts an optional 'roundTolerance' float, with values between
0 and 1 (default is 0).
Values >= 0.5 mean round all coordinates to integers.
Values between 0 and 0.5 mean round only when the absolute difference
between the original float and the rounded integer is within the tolerance
Fixes#769