Skip to content

Commit

Permalink
Merge pull request #231 from googlefonts/evenodd-to-nonzero-on-shapes
Browse files Browse the repository at this point in the history
allow to run evenodd_to_nonzero_winding method in isolation
  • Loading branch information
anthrotype authored Jun 4, 2021
2 parents a4a53f7 + fc5bedb commit eb65dbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/picosvg/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,11 @@ def evenodd_to_nonzero_winding(self, inplace=False):
svg.evenodd_to_nonzero_winding(inplace=True)
return svg

for shape in self.shapes():
for idx, (el, (shape,)) in enumerate(self._elements()):
if shape.fill_rule == "evenodd":
shape.remove_overlaps(inplace=True)
path = shape.as_path().remove_overlaps(inplace=True)
self._set_element(idx, el, (path,))

return self

def round_floats(self, ndigits: int, inplace=False):
Expand Down
11 changes: 11 additions & 0 deletions tests/fill-rule-evenodd-after.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions tests/svg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,17 @@ def test_tostring_pretty_print():
</svg>
"""
)


@pytest.mark.parametrize(
"actual, expected_result",
[
("fill-rule-evenodd-before.svg", "fill-rule-evenodd-after.svg"),
],
)
def test_evenodd_to_nonzero_winding(actual, expected_result):
_test(
actual,
expected_result,
lambda svg: svg.evenodd_to_nonzero_winding().round_floats(3, inplace=True),
)

0 comments on commit eb65dbe

Please sign in to comment.