44 Commits

Author SHA1 Message Date
Cosimo Lupo
0dc2a2a13f ttGlyphPen: test that open contours work with TTGlyphPen
currently this fails with NotImplementedError. Fix will follow in subsequent commit
2021-07-15 18:19:46 +01:00
Jens Kutilek
0cb2bea386
Add TTGlyphPointPen (#2205)
* Add TTGlyphPointPen
* Format code with black
* Implement TTGlyphPen and TTGlyphPointPen with common base class
* Use PenError instead of assert
* Add note about decomposing mixed composites to the docstring
2021-05-17 14:09:36 +02:00
Just van Rossum
5fc65d7168
Misc py23 cleanups (#2243)
* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
2021-03-29 11:45:58 +02:00
justvanrossum
2429a187fc Revert ABC changes to Pens, fixes #2198 2021-02-26 20:18:37 +01:00
Nikolaus Waxweiler
839c57a50d Remove some Python 2 vestiges from pen tests 2021-02-21 10:30:17 +00:00
Nikolaus Waxweiler
ab1883da1d Turn AbstractPen and AbstractPointPen into ABCs plus typing 2021-02-21 10:20:37 +00:00
Antonio Cavedoni
742983f087 Add QuartzPen 2020-11-20 12:38:43 +01:00
Jens Kutilek
b9c268943a
Add HashPointPen from psautohint (#2005)
* Add HashPointPen from psautohint (with changes)
* Decompose components
* Use format string and disambiguate critical changes
* Remove "getHash()" in favour of "hash" property
* Add transformation for composites
* Omit base glyph name from component hash
* Use untransformed coords for components
* Add tests
* Add example code

Co-authored-by: Cosimo Lupo <cosimo@anthrotype.com>
2020-10-22 11:16:24 +02:00
Cosimo Lupo
5c0d6f2a3e
Move test fonts to Tests/cu2qu/data 2020-04-01 18:59:35 +01:00
Cosimo Lupo
0782b4e4cf
cu2qu: Add missing Apache 2.0 header and copyright notice 2020-03-31 17:09:26 +01:00
Cosimo Lupo
c2e8403937
cu2qu: remove from __future__ imports 2020-03-31 13:38:51 +01:00
Cosimo Lupo
00058833f2
Move cu2qu.pens to fontTools.pens.cu2quPen 2020-03-31 13:34:46 +01:00
Cosimo Lupo
b6467b7e85
ttGlyphPen: quantize component.transform to F2Dot14 to fix issue with bbox
Fixes https://github.com/googlefonts/fontmake/issues/558

When drawing a composite glyph with a scaled component using the TTGlyphPen, the bounding
box coordinates may change depending on whether one computes them *before* compiling or
*after* decompiling. Before compiling, component.transform holds double precision floats,
but after compiling and decompiling, these are necessarily clamped to F2Dot14 fixed precision.

The TTGlyphPen needs to quantize transform floats to F2Dot14 so that the values don't
change after compilation.

Without this change, it may happen that round-tripping fonts through ttx (which by default
recalcBBoxes) will produce different bounding boxes for composite glyphs that have
scaled or transformed components.
2020-02-13 13:49:01 +00:00
Cosimo Lupo
ae5212f76b
add tests for RecordingPointPen 2019-11-28 16:32:40 +00:00
Cosimo Lupo
7fe59e4b94
ttGlyphPen_test: test computing bounds with float coordinates and offsets
https://github.com/googlefonts/fontmake/issues/593

This test currently fails. The compositeGlyph.xMax is set to 281, but it should be 282.
2019-11-26 16:03:18 +00: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
justvanrossum
7bcb67f0cc avoid %r to eliminate unicode repr problems in the tests 2018-10-29 20:47:17 +01:00
justvanrossum
c9d4b65fd4 add some component tests 2018-10-29 19:54:52 +01:00
justvanrossum
b5b8a776fe one more identifier test 2018-10-29 19:45:06 +01:00
justvanrossum
25f3dbfb85 test identifier kwarg behavior 2018-10-29 19:43:27 +01:00
justvanrossum
f8ff962490 added some point pen tests 2018-10-29 19:37:50 +01:00
Cosimo Lupo
176b5f763d
change 'import ufoLib' to 'import fontTools.ufoLib' 2018-10-17 17:43:28 +01:00
Cosimo Lupo
0337fc92fc
Tests: adjust to use new otRound function 2018-06-14 17:49:37 +01:00
Cosimo Lupo
ae69133924
ttGlyphPen: gracefully handle missing components while decomposing 2018-06-11 18:40:11 +01:00
Cosimo Lupo
4173315f09
[ttGlyphPen] rename option to 'handleOverflowingTransforms' 2018-03-01 20:17:48 +00:00
Cosimo Lupo
6ce8eec89c
[ttGlyphPen_test] add test for decomposeOverflowingTransform=False 2018-03-01 20:10:32 +00:00
Cosimo Lupo
08c663f798
[ttGlyphPen_test] remove OverflowError test 2018-03-01 19:59:49 +00:00
Cosimo Lupo
4771e7cd6c
[ttGlyphPen_test] add test for OverflowError 2018-03-01 19:41:40 +00:00
Cosimo Lupo
ede35d72c8
[ttGlyphPen_test] test decomposed contours keep original order 2018-03-01 18:52:55 +00:00
Cosimo Lupo
778d4933da
[ttGlyphPen_test] check ambiguous out-of-range case
that has both a value that exceeds the bounds, and one that's almost 2;
the former case should take precedence and the componed be decomposed
2018-03-01 18:01:01 +00:00
Denis Moyogo Jacquerye
85e363c216
Add TTGlyphPen test for scale limits 2018-03-01 17:48:49 +00:00
Cosimo Lupo
faedfacbae [reverseContourPen_test] fix expected result for ReverseContourPointPen
This test is not normally run. It is skipped when ufoLib is not importable,
as it's the case from the test runner's virtual environment.

The only reason it exists is so that I could check that the
ReverseContourPen I was writing behaves the same as using ufoLib's
ReverseContourPointPen when the latter is run through the
SegmentToPointPen and PointToSegmentPen converters.

The two methods for reversing contours now diverge since
https://github.com/fonttools/fonttools/pull/1080,
but only nominally because both produce effectively the same results.
The only difference is that, when using the point pens with
outputImpliedClosingLine=True, the closing lineTo is always there even
when it's redundant. In our implmentation, we only output the closing
lineTo when it is the same as moveTo (this was necessary in order to
fix https://github.com/googlei18n/cu2qu/issues/51)
Nevertheless, the total number of points is the same in both cases.

Maybe this test should not be here, as it's testing functionalities
from a different package.

Closes https://github.com/fonttools/fonttools/issues/1081
2017-10-25 11:18:35 +01:00
Cosimo Lupo
1ef034c385 use outputImpliedClosingLine=True with ReverseContourPointPen
One way to work around https://github.com/googlei18n/cu2qu/issues/51
when using the ufoLib's ReverseConturPointPen via the converter pens
would be to pass the outputImpliedClosingLine=True argument
(False by default) to the PointToSegmentPen.

This way, all the final lineTos are explicitly outputted, even when
they are redundant and could be implied (i.e. when they are not
duplicate points).

Note that this test is skipped by the CI, because ufoLib is not a
dependency of fonttools; you can run locally if you wish.
2017-10-24 19:20:44 +01:00
Cosimo Lupo
0a22639ed3 [reverseContourPen_test] add test case from cu2qu#51
https://github.com/googlei18n/cu2qu/issues/51#issue-179370514a
2017-10-24 19:04:38 +01:00
Cosimo Lupo
d316ebebbb [reverseContourPen_test] keep duplicate point in expected result 2017-10-24 18:14:22 +01:00
Cosimo Lupo
3bbba21f1f [reverseContourPen_test] unit tests for ReverseContourPen
For comparison, I also include tests for the ufoLib pen.
They are skipped if ufoLib is not importable.
2017-10-11 21:13:23 +01:00
Miguel Sousa
2d02c54d1a [t2CharStringPen_test] Update test results 2017-05-06 00:11:27 -07:00
Cosimo Lupo
0690634eb1
[t2CharStringPen_test] add test for horizontal _relativeMoveTo (hmoveto) 2017-04-28 15:36:42 +01:00
Miguel Sousa
86b820ad0d [t2CharStringPen] Update tests 2017-04-28 03:27:42 -07:00
Cosimo Lupo
3e70daa206
[basePen_test] add test for missing component skipped 2017-04-13 14:22:40 +01:00
Cosimo Lupo
78212239aa
[recordingPen_test] test recording component references as well as decomposed paths 2017-04-13 14:22:40 +01:00
Cosimo Lupo
3cdc800873
[Tests] rename all 'testdata' folders to simply 'data'
as it's now obvious what kind of data they are
2017-01-17 13:33:46 +00:00
Cosimo Lupo
78ad48eaf3
Move all *_test.py modules and test data to external Tests/ folder 2017-01-16 09:14:12 +00:00