165 Commits

Author SHA1 Message Date
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
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
b4827ae965 Add recordingPen.replayRecording 2017-04-20 14:54:13 -07:00
Cosimo Lupo
94c88f56cb
[recordingPen] add DecomposingRecordingPen
Uses the DecomposingPen as mixin, and raise KeyError on missing glyphs

See https://github.com/fonttools/fonttools/pull/880#issuecomment-288558012
2017-04-13 14:22:39 +01:00
Cosimo Lupo
b438dbeee5
[basePen] add LoggingPen and DecomposingPen, subclass BasePen from DecomposingPen
This is so we can reuse addComponent with the recording pen, without having to
inherit from the BasePen (which also splits curveTo and qCurveTo commands).

Log warning message on missing glyphs by default, optionally raise KeyError
if skipMissingComponents = False
2017-04-13 14:22:29 +01:00
Cosimo Lupo
980ac7d415
[transformPen] use FilterPen as the base class instead of AbstractPen 2017-04-12 14:17:15 +01:00
Cosimo Lupo
107bf48ffe
[filterPen] add FilterPen base class
Can be useful for others, e.g.:
https://github.com/googlei18n/ufo2ft/issues/120#issuecomment-288503784
2017-04-12 14:17:15 +01:00
Adrien Tétar
a03eb1137b pens: add a wx pen 2017-04-07 20:50:20 +02:00
Miguel Sousa
e2d4fe9da8 minor 2017-03-17 07:48:22 -07:00
Miguel Sousa
4de5af36cb Add usage example of RecordingPen 2017-03-17 02:19:12 -07:00
Behdad Esfahbod
c2033cb095 Document new pens 2017-02-26 10:41:11 -08:00
Behdad Esfahbod
19ab2c96cc Fix typo
Who knew __all__ does not actually hide symbols not listed from
importing by name?
2017-02-26 10:33:58 -08:00
Behdad Esfahbod
a02a429573 [StatisticsPen] Some more (probably over-) optimization 2017-02-24 15:20:38 -08:00
Behdad Esfahbod
8335af0d1d [statisticsPen] Micro-optimize 2017-02-24 14:06:58 -08:00
Behdad Esfahbod
8879318c0b Move RecordingPen to fontTools.pens.recordingPen 2017-02-21 12:11:36 -06:00
Behdad Esfahbod
55e529f7a3 Add fontTools.pens.teePen 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
6face10ca3 [basePen] Default glyphset to None 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
f3bfea12c6 Add __all__ to pens that didn't have it 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
69f38605d1 [transformPen] Minor 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
14b46cf7a6 [symfont] Move symfont to fontTools.misc.symfont 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
621759b3a8 [symfont] Add endPath() 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
d8e8a657fa [areaPen] Remove unnecessary docstrings 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
821ea7385f Minor 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
0a2c5ef7ae [symfont] Write generator code as main function in printPen() output 2017-02-21 12:01:10 -06:00
Behdad Esfahbod
f3224d7d34 Move StatisticsPen into fontTools.pens.statisticsPen 2017-02-20 13:19:35 -06:00
Behdad Esfahbod
a8db22a077 Move MomentsPen into fontTools.pens.momentsPen 2017-02-20 12:33:12 -06:00
Behdad Esfahbod
8712c20156 [perimeterPen] Use Gauss-Legendre instead of Lobatto-Gauss for qudratic
Uses one fewer point and is no uglier.
2017-02-20 11:16:12 -06:00
Behdad Esfahbod
6738305fb1 [perimeterPoint] Minor 2017-02-20 11:09:14 -06:00
Behdad Esfahbod
3d4bd76a76 [perimeterPen] Add Gauss-Lobatto implementation for quadratic Bezier as well
Is twice faster than the exact algorithm.
2017-02-20 10:17:07 -06:00
Behdad Esfahbod
9f1067a991 [perimeterPen] Optimize Lobatto code 2017-02-20 10:17:07 -06:00
Cosimo Lupo
a226c4772b
[perimeterPen] move source encoding declaration to the first line
Otherwise I get this error on python2.7:

SyntaxError: Non-ASCII character '\xc2' in file perimeterPen.py on line 87, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
2017-02-19 20:08:57 -08:00
Behdad Esfahbod
3e74798499 [perimeterPen] Add Gauss-Lobatto quadrature approximation implementation
Is about 30 percent faster than recursive approach for the default .005
error tolerance.  To be optimized more.
2017-02-19 16:08:21 -06:00
Cosimo Lupo
78ad48eaf3
Move all *_test.py modules and test data to external Tests/ folder 2017-01-16 09:14:12 +00:00