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
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.
* 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
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.
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.
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.
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....