Imported 9b7ecb4 from fontPens, which is the version modified to accept
a parameterized tolerance. Recent changes in fontTools such as 2831096,
186e461 and 7d5530e were considered so that the diff will be minimal.
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
* 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
* 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>
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.
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.
'identifier' param is part of the AbstractPointPen interface.
Even though it is unused by the segment pen protocol, the caller may attempt
to pass it by positional argument instead of keyword argument, e.g.
2920ddd07c/Lib/fontMath/mathGlyph.py (L486)
this patch avoids the resulting TypeError exception
Fix syntax error reported by build system: can't mix string string types when doing literal concatenation
Fix local import reference - doesn't work in Python3.
Addressed issues raised by @msousa for PR 1345 yesterday.
Will change cff2_merge_funcs.py and cff2mergePen.py from tab to space indentations after the current comments are resolved.
Add various improvements from comments:
- do not edit the post table under varLib.build(). Setting post table format 2 or 3 is now expected to be managed by whatever calls varLib.build().
- In the t2CharStringPen module, rename closure _round() nested in makeRoundFunc to an exportable function, and use it in cff2mergePen.
- remove TypeSupply copyright from cff2mergePen.
- use modulo function to convert float to int when it is meant to be 0 in cff2mergePen.
cff2_merge_funcs.py:merge_PrivateDicts() should only be blending the hint related fields in the PrivateDict. This oversight that was surfaced by @madig reporting an error building his Cantrell font. The bug appeared when the font was subroutinized, as the pen draw method then has to interpret the Subr field in order to access T2Charstring subroutines.
Fix expected ttx output file. When I removed the logic to add glyph names to the post table, glyph names in the ttx file changed.
Miguel prefers a simple list for readability in cff2_merge_funs.py:138.