64 Commits

Author SHA1 Message Date
Behdad Esfahbod
78a939848f [Cu2QuMultiPen] Add tests and fix a but
Fixes https://github.com/fonttools/fonttools/issues/2926
2022-12-13 11:28:33 -07:00
Behdad Esfahbod
78e10d8b42 [ttGlyphPen] Add outputImpliedClosingLine argument
Fixes https://github.com/fonttools/fonttools/issues/2913
2022-12-12 09:53:59 -07:00
Behdad Esfahbod
ddbbef2257 [reverseContourPen] Add outputImpliedClosingLine
Fixes https://github.com/fonttools/fonttools/issues/2914
2022-12-12 09:49:06 -07:00
Just van Rossum
d5db47e09d minor cleanup 2022-08-30 08:49:36 +02:00
Just van Rossum
b818e1494f Refactor ttGlyphSet.py
- only differentiate between glyf and CFF/CFF2 implementations, not var vs non-var
- use collections.abc.Mapping to get a more consistent dict-like object with less code
- prefer HVAR metrics over gvar metrics
- move some responsibilities from the _TTGlyphSet objects to the _TTGlyph objects
- adjust some tests to the changes
2022-08-30 08:49:36 +02:00
Cosimo Lupo
14f88fb781 Fix cu2quPen_test.py for python 3.11
Credits to pnamade from https://github.com/fonttools/fonttools/pull/2655
2022-07-06 11:16:02 +01:00
Takaaki Fuji
5f2c492635 freetypePen: format code with Black 2022-01-31 20:56:03 +09:00
Takaaki Fuji
a27789c477 freetypePen: handle rotate/skew transform
The pen is designed to determine the bitmap size when omitted, which
helps users to see an image somehow even when they have no idea how the
arguments should be passed. And I realised that I didn't give enough
thought to rotate/skew transforms in former PRs. This commit fixes the
calculation of the bbox after transformation. Also tries to clear up how
the autosizing options work in the docstring.

Some minor fixes will follow.
2022-01-31 18:08:51 +09:00
Takaaki Fuji
f87f75a437 Replace base64-encoded images with PGM files
Surprisingly I found Preview.app can still display PGM images. While
somewhat legacy, it's a super straightforward format to (de)serialize.
The images are scaled to 50x50 px and only consume 5KB in total. Makes
more sense to human being than the previous base64-encoded zlib
compressed data, plus we don't have to add pillow as a dependency.
2022-01-12 01:09:15 +09:00
Takaaki Fuji
072b4c8db0 Fit to contents when image size omitted
Eliminates the assumption of any specific metrics from the pen. It still
gives some image without giving any parameters, thus it should be a good
starting point for new users.
2022-01-11 23:02:37 +09:00
Takaaki Fuji
6f7ef4a838 Prefer single transform matrix over offset/scale 2022-01-11 23:02:37 +09:00
Takaaki Fuji
42bc1257b4 Add reference for PSNR 2022-01-11 02:26:05 +09:00
Takaaki Fuji
d399e93d95 Rename even_odd to evenOdd
PointInsidePen already uses camelCase convention for the argument.
2022-01-11 01:42:05 +09:00
Takaaki Fuji
2c0ab2a05a Relax assertions for rendering tests
There are possibilities that the rendering results may change among
FreeType versions. I've already used the PSNR comparison for cubic
vs quadratic testing, so I applied the same technique and threshold to
all rendering tests to relax assertions. Also handles the case that
MSE becomes zero. Optional dependencies are not needed for the tests.
2022-01-11 01:42:05 +09:00
Takaaki Fuji
0e880260ae Remove unnecessary import in test 2022-01-11 01:41:43 +09:00
Takaaki Fuji
d0dbbbd3c8 Rename to freetypePen/FreeTypePen 2022-01-10 23:51:28 +09:00
Takaaki Fuji
f7c29e89be Change arguments for positioning and dimension
After experimenting with uharfbuzz for a while, I found out it was hard
to handle top-to-bottom texts, so I gave up an idea to put an ascender
or a descender value in the arguments. Instead, I simply expose 'offset',
'width' and 'height', which is way more straightforward than the
previous design.

In addition, 'contain' option is added to easily compensate and render
glyphs such as combining accents or excessively tall letters.
2022-01-07 22:29:01 +09:00
Takaaki Fuji
10a3ca8ea5 Use freetype-py instead
I didn't expect that the PyPI package contains the pre-built binary
for each platform. Skip the test when freetype-py is not avaiable.
2022-01-06 19:07:26 +09:00
Takaaki Fuji
46c580f00b Fix import in unit test 2022-01-06 18:18:42 +09:00
Takaaki Fuji
e2fad4db11 Add FreeType-based Pen for rasterisation 2022-01-06 09:00:53 +09:00
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