Hi there, this is my first post, my first Lua library and my first Love library.
I wrote svglover, in order to import and display simple SVGs in Love. It only works with basic SVGs ... notably typography is not supported. If you have the chance, perhaps you can get around this limitation if your SVG software supports the conversion of type to outlines.
I personally have only tested it with SVGs generated by https://github.com/fogleman/primitive - a tool to automatically convert raster (bitmap) images in to a series of vector shape primitives. You can choose between triangles, rectangles, ellipses, circles, aribitrarily rotated rectangles, or a combination of these. If you need to generate art for a project quick smart, you could do worse than follow my example and use this tool.
Anyway, you can download it at https://github.com/globalcitizen/svglover .. contributions, bug reports, forks, and issues welcome.
svglover :: Import and render simple SVGs
-
- Prole
- Posts: 3
- Joined: Thu Sep 22, 2016 5:45 pm
svglover :: Import and render simple SVGs
Last edited by globalcitizen on Tue Sep 27, 2016 9:28 am, edited 1 time in total.
- Sheepolution
- Party member
- Posts: 264
- Joined: Mon Mar 04, 2013 9:31 am
- Location: The Netherlands
- Contact:
Re: svglover :: Import and render SVGs
This is pretty neat, though I think you should really try to make it work with standard svgs. I tried it out with the old LÖVE logo svg, and sadly it didn't work.
I also recommend you read Kikito's module guide. Your library shouldn't be a bunch of global functions, you should instead return a svglover object contain these functions.
I also recommend you read Kikito's module guide. Your library shouldn't be a bunch of global functions, you should instead return a svglover object contain these functions.
-
- Prole
- Posts: 3
- Joined: Thu Sep 22, 2016 5:45 pm
Re: svglover :: Import and render SVGs
I had a look at the old logo file. It was made in Illustrator. The good news is, the code it exported shouldn't be too hard to support as the only missing feature is <path> tags. Unfortunately they are nontrivial and I don't need them, so I am not going to bother. For anyone that does want to bother, I have made an issue with the results of my research at https://github.com/globalcitizen/svglover/issues/1
Issues are not only <path> - there are a lot of features in SVG that I believe are not automatically/directly/easily supported in Love, for example various complex gradient fill types. While anything is possible, I am not motivated to implement these types of features because I personally have no use for them, but welcome others to join in and make the library better. About the complexity of SVG, see a post from today on HN: https://news.ycombinator.com/item?id=12583509
About the module structure, I've never been a fan of OO but I will do my best to normalize it.
Issues are not only <path> - there are a lot of features in SVG that I believe are not automatically/directly/easily supported in Love, for example various complex gradient fill types. While anything is possible, I am not motivated to implement these types of features because I personally have no use for them, but welcome others to join in and make the library better. About the complexity of SVG, see a post from today on HN: https://news.ycombinator.com/item?id=12583509
About the module structure, I've never been a fan of OO but I will do my best to normalize it.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: svglover :: Import and render simple SVGs
You don't need to do it OO-style, just don't have it barf stuff into the _Globals
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: svglover :: Import and render simple SVGs
Hello there.
I've played around with SVG in the past:
viewtopic.php?f=5&t=78537&p=195852#p195245
SVG has so many features that it's out of hand.
The problem is that some of these features (like elliptic arcs) have no standard rendering equivalent so they must be implemented in software.
There is another reason why I moved away from SVG - it's easier and faster to convert your vector graphics to something that you can directly handle in Love2D.
Also, if I were to rewrite my old project from scratch, I would keep it in "pure Lua" where the output can be handled by any rendering system.
I've played around with SVG in the past:
viewtopic.php?f=5&t=78537&p=195852#p195245
SVG has so many features that it's out of hand.
The problem is that some of these features (like elliptic arcs) have no standard rendering equivalent so they must be implemented in software.
There is another reason why I moved away from SVG - it's easier and faster to convert your vector graphics to something that you can directly handle in Love2D.
Also, if I were to rewrite my old project from scratch, I would keep it in "pure Lua" where the output can be handled by any rendering system.
-
- Prole
- Posts: 3
- Joined: Thu Sep 22, 2016 5:45 pm
Re: svglover :: Import and render simple SVGs
Cool, you actually have a <path> implementation! But if I am reading correctly, only for filled (not stroked) paths. So perhaps this means also your implementation would not display the love logo either. And I tested, and it doesn't. I guess I still prefer my implementation Rationale: with the third party 'primitive' tool, it can really be targeted at any image, and is a lot smaller/simpler code. It does have issues handling non-square images and transparency, though, and also lacks many SVG features, so it's far from perfect. But meets my needs.
Re: svglover :: Import and render simple SVGs
Nice implementation. I've found a bug in utils/math/curves.lua: Ramanujan's approximation lacks parentheses and needs a product instead of a plus sign. It should be:ivan wrote:Hello there.
I've played around with SVG in the past:
viewtopic.php?f=5&t=78537&p=195852#p195245
Code: Select all
-- pi * (3(a + b) - sqrt((3a + b) * (a + 3b)))
local l = (3*(rx + ry) - sqrt((3*rx + ry) * (rx + 3*ry)))*pi
Re: svglover :: Import and render simple SVGs
globalcitizen: Supporting svg paths requires triangulation with holes and a lot of scary maths. It could be done in Lua, but it's a lot of work to make it robust and fast. "stroke" requires polygon offsetting which is another problem altogether. Fill rules and clipping are also pretty complicated. In short, you need a very good geometry library to make something like that work properly. For vector graphics, I recommend potrace (using geojson output) and poly2tri - those two utilities used in conjunction can give you a list of triangles which can be rendered directly.
pgimeno: Good catch there! I have to look at that code, since I know that there are a few other errors too (for example, I couldn't come up with a constant time solution to the "Length of a cubic Bezier curve" problem). Maybe I'll work on it some more in the future, but it doesn't look like it will ever turn into a mature project. It just doesn't make sense to do all that heavy math lifting in Lua. The lib you found looks basically like an XML parser (it just extracts the paths and that it).
pgimeno: Good catch there! I have to look at that code, since I know that there are a few other errors too (for example, I couldn't come up with a constant time solution to the "Length of a cubic Bezier curve" problem). Maybe I'll work on it some more in the future, but it doesn't look like it will ever turn into a mature project. It just doesn't make sense to do all that heavy math lifting in Lua. The lib you found looks basically like an XML parser (it just extracts the paths and that it).
Re: svglover :: Import and render simple SVGs
How complex or simple the svg's need to be for the library to work? I was thinking of using vector graphics for easier scaling, too.
Who is online
Users browsing this forum: Bing [Bot] and 6 guests