arsd.svg

NanoVega.SVG is a simple stupid SVG parser. The output of the parser is a list of drawing commands.

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

NanoVega.SVG supports a wide range of SVG features, but something may be missing. Your's Captain Obvious.

More...

Members

Enums

NSVGDefaults
enum NSVGDefaults

Functions

kill
void kill(NSVG* image)
kill
void kill(NSVGrasterizer r)
nsvgCreateRasterizer
NSVGrasterizer nsvgCreateRasterizer()
nsvgParse
NSVG* nsvgParse(const(char)[] input, const(char)[] units = "px", float dpi = 96, int canvaswdt = -1, int canvashgt = -1)
nsvgParseFromFile
NSVG* nsvgParseFromFile(const(char)[] filename, const(char)[] units = "px", float dpi = 96, int canvaswdt = -1, int canvashgt = -1)
nsvgParseFromFile
NSVG* nsvgParseFromFile(auto ref ST fi, const(char)[] units = "px", float dpi = 96, int canvaswdt = -1, int canvashgt = -1)
nsvg__curveBounds
void nsvg__curveBounds(float* bounds, const(float)* curve)
nsvg__evalBezier
double nsvg__evalBezier(double t, double p0, double p1, double p2, double p3)
nsvg__ptInBounds
int nsvg__ptInBounds(const(float)* pt, const(float)* bounds)
nsvg__xformIdentity
void nsvg__xformIdentity(float* t)
nsvg__xformInverse
void nsvg__xformInverse(float* inv, const(float)* t)
nsvg__xformMultiply
void nsvg__xformMultiply(float* t, const(float)* s)
nsvg__xformPoint
void nsvg__xformPoint(float* dx, float* dy, in float x, in float y, const(float)* t)
nsvg__xformPremultiply
void nsvg__xformPremultiply(float* t, const(float)* s)
nsvg__xformSetRotation
void nsvg__xformSetRotation(float* t, in float a)
nsvg__xformSetScale
void nsvg__xformSetScale(float* t, in float sx, in float sy)
nsvg__xformSetSkewX
void nsvg__xformSetSkewX(float* t, in float a)
nsvg__xformSetSkewY
void nsvg__xformSetSkewY(float* t, in float a)
nsvg__xformSetTranslation
void nsvg__xformSetTranslation(float* t, in float tx, in float ty)
nsvg__xformVec
void nsvg__xformVec(float* dx, float* dy, in float x, in float y, const(float)* t)
rasterize
void rasterize(NSVGrasterizer r, const(NSVG)* image, float tx, float ty, float scale, ubyte* dst, int w, int h, int stride = -1)

Rasterizes SVG image, returns RGBA image (non-premultiplied alpha).

Manifest constants

NSVG_EPSILON
enum NSVG_EPSILON;

Structs

NSVG
struct NSVG

Detailed Description

The shapes in the SVG images are transformed by the viewBox and converted to specified units. That is, you should get the same looking data as your designed in your favorite app.

NanoVega.SVG can return the paths in few different units. For example if you want to render an image, you may choose to get the paths in pixels, or if you are feeding the data into a CNC-cutter, you may want to use millimeters.

The units passed to NanoVega.SVG should be one of: 'px', 'pt', 'pc', 'mm', 'cm', 'in'. DPI (dots-per-inch) controls how the unit conversion is done.

If you don't know or care about the units stuff, "px" and 96 should get you going.

Example Usage:

1 // Load
2 NSVG* image = nsvgParseFromFile("test.svg", "px", 96);
3 printf("size: %f x %f\n", image.width, image.height);
4 // Use...
5 image.forEachShape((in ref NSVG.Shape shape) {
6   if (!shape.visible) return;
7   shape.forEachPath((in ref NSVG.Path path) {
8     // this will issue final `LineTo` for closed pathes
9     path.forEachCommand!true(delegate (NSVG.Command cmd, const(float)[] args) nothrow @trusted @nogc {
10       final switch (cmd) {
11         case NSVG.Command.MoveTo: nvg.moveTo(args); break;
12         case NSVG.Command.LineTo: nvg.lineTo(args); break;
13         case NSVG.Command.QuadTo: nvg.quadTo(args); break;
14         case NSVG.Command.BezierTo: nvg.bezierTo(args); break;
15       }
16     });
17   });
18 });
19 
20 NSVGrasterizer rast = nsvgCreateRasterizer();
21 // Allocate memory for image
22 ubyte* img = malloc(w*h*4);
23 // Rasterize
24 nsvgRasterize(rast, image, 0, 0, 1, img, w, h, w*4);
25 
26 // Delete
27 image.kill();

Meta

Suggestion Box / Bug Report