198 Commits

Author SHA1 Message Date
Cosimo Lupo
d9b6067447
roundingPen: Add RoundingPointPen, like RoundingPen but for point pens 2019-11-28 16:32:40 +00:00
Cosimo Lupo
b885a852ed
recordingPen: add RecordingPointPen, like RecordingPen but for point pens 2019-11-28 16:29:36 +00:00
Cosimo Lupo
0fef59fd9e
transformPen: add TransformPointPen, like TransformPen but for point pens 2019-11-28 16:29:36 +00:00
Cosimo Lupo
646e26603d
filterPen: add FilterPointPen, like FilterPen but for point pens
the base class simply passes through contours/components unchanged
2019-11-28 16:29:35 +00:00
Cosimo Lupo
3d4fb2b371
add RoundingPen, a filter pen to round coordinates and comp offsets 2019-11-27 11:01:09 +00:00
Cosimo Lupo
97fce155ad
ttGlyphPen: always round float coordinates and offsets to integers
Fixes googlefonts/fontmake#593
2019-11-26 16:16:48 +00:00
Cosimo Lupo
7c695d411f
Merge remote-tracking branch 'origin/master' into l3-instancer 2019-11-15 17:05:47 +00:00
Just van Rossum
07140c12bd
[pens] Improve error message if pen.moveTo() is omitted. (#1757)
Improve error message if pen.moveTo() is omitted. See also robotools/fontParts#470
2019-10-30 14:45:55 +01:00
Cosimo Lupo
550711e106
move MAX_F2DOT14 constant to fixedTools 2019-10-23 16:50:12 +01:00
Cosimo Lupo
d33eaaf4ca
PointToSegmentPen: preserve duplicate last point
The PointToSegmentPen translates between PointPen and (Segment)Pen
protocol.

In the SegmentPen protocol, closed contours always imply a final 'lineTo'
segment from the last oncurve point to the starting point.
So the PointToSegmentPen omits the final 'lineTo' segment for closed
contours -- unless the option 'outputImpliedClosingLine' is True
(it is False by default, and defcon.Glyph.draw method initializes the
converter pen without this option).

However, if the last oncurve point is on a "line" segment and has same
coordinates as the starting point of a closed contour, the converter pen must
always output the closing 'lineTo' explicitly (regardless of the value of the
'outputImpliedClosingLine' option) in order to disambiguate this case from
the implied closing 'lineTo'.

If it doesn't do that, a duplicate 'line' point at the end of a closed
contour gets lost in the conversion.

See https://github.com/googlefonts/fontmake/issues/572.
2019-09-10 13:05:36 +02:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Cosimo Lupo
fdb3974dd9 add identifier parameter to PointToSegmentPen.addComponent method
'identifier' param is part of the AbstractPointPen interface.
Even though it is unused by the segment pen protocol, the caller may attempt
to pass it by positional argument instead of keyword argument, e.g.
2920ddd07c/Lib/fontMath/mathGlyph.py (L486)

this patch avoids the resulting TypeError exception
2019-02-27 16:30:20 -08: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
justvanrossum
7bcb67f0cc avoid %r to eliminate unicode repr problems in the tests 2018-10-29 20:47:17 +01:00
justvanrossum
6b4a4e3087 don't use unicode literals in pointPen 2018-10-29 19:58:33 +01:00
justvanrossum
7d5530ec91 more pointpen method signature consistency fixes 2018-10-29 16:42:07 +01:00
justvanrossum
186e4615ab fix some PointPen method signatures 2018-10-29 16:23:54 +01:00
Cosimo Lupo
e871b2f41d
pointPen: add missing classes to __all__ 2018-10-18 16:12:58 +01:00
Cosimo Lupo
6b1bf4247b
move pointPen to fontTools.pens subpackage; keep ufoLib.pointPen alias 2018-10-18 16:03:09 +01: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
79449bc2d4
ttGlyphPen: always skip non-existing components
It doesn't make sense to add components that reference non-existing base glyphs
(ie. glyphs not in the input glyphSet, hence missing from the generated glyf table).
Even if we let them in here, it will fail immediately as soon as we attempt to
compile this glyf table containing 'dangling' component references.
Better to warn and skip.
2018-06-11 19:25:15 +01:00
Cosimo Lupo
ae69133924
ttGlyphPen: gracefully handle missing components while decomposing 2018-06-11 18:40:11 +01:00
Cosimo Lupo
d2ee826680
[ttGlyphPen] explain 'handleOverflowingTransforms' option in docstring
[skip ci]
2018-03-01 20:34:47 +00:00
Cosimo Lupo
4173315f09
[ttGlyphPen] rename option to 'handleOverflowingTransforms' 2018-03-01 20:17:48 +00:00
Cosimo Lupo
56be13915b
[ttGlyphPen] minor 2018-03-01 20:03:45 +00:00
Cosimo Lupo
aabc894d19
[ttGlyphPen] don't clamp to almost2 if asked to not decompose
In that case, let the struct.error do its job, no need to raise OverflowError ourselves here
2018-03-01 19:59:25 +00:00
Cosimo Lupo
acb1ebc793
[ttGlyphPen] add 'decomposeOverflowingTransform' option
if it's false and any transform value overflows, we raise an error instead of decomposing
2018-03-01 19:39:00 +00:00
Cosimo Lupo
4377185e29
[ttGlyphPen] further simplify 2018-03-01 19:15:36 +00:00
Cosimo Lupo
6606bbef3c
[ttGlyphPen] simplify 2018-03-01 18:50:45 +00:00
Cosimo Lupo
6a4ccd0e9f
[ttGlyphPen] check for out-of-range values before clamping 2018-03-01 18:00:41 +00:00
Denis Moyogo Jacquerye
098d9ecf6f
TTGlyphPen: handle scale limit
* decompose components with scale out of range [-2, 2)

* use closest F2Dot14 value when 0b1.11111111111111 < scale <= 2
2018-03-01 17:48:48 +00: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
2d4e76ff0b [bezierTools] Add calcCubicArcLength() and calcCubicArcLengthC()
Fixes https://github.com/fonttools/fonttools/issues/1142
2018-01-09 11:33:57 +01:00
Jens Kutilek
dd558f5df8 Move arc length calculations from pens.perimeterPen to misc.bezierTools 2017-11-14 13:03:58 +01:00
Cosimo Lupo
e201ea9891 [reverseContourPen] don't imply closing lineTo when same as moveTo
Previously, for closed paths, we were always dropping a lineTo segment
that followed moveTo, because after reversing the contour this lineTo
would become the last segment, and in the Pen protocol a closePath
always implies a line to the fist point.

This is OK when the move point and the following lineTo oncurve point
(which becomes last after reversal) don't overlap.

However, if they do, we ended up dropping the duplicate point.

This cu2qu issue exemplify the problem (cu2qu actually uses the
ReverseContourPointPen wrapped by ufoLib's converter pens, but
fontTools' ReverseContourPen does exactly the same):

https://github.com/googlei18n/cu2qu/issues/51

With this patch, the ReverseContourPen now emits the last lineTo
when it is the same as moveTo.
2017-10-24 19:04:38 +01:00
Cosimo Lupo
76e49d6ff5 rename SVGPen to SVGPathPen
This is to make clear that the pen deals specifically with SVG "path" element, not all SVG.
2017-10-15 15:18:35 +02:00
Khaled Hosny
2a69b4b619 I don’t think this rounding is needed 2017-10-15 14:24:14 +03:00
Khaled Hosny
0355d967a0 Add SVGPen
Copied and slightly adapted from:
https://github.com/typesupply/ufo2svg/blob/master/Lib/ufo2svg/svgPathPen.py
2017-10-15 14:24:14 +03:00
Cosimo Lupo
0df9b989be [boundsPen] add init() method to reset ControlBoundsPen
So one can reuse the same pen instance to compute the bounds of more than one glyph in a glyphset, by calling pen.init() before each glyph.draw(pen)
2017-10-13 11:49:36 +01:00
Cosimo Lupo
3f933548b8 [filterPen] clarify ContourFilterPen doesn't touch components 2017-10-12 11:16:43 +01:00
Cosimo Lupo
021de9963b [reverseContourPen] add ReverseContourPen
A filter pen that passes outline data to another pen, but reversing
the winding direction of all contours.

Like ufoLib's ReverseContourPointPen, but using segment-wise pen
interface, without additional point/segment converters, and without
ufoLib.

627f997ddb/Lib/ufoLib/pointPen.py (L327-L406)
2017-10-11 21:13:23 +01:00
Cosimo Lupo
ccf7ab3ab1 [filterPen] add ContourFilterPen
A filter pen that accumulates contour data, passes it through a
`filterContour` method as the contour is closed or ended, and
draws the result with the output pen.
2017-10-11 21:13:23 +01: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