SVG Support

This is a new topic for me. Is there any support in Codea that is useful for reading SVG files? If not, has anyone done any work towards this end? If not, is anyone familiar with a good XML parser or Lua libraries out in the wild that could be of help? Thanks!

@brianolive What’s an SVG file and what do you want to do with it. What’s the file format. Do you just want to read it or create one.

Hi Dave,

SVG are Scalable Vector Graphics files (https://en.wikipedia.org/wiki/Scalable_Vector_Graphics), an XML-based file spec to represent vector (as opposed to raster) data.

There is a very interesting set of Japanese Kanji SVG files here (https://github.com/parsimonhi/animCJK) that I’d like to use to power a Codea app used to learn how to write the Japanese Kanji (characters). The SVG files encode the stroke order, allow for animations of the character drawing, etc.

If I’m sufficiently motived, I’ll write what I need, but just seeing if anyone has done anything already with this file format. It is pretty common in Web development.

Thanks!

@brianolive Looking at the example file that’s in the Wikipedia link you show above, you could probably write something in Codea that could read it and do the graphics. I just wonder what a real SVG file would contain.

PS. I found a lot of example files at

https://www.w3schools.com/graphics/svg_examples.asp

@brianolive we don’t support SVG at the moment but you can use PDF for vector graphics (Codea will rasterise them at the supplied width and height, or at their native size if not specified. Also supports multi-page PDFs.)

But yeah your specific use requires more than just rasterising an SVG, since you need the stroke order.

@brianolive - found this about a library for svg support on the Lua based Love2D. Hope it’s of use.

https://love2d.org/forums/viewtopic.php?f=5&t=86419

Thanks everyone. I’ll check out the provided links and, if I stick with this project, I’ll likely just roll my own svg parser.

@brianolive - the forum link I posted above refers to the following Gist:

nanosvg

I’ve used an XML parser in Codea (as part of a Markdown → text-on-screen project). It’s an old project, but I’m pretty sure that I found a lua XML parser and didn’t have to do much (if anything) to get it to work.

I also have some drawing code that works in a similar fashion to how SVG paths are built up: saving the last point, and using relative points, and similar.

So you could use the XML parser to convert an SVG string into a lua object, then use the drawing code to render that onto the screen.

How much of SVG do you want to work with? Are you planning on supporting the entirety of SVG, or are you more interested in just rendering a single path with appropriate styling?

Thx @LoopSpace for the ideas. I only plan on parsing the info I would need at first - as you say, the path and basic styling. I’m open to any code you want to share or point me to. I haven’t had the time yet to do anything, but I’ll come around to it. Thanks!