drawbot icon indicating copy to clipboard operation
drawbot copied to clipboard

Support SVG in image()

Open Lorp opened this issue 7 years ago • 9 comments

Any chance that SVG images can be supported in the image() function?

Lorp avatar Nov 13 '18 14:11 Lorp

The problem was always that SVG is not directly supported at the Quartz level. Not sure whether that situation has improved with 10.13 or 10.14.

justvanrossum avatar Nov 13 '18 14:11 justvanrossum

I’ve managed to use Simple SVG Parser some time ago to create a custom pen to convert flat SVGs into glyphs. the same could work for DrawBot if we add support for colors…

gferreira avatar Nov 13 '18 15:11 gferreira

in cocoa a WebKit htmlView can render a svg, convert that to a pdf and use that data in an image. This feels like a big detour ;)

typemytype avatar Nov 13 '18 15:11 typemytype

ok, goed to know. but in the meantime, the detour works :)

screen shot 2018-11-13 at 14 20 09

gferreira avatar Nov 13 '18 16:11 gferreira

oh cool could you post this on the drawbot forum?

thanks

typemytype avatar Nov 13 '18 16:11 typemytype

I’ve started to convert my quick & dirty example into a more useful conversion ~~tool~~ helper, separating parsing from drawing. (still a work in progress)

I’ve tested it with different SVGs, and not all of them work: simple_svg_parser supports only px as units, so an error is raised for SVGs which have % or cm as units.

there also seems to be a problem with shapes which have a stroke but no fill (I guess it needs to be set to None explicitly, because the default fill is black in DB). for example, this is what I get when trying to draw the GhostScript Tiger:

screen shot 2018-11-15 at 09 09 07

btw thanks @typemytype for the feedback on the current code – I will be making some changes soon!

gferreira avatar Nov 15 '18 11:11 gferreira

I'm a little skeptical about building a full SVG parser like that from scratch. Basic SVG is simple, but the full spec is huge and complex, with masking, reuse of objects, transformations, external references, embedded CSS and and and... And those are only the things which immediately spring to mind.

If the detour via an HTML view and PDF can work reliably, I think that's the better route, as then at least the PDF data is built natively.

justvanrossum avatar Nov 15 '18 13:11 justvanrossum

@justvanrossum I agree. this is meant only as a helper to get things done today. a bird in the hand…

gferreira avatar Nov 15 '18 14:11 gferreira

Good discussion, thanks for the explanations and workaround.

Lorp avatar Nov 15 '18 17:11 Lorp