57 Commits

Author SHA1 Message Date
Cosimo Lupo
5c0f05cc42
allow to pass 'round' parameter in ttGlyphPen, optimize for noRound 2023-06-08 11:41:07 +01:00
Cosimo Lupo
97e626b23e
ttGlyphPen: drop implied before rounding, allow not to round at all
We want to be able to compute implied oncurves both before coordinates have been rounded to integer and afterwards.
Also when ufo2ft builds interpolatable master TTFs, we want to turn off the rounding so that varLib can call dropImpliedOnCurvePoints on the un-rounded coordinates, so we need an option to disable rounding the coordinates in the ttGlyphPens
2023-06-07 17:55:56 +01:00
Cosimo Lupo
b6bb9dfef0
ttGlyphPen: only call dropImpliedOnCurvePoints for simple glyphs after fully formed 2023-06-02 13:53:00 +01:00
Cosimo Lupo
b7f4e9b83e
move dropImpliedOnCurvePoints function to glyf table module
so it can be used by client code on multiple glyf Glyph objects regardles of TTGlyphPen
2023-06-01 16:49:29 +01:00
Cosimo Lupo
a73abc6b87
make drop_implied_oncurves work with multiple interpolatable glyphs 2023-06-01 16:49:29 +01:00
Cosimo Lupo
3bbc19abb1
TTGlyphPen: do not error with empty contours, simply ignore them
Fixes https://github.com/googlefonts/fontmake/issues/1001
2023-05-31 11:58:14 +01:00
Behdad Esfahbod
8f89a435ac [ttGlyphPen] Rename preserveTopology to dropImpliedOnCurves 2023-02-22 09:08:39 -07:00
Behdad Esfahbod
58f9245115 [ttGlyphPen] Refactor code into function 2023-02-21 21:16:27 -07:00
Behdad Esfahbod
82e0536beb [glyf] Support cubic curves
https://github.com/harfbuzz/boring-expansion-spec/issues/41
2023-02-21 13:01:49 -07:00
Behdad Esfahbod
8427e6dd18 [ttGlyphPen] Add preserveTopology=True
If False, perform implicit-oncurve elimination.
2023-02-18 15:45:27 -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
Cosimo Lupo
934349a9c5 ttGlyphPen: handle open contours starting with 'move'; treat them as if they were closed
Fixes #2365
2021-07-15 18:25:19 +01:00
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