typst
typst copied to clipboard
Add parameter of "evenodd" fill-rule to `path` function
Description
In the document of path
function, there is a following paragraph:
Currently all paths are filled according to the non-zero winding rule.
However in SVG specification,two fill-rules nonzero and evenodd are supported. And the default value of fill-rule is nonzero.
Consider the two following SVG files, with different fill-rules:
nonzero.svg
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
<polygon fill-rule="nonzero" stroke="red" points="50,0 21,90 98,35 2,35 79,90"/>
</svg>
evenodd.svg
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100" viewBox="0 0 100 100">
<polygon fill-rule="evenodd" stroke="red" points="50,0 21,90 98,35 2,35 79,90"/>
</svg>
Import them to a Typst file and the output result shows as below:
Use Case
It would be nice if there is an "evenodd" fill-rule in path
function, which is more consistent with the behavior of the SVG. And higher-level drawing packages like CeTZ
would benefit from this.