Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TypeError when converting pathops.Path to svg #305

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

anthrotype
Copy link
Member

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.

Fixes #304
Fixes googlefonts/nanoemoji#455
Fixes googlefonts/noto-emoji#429

since skia-pathops v0.8.0, the Path.segments (SegmentPenIterator) may yield segments with an on-curve point set to None when closed contour is only comprised of quadratic beziers and all the on-curve points can be implied as in-between consecutive off-curve points (special TrueType quadratic spline), this was to match FontTools pen protocol, which the SegmentPenIterator is supposed to work with.
Picosvg was using this interface for converting from pathops.Path to SVG path.d strings, and uncaught TypeError was being raised when that happened. However, it turns out picosvg can avoid the SegmentPenIterator altogether when converting from pathops.Path to SVG, because the Path's RawPathIterator (i.e. iterating over the path itself as opposed to Path.segments) already yields (verb, points) for individual segment that matches what SVG expects (in this particular case, a move, a list of quadratic bezier segments each with one off-curve point, and a close command, no fonttools-style implied points anywhere). This way we can translate between SVG<=>pathops.Path in a more straightforward way (since they are closed to one another than to fonttools pen protocol more geared to font format specifics).
@anthrotype anthrotype merged commit 2c304b5 into main Aug 4, 2023
6 checks passed
@anthrotype anthrotype deleted the fix-pathops-to-svg branch August 4, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant