treeform / pixie

Full-featured 2d graphics library for Nim.
MIT License
741 stars 28 forks source link

Pixie SVG does not support clipPath #301

Open 1jss opened 2 years ago

1jss commented 2 years ago

I was trying to draw one of my SVGs, but got the following error:

Error: unhandled exception: Unsupported SVG tag: clipPath [PixieError]

Simple test image that generates the error:

<?xml version="1.0" encoding="UTF-8"?>
<svg clip-rule="evenodd" fill-rule="evenodd" version="1.1" viewBox="0 0 140 140" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<rect x="20" y="20" width="100" height="100"/>
<clipPath id="a">
 <rect x="20" y="20" width="100" height="100"/>
</clipPath>
<g clip-path="url(#a)">
 <rect x="40" y="40" width="100" height="100" fill="#f00"/>
</g></svg>

I don't know if the current plan is to use Cairo for SVGs, but I thought I would create an issue anyways.

How hard would it be implementing clipPath given that we already have masks in the drawing library?

guzba commented 2 years ago

SVG is impossibly complex unfortunately, we certainly do not support everything. This looks like one of the tags we do not support yet. I add support for more things every now and then as I find SVG examples of them. I don't think clipPath would be particularly difficult to add fortunately.

1jss commented 2 years ago

Definitely! You guys are heroes for building this!

I have read the svg.nim to figure out how it was built, but I haven't understood it well enough yet to try to implement clipPath myself. Will try to wrap my head around it and give it a go.

guzba commented 2 years ago

No problem. The svg.nim file is certainly not the cleanest file we have since SVG is always in-flux, hard to clean up something always getting more complicated haha. If you do manage a PR that'd be great, otherwise it is something I can work on next time I do SVG work.