fonttools / skia-pathops

Python bindings for the Skia library's Path Ops
https://skia.org/docs/dev/present/pathops/
BSD 3-Clause "New" or "Revised" License
47 stars 14 forks source link

should pathops keep the original contour direction? #30

Closed anthrotype closed 3 years ago

anthrotype commented 3 years ago

Right now, by default, we always set the outermost contours' direction to counter-clockwise (i.e. whenever fix_winding=True, which is the default). There is no way in the public pathops Python API to set the inverse clockwise direction. winding_from_even_odd function (called when fix_winding is True) has a truetype=False parameter (that would make it use clockwise as the desired result's direction), however that option is not exposed at the top-level (e.g. in simplify or op methods).

I am adding a removeOverlaps module to fontTools to merge overlapping paths from TTFs (to be used as an optional feature of the varLib.instancer). TrueType fonts usually use clockwise as the outermost (black) path direction. I don't want to change all glyphs when removing overlaps just because pathops doesn't let me choose the result's direction.

Ideally, in all the public methods where we have a fix_winding option (ie. simplify, op, and the various named boolean ops), before we run the underlying Skia operation, we save the current path's direction (it's clockwise if path.area < 0), and then pass that one to winding_from_even_odd.

This way, skia-pathops would "remember" and keep the current path direction, instead of always setting the result's direction to counter-clockwise as it does now.

This would be a breaking change however, which is why I am opening this issue to gather comments before I go on and apply this change.

Another solution would be to expose a way to set the destination path's direction (make that truetype parameter settable from the public methods somehow, maybe as a new direction parameter), so the client can choose which direction (whether CW, CCW or whatever the original direction was).

behdad commented 3 years ago

This is great. Having reliable removeOverlaps in fonttools is quite empowering. Thank you Cosimo!