fix TypeError when converting pathops.Path to svg #305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #304
Fixes googlefonts/nanoemoji#455
Fixes googlefonts/noto-emoji#429
since skia-pathops v0.8.0, the Path.segments (aka SegmentPenIterator) may yield segments where the on-curve point is set to None, which happens when a closed contour is only comprised of quadratic beziers and all the on-curve points can be implied as in-between consecutive off-curve points (i.e. special TrueType quadratic spline). This was to match FontTools pen protocol, which the SegmentPenIterator is supposed to work with, allowing to round-trip these oncurve-less contours through pathops.
Picosvg happens to be using this Path.segments interface when converting from pathops.Path to SVG path.d strings, and an uncaught TypeError was being raised when that happened. However, it turns out that picosvg can avoid using the SegmentPenIterator altogether when converting from pathops.Path to SVG, because the Path's
RawPathIterator
(i.e. used for iterating over the Path itself, as opposed to its Path.segments) already yields (verb, points) for individual curve segments that match what SVG expects: in this particular case, an explicit move, a list of quadratic bezier segments each with one off-curve point, and a close command, and no fonttools-style None-implied points.This way we can translate between SVG<=>pathops.Path in a more straightforward way, since they are closer to one another than to fonttools pen protocol, more geared towards font format specifics.