Git Product home page Git Product logo

svglover's Introduction

svglover

A pure lua library to import and display simple SVGs in LÖVE.

Tested up to love-11.3 (Mysterious Mysteries).

Note that because it is specifically written for LÖVE, it is probably not useful for other Lua environments.

If you really want to squash your SVGs, try running them through SVGO and/or gzipping them.

The latest code can always be found at Github.

Alternative SVG libraries

  • lvg is a relatively simple SVG renderer (in pure lua, like svglover)
  • tove2d a non pure lua love2d library for SVG support which includes multiple renderers and animation features, based on the unmaintained nanosvg C library

News

  • 2019-03-26: v1.1.1 released!

    • Fix typo
  • 2019-03-19: v1.1.0 released! Major work from @nasso, thanks!

    • Add support for the following elements: <path>, <use> and <polyline>.
    • Add support for the following attributes: href, xlink:href, d, viewBox, (stroke|fill)-opacity.
    • Add support for many more color formats.
    • Improved support for the transform attribute.
    • Improved support for opacity-related attributes.
    • Various XML parsing improvements.
    • Removed tableshow.lua - I don't know why it was there but I'm pretty sure it isn't needed for svglover to work since it wasn't used at all.
    • Changed the demo code to show all the new features.
    • Some bug fixes.
  • 2017-05-30: v1.0.5 released!

    • Normalize internal function naming / reduce potential namespace collision issues
  • 2016-10-02: v1.0.4 released!

    • Fix compatibility issue by moving from basic Lua IO functions to 100% Love filesystem functions
  • 2016-10-02: v1.0.3 released!

    • Allow automatic / transparent loading of gzip compressed SVG files
    • Add zoom feature
  • 2016-10-02: v1.0.2 released!

    • Fix Lua logic error that was stopping fill-related scaling from working properly
  • 2016-09-27: v1.0.1 released!

    • Add <circle> support (when circles are not drawn as <ellipse>)
    • Slightly hardier parsing
    • Improved documentation
  • 2016-09-27: v1.0.0 released!

    • Basic functionality

Features

  • Supports the following elements:

    • <circle>
    • <ellipse>
    • <g>
    • <path> (no support for ArcTo yet)
    • <polygon>
    • <polyline>
    • <rect>
    • <use>
  • Supports the following attributes:

    • id, href, xlink:href, x, y, width, height, cx, cy, r, rx, ry, d, points
    • transform (with support for translate, rotate, scale, skewX, skewY and matrix)
    • viewBox
    • stroke
    • stroke-opacity
    • stroke-width
    • fill
    • fill-opacity
    • opacity
  • Supports the following color syntaxes:

    • #1e90ff
    • #621
    • dodgerblue (or any other valid CSS color name)
    • rgb(12%, 56%, 100%)
    • rgb(30, 144, 255)
    • rgba(12%, 56%, 100%, 0.5)
    • rgba(30, 144, 255, 0.5)

Demo screenshot

Why?

  • SVGs are scalable, which is useful in today's era of vastly differing device screen resolutions
  • SVGs are small
  • Vector images look cool
  • With a little more coding you can probably animate their bits

Usage

First import the library with require

svglover = require('svglover')

You should normally load your SVGs straight away in the love.load() function to prevent duplicate reads. The syntax for doing this is as follows:

vector_image = svglover.load('some.svg')

You then specify where you want them displayed using:

svglover.display(vector_image,topleft_x,topleft_y,width,height,completely_fill_region,border_color,border_width,zoom)

... where completely_fill_region, border_color, border_width and zoom are optional.

Finally, you should add the svglover.draw() call to the end of your love.draw() function.

A complete example:

function love.load()
    vector_image = svglover.load('some.svg')
    svglover.display(vector_image,100,100,100,100,true,{255,0,0,255},1,1)
end

function love.draw()
    -- draw any scheduled SVGs
    svglover.draw()
end

Development

Feel free to hack, fork, create issues, or send pull requests. It should be possible and not too difficult to add advanced features like text and post-draw handles for dynamic manipuplation of the resulting images to support things like transitions. However, I am personally happy with the existing functionality and will not be adding features in the near future.

Motivation

I wanted to place SVG vector images in a roguelike game I was making, Zomia, but there was no pre-existing library. I first built a proof of concept in perl, svg2love, but then wanted to load files direct from SVG in Lua instead of an intermediate format.

This is my first Lua library, so it probably ignores many best practices.

svglover's People

Contributors

danielpower avatar globalcitizen avatar nasso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svglover's Issues

Add proper error messages

I'm currently trying to work with the lib but there's no proper errors. I think my current error is because I'm drawing to a canvas, not directly to the screen.

Support for the "style" attribute

I tried to draw a svg created in Inkscape, but the shapes are always black. I think it's because Inkscape stores the fill color in the style attribute:

style="fill:#ff0000"

rather than:

fill="#ff0000"

Is it possible to add support for style in svglover? I had a look at the code but couldn't really figure out where to start.

(Suggestion) MIT License?

I recently found out about svglover, and it is a very useful library. I'm looking to use it in some of my projects and make a fork to help continue development. However, I noticed that it's licensed under the GPL v3 license, which requires projects that use the library to release their source code. I often release the source code of projects I work on, but there are some cases where I would rather keep my source code proprietary. Could you consider relicensing svglover under a more permissive license like the MIT license?

I apologize if this has been asked or addressed already, I didn't see anything about this on the repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.