26 Commits

Author SHA1 Message Date
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
ReadRoberts
a460eee80b varLib. Add support for building CFF2 variable font
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.
2018-11-12 11:38:18 -08:00
Cosimo Lupo
d570fc038a
use otRound when rounding visual coordinates or deltas
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
2018-06-14 17:40:11 +01:00
Cosimo Lupo
2cc182ce58
Revert "Revert "t2CharStringPen: specializeCommands expects command args to be list, not tuples""
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
2018-02-20 17:35:10 +00:00
Cosimo Lupo
fe2e897d13
Revert "t2CharStringPen: specializeCommands expects command args to be list, not tuples"
This reverts commit 41445b8449733ade6117b3ae834da518e5623ef8.

41445b8449 (commitcomment-27640426)
2018-02-19 14:57:18 +00:00
Behdad Esfahbod
7ade0096de [pens.t2CharStringPen] Call BasePen constructor
Fixes https://github.com/fonttools/fonttools/issues/965
2017-05-17 17:06:00 -07:00
Cosimo Lupo
41445b8449
t2CharStringPen: specializeCommands expects command args to be list, not tuples
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.
2017-05-08 10:51:39 +01:00
Behdad Esfahbod
0e94f909a6 [pens.t2CharStringPen] Disallow glyph width in CFF2 2017-05-06 13:16:07 -06:00
Behdad Esfahbod
2abacb9366 [pens.t2CharString] Bump CFF2 stack size from 193 to 513
That's happening in the next version of OpenType spec (and maxstack
operator deprecated.)
2017-05-06 13:14:25 -06:00
Behdad Esfahbod
4b5c1be29b [pens.t2CharStringPen] Add CFF2 mode 2017-05-06 04:54:07 -06:00
Behdad Esfahbod
72ec474f74 [pens.t2CharStringPen] Simplify drastically 2017-05-06 04:50:24 -06:00
Behdad Esfahbod
c8cf233e26 [pens.t2CharStringPen] Hook up to cffLib.specializer
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
2017-05-05 21:21:30 -06:00
Miguel Sousa
70c695f8f6 [t2CharStringPen] Make it more clear that the variables hold offsets 2017-04-28 03:34:41 -07:00
Miguel Sousa
c757cf7b70 [t2CharStringPen] Support more path construction operators 2017-04-28 03:26:37 -07:00
Behdad Esfahbod
f3bfea12c6 Add __all__ to pens that didn't have it 2017-02-21 12:01:10 -06:00
Cosimo Lupo
29f0a99a06
[t2CharStringPen] add docstring to T2CharStringPen to explain how 'roundTolerance' works 2017-01-14 12:11:21 +00:00
Cosimo Lupo
8891f4185e
[t2CharStringPen] allow tolerance to be > 0.5
See https://github.com/fonttools/fonttools/pull/804#issuecomment-272559973
2017-01-13 22:32:10 +00:00
Cosimo Lupo
456e159a5a
[t2CharStringPen] raise ValueError if tolerance not in range 0 <= t <= 0.5 2017-01-13 09:34:42 +00:00
Cosimo Lupo
0a9800b109
[t2CharStringPen] use abs() instead of math.fabs()
abs ends up calling fabs for floats anyway, and is a bit faster if 'number' is an int
2017-01-13 09:25:49 +00:00
Cosimo Lupo
3165fa9703
[t2CharStringPen] always round the advance widths regardless of roundTolerance
hmtx only can have integer values, so it would be weird to have widths as float in CFF...
2017-01-12 22:38:28 +00:00
Cosimo Lupo
adac78591d
[t2CharStringPen] restore default rounding; tolerance must be between 0 and .5 2017-01-12 21:34:59 +00:00
Cosimo Lupo
834d0d4cca
[t2CharStringPen] disable rounding coordinates; add 'roundTolerance' argument
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
2017-01-12 19:48:55 +00:00
James Godfrey-Kittle
5d7f3a9a1f Fix author name typo 2015-10-30 10:32:04 -07:00
James Godfrey-Kittle
e85b975f3a Fix imports in t2CharStringPen
We don't need the array module here, and it looks like py23.* should
be imported everywhere.
2015-10-23 11:36:46 -07:00
James Godfrey-Kittle
82e53f020c Use Python3-compatible arguments for roundIntPoint 2015-10-23 11:23:21 -07:00
James Godfrey-Kittle
7b3ac62db7 Add pen which draws to Type 2 charstrings 2015-10-23 11:15:16 -07:00