revery-ui / revery

:zap: Native, high-performance, cross-platform desktop apps - built with Reason!
https://www.outrunlabs.com/revery/
MIT License
8.06k stars 196 forks source link

Ability to render SVG files #569

Open kyldvs opened 4 years ago

kyldvs commented 4 years ago

Would really like this feature, there are some nice SVG files I'd like to use but I'm having to convert them to png instead.

bryphe commented 4 years ago

Ah ya, sorry @kyldvs - this is a major pain point at the moment!

Our work to integrate Skia (#567) will help here, as Skia has support for loading and rendering SVGs.

kyldvs commented 4 years ago

@bryphe now that Skia is in, is there an example of using SVG files? or do you have pointers about how I can try setting it up?

Et7f3 commented 4 years ago

We need to create some module like Svg that define line, rect and cie. With the JSX syntax it will mean SVG has reason 🙂 (maybe not the header)

bryphe commented 4 years ago

Ya, unfortunately I was mistaken - SVG loading is not built-in to Skia (although it provides all the drawing primitives we need to render them).

Flutter and Skiasharp actually have similar issues:

What we could do is bring in an XML parser (or a specific SVG one, like TyXml: http://ocsigen.org/tyxml/4.3.0/api/Svg_types) - and then, to render the SVG, traverse the document and render the paths/lines/rects/etc. We could limit ourselves to a small subset (ie, enough to get chess pieces rendering to start 😎 ). Although there are a lot that SVG supports, I think we could get by with a very small useful subset.

Additional capabilities could make for 'good first issues' once we have the infrastructure in place.

Alternatively, it looks like there are a few C/C++ libraries that could help:

bryphe commented 4 years ago

I think what tricked me is there is an SkSVG class.... but it's for a canvas with a SVG backend, not for loading/parsing/rendering SVGs

kyldvs commented 4 years ago

I see, that makes sense! I'll continue to work around this for now and hold out a bit longer since it seems further out :)

zbaylin commented 4 years ago

I was looking at something unrelated to this and stumbled upon this SVG rasterizing library: https://github.com/RazrFalcon/resvg. It even has minimal Skia bindings! Definitely something to consider. Writing an SVG renderer ourselves would be very time consuming!