45 Commits

Author SHA1 Message Date
Cosimo Lupo
c995411a60 leave self.glyphSet alone 2021-05-20 14:03:56 +01:00
Cosimo Lupo
1d9f267ad5 make glyphSet required.. but Optional :) 2021-05-20 13:20:45 +01:00
Cosimo Lupo
d4408baf70 ttGlyphPen: fix typing annotation for glyphSet parameter
It is an optional dictionary. Even the ttGlypgPen_test.py or the fontBuilder.py calls TTGlyphPen(None) often.
We caught this because internally we run a type-checker. Originally the glyphSet parameter was not explicitly typed.
Now that it is, make the type hints match the way code is intended to be used.
2021-05-20 12:33:58 +01:00
Cosimo Lupo
d0bcae94dd ttGlyphPen: run black 2021-05-20 12:30:08 +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
Behdad Esfahbod
abc1ba07a4 [misc.roundTools] New module; move otRound() here
Code relying on old place (fixedTools.otRound) still works.
2021-03-04 09:20:43 -07:00
Nikolaus Waxweiler
f6a62e0db1
Merge pull request #2164 from fonttools/pen-maintenance
Pen maintenance
2021-02-22 10:26:39 +00:00
Nikolaus Waxweiler
f7546baf00 Complete implementation of TTGlyphPen 2021-02-21 10:20:59 +00:00
Simon Cozens
9cb126b10a Document expected arguments for _TTGlyphSet, _TTGlyph and TTGlyphPen 2021-02-08 11:30:39 +00:00
Nikolaus Waxweiler
a3acb1426b Remove py23 import 2021-01-29 22:23:27 +00: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
97fce155ad
ttGlyphPen: always round float coordinates and offsets to integers
Fixes googlefonts/fontmake#593
2019-11-26 16:16:48 +00:00
Cosimo Lupo
550711e106
move MAX_F2DOT14 constant to fixedTools 2019-10-23 16:50:12 +01:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +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
Behdad Esfahbod
f3bfea12c6 Add __all__ to pens that didn't have it 2017-02-21 12:01:10 -06:00
Cosimo Lupo
9b83c377c2 [ttGlyphPen] only add empty ttProgram to simple glyphs, not to composites
Unlike simple glyphs (with contours) which must always have `instructionLength`, the field is optional in composite glyphs and depends on whether `WE_HAVE_INSTR` flag is set:
https://www.microsoft.com/typography/otspec/glyf.htm

In the previous code, the TTGlyphPen was adding an empty `program` attribute to any new glyph, including composite glyphs. It should only do it for simple glyphs.

For example, if you take Roboto-Regular.ttf from here:
https://github.com/google/roboto/releases/tag/v2.129

The font (unhinted) was compiled using the ttGlyphPen. It has 1434 composite glyphs. For each of them, a USHORT value for the number of instructions (0) is written, so the binary ttf is 2.868 KB greater than
what it should be.
2016-03-11 10:53:41 +00:00
Cosimo Lupo
87d13888ce [ttGlyphPen] check last point in qCurveTo is not None
otherwise, if points[-1] == 0, the on-curve point won't be added.
2016-03-09 17:58:48 +00:00
James Godfrey-Kittle
fd5b6de3ba [TTGlyphPen] Add component flags argument 2016-03-07 14:48:46 -08:00
James Godfrey-Kittle
f02e771527 [TTGlyphPen] Don't cast values to int
The glyf table will handle rounding when compiling, so this is
unnecessary.
2016-02-16 17:17:14 -08:00
James Godfrey-Kittle
45e496fdb8 [TTGlyphPen] Use bytes for array.array for python3 2015-11-06 11:50:39 -08:00
James Godfrey-Kittle
9ff7d62454 [TTGlyphPen] Do special case ignoring anchors
This fixes the ignoring anchors test, which led me to believe we
didn't need to special case them (which we do, and now are).
2015-11-05 15:28:19 -08:00
James Godfrey-Kittle
6dc5092e2b [TTGlyphPen] Move some code around
No effective differences, just lingering un-committed local changes.
2015-11-05 15:19:53 -08:00
James Godfrey-Kittle
0b3b83f765 [TTGlyphPen] Don't special case ignoring anchors
There's no need to special case this, it happens anyways.
2015-11-05 15:12:18 -08:00
James Godfrey-Kittle
b511b2b0d8 [TTGlyphPen] Go back to using AbstractPen
Using BasePen breaks on quadratic splines, since there's no way to
know if a on-curve point was added by the pen or in the original
glyph. Should have considered this before....
2015-11-05 13:57:53 -08:00
James Godfrey-Kittle
7767683ea4 [TTGlyphPen] Abstract out a _popPoint method 2015-11-05 13:57:06 -08:00
James Godfrey-Kittle
9f5c51897c [TTGlyphPen] Move checks for closed contours
We probably don't want to raise errors in init, which allows a drawer
to reset the pen state.
2015-11-05 13:54:51 -08:00
James Godfrey-Kittle
fa82fcd213 [TTGlyphPen] Make components with correct defaults
This seems consistent with what one sees opening up an existing TTF.
2015-11-04 17:59:57 -08:00
James Godfrey-Kittle
8c61d08d94 [TTGlyphPen] Remove last point in closed contours
When a pen adds the first point to a contour at the end to close it,
we should remove it for the TrueType outline.
2015-11-04 17:58:27 -08:00
James Godfrey-Kittle
1c73a1942a Don't use lineTo in moveTo
It shouldn't make a difference, but semantically this is now correct.
2015-11-04 17:21:17 -08:00
James Godfrey-Kittle
b83ed7ab2b Allow a TTGlyph pen to be used more than once 2015-11-04 17:19:58 -08:00
James Godfrey-Kittle
58dd55c0ae Use BasePen instead of AbstractPen in TTGlyphPen 2015-11-04 17:18:03 -08:00
James Godfrey-Kittle
8b4c3b7892 Add assertion and comments to ttGlyphPen 2015-10-06 09:14:04 -07:00
James Godfrey-Kittle
b916c5bb93 ttGlyphPen: handle qcurves with no on-curve points 2015-10-06 09:12:15 -07:00
James Godfrey-Kittle
b0c03b86d6 Add pen which draws to TrueType glyphs. 2015-10-01 15:12:20 -07:00