Go to file
Mikko Mononen 87aed6d1fc Fixed bug in path number parsing in exponent form (i.e. 6e-5) 2014-01-23 19:02:23 +02:00
example Updated documentation 2014-01-09 23:22:38 +02:00
src Fixed bug in path number parsing in exponent form (i.e. 6e-5) 2014-01-23 19:02:23 +02:00
.gitignore Fixed bug in path number parsing in exponent form (i.e. 6e-5) 2014-01-23 19:02:23 +02:00
LICENSE.txt Updated documentation 2014-01-09 23:22:38 +02:00
README.md Updated documentation 2014-01-09 23:22:38 +02:00
premake4.lua Changed struct names, fixed color parser bug and added rasterizer 2014-01-09 22:15:26 +02:00

README.md

Nano SVG

Parser

screenshot of some splines rendered witht the sample program

NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes.

The library suits well for anything from rendering scalable icons in your editor application to prototyping a game.

NanoSVG supports a wide range of SVG features, if somehing is missing, feel free to create a pull request!

Rasterizer

screenshot of tiger.svg rendered with NanoSVG rasterizer

The parser library is accompanied with really simpler SVG rasterizer. Currently it only renders flat filled shapes.

The intended usage for the rasterizer is to for example bake icons of different size into a texture. The rasterizer is not particular fast or accurate, but it's small and packed in one header file.

Example Usage

// Load
struct NSVGimage* image;
image = nsvgParseFromFile("test.svg.");
printf("size: %f x %f\n", image->width, image->height);
// Use...
for (shape = image->shapes; shape != NULL; shape = shape->next) {
	for (path = shape->paths; path != NULL; path = path->next) {
		for (i = 0; i < path->npts-1; i += 3) {
			float* p = &path->pts[i*2];
			drawCubicBez(p[0],p[1], p[2],p[3], p[4],p[5], p[6],p[7]);
		}
	}
}
// Delete
nsvgDelete(image);

Using NanoSVG in your project

In order to use NanoSVG in your own project, just copy nanosvg.h to your project. In one C/C++ define NANOSVG_IMPLEMENTATION before including the library to expand the NanoSVG implementation in that file.

#define NANOSVG_IMPLEMENTATION	// Expands implementation
#include "nanosvg.h"

By default, NanoSVG parses only the most common colors. In order to get support for full list of SVG color keywords, define NANOSVG_ALL_COLOR_KEYWORDS before expanding the implementation.

#define NANOSVG_ALL_COLOR_KEYWORDS	// Include full list of color keywords.
#define NANOSVG_IMPLEMENTATION		// Expands implementation
#include "nanosvg.h"

Compiling Example Project

In order to compile the demo project, your will need to install GLFW to compile.

NanoSVG demo project uses premake4 to build platform specific projects, now is good time to install it if you don't have it already. To build the example, navigate into the root folder in your favorite terminal, then:

  • OS X: premake4 xcode4
  • Windows: premake4 vs2010
  • Linux: premake4 gmake

See premake4 documentation for full list of supported build file types. The projects will be created in build folder. An example of building and running the example on OS X:

$ premake4 gmake
$ cd build/
$ make
$ ./example

License

The library is licensed under zlib license