SVG icon indicating copy to clipboard operation
SVG copied to clipboard

Masks not rendered properly

Open thibnes opened this issue 6 years ago • 6 comments

Using this file as example testSvgMasks.zip

the generated jpeg looks like this output

Is there a special setup to handle masks?

thibnes avatar Jun 06 '19 13:06 thibnes

I will have a look later, but this is most certainly not supported or a bug.

mrbean-bremen avatar Jun 06 '19 14:06 mrbean-bremen

Yes, masks are unsupported - the related W3C examples also fail. There is an empty class SvgMask, so I guess an implementation has been considered some time... So I think you are out of luck here, as I doubt that mask implementation is something trivial enough to be added soon.

mrbean-bremen avatar Jun 06 '19 18:06 mrbean-bremen

Yes, masks are unsupported - the related W3C examples also fail. There is an empty class SvgMask, so I guess an implementation has been considered some time... So I think you are out of luck here, as I doubt that mask implementation is something trivial enough to be added soon.

Alright, thank you for your quick response.

thibnes avatar Jun 06 '19 19:06 thibnes

I found a simple workaround, for anyone interested. To get masks to atleast be written into the .svg files, create a class like this:

[SvgElement("mask")] public class SvgMask2 : SvgMask { } And use that instead of SvgMask. Remember to give it an ID so you can reference it later.

And to make a SvgElement use the said mask, simply add a custom attribute to it, using the ID you gave the mask: element.CustomAttributes.Add("mask", "url(#maskID)");

This will obviously not render when converting to bitmap, but it won't throw an error either. Useful if all you care about is the .svg file.

Zakkon avatar Jun 19 '19 18:06 Zakkon

Yes, I also added the attribute to the (empty) SvgMask class, and this fixes at least the writing (though not the functionality, of course). I thought it not worth a separate commit without the mask working, but that was obviously wrong. I will add this tomorrow.

mrbean-bremen avatar Jun 19 '19 21:06 mrbean-bremen

@Zakkon: Thanks for the hint, I committed the change now!

mrbean-bremen avatar Jun 20 '19 19:06 mrbean-bremen