From 3d8f8485f2c40bdde0558c91451a086091a5da81 Mon Sep 17 00:00:00 2001 From: Alessandro Roncone Date: Wed, 17 Feb 2016 20:12:59 -0500 Subject: [PATCH] Added nsvgDuplicatePath . Also, fixed some minor typos into the tutorial. Ref #62 --- src/nanosvg.h | 41 +++++++++++++++++++++++++++++++++++++---- src/nanosvgrast.h | 3 ++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index 91dbdec..3632bf6 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -45,15 +45,15 @@ extern "C" { // NanoSVG 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 NanoVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or 'in'. +// The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or '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: - // Load - SNVGImage* image; + // Load SVG + NSVGimage* image; image = nsvgParseFromFile("test.svg", "px", 96); printf("size: %f x %f\n", image->width, image->height); // Use... @@ -166,7 +166,10 @@ NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi) // Important note: changes the string. NSVGimage* nsvgParse(char* input, const char* units, float dpi); -// Deletes list of paths. +// Duplicates a path. +NSVGpath* nsvgDuplicatePath(NSVGpath* p); + +// Deletes an image. void nsvgDelete(NSVGimage* image); #ifdef __cplusplus @@ -2830,6 +2833,36 @@ error: return NULL; } +NSVGpath* nsvgDuplicatePath(NSVGpath* p) +{ + NSVGpath* res = NULL; + + if (p == NULL) + return NULL; + + res = (NSVGpath*)malloc(sizeof(NSVGpath)); + if (res == NULL) goto error; + memset(res, 0, sizeof(NSVGpath)); + + res->pts = (float*)malloc(p->npts*2*sizeof(float)); + if (res->pts == NULL) goto error; + memcpy(res->pts, p->pts, p->npts * sizeof(float) * 2); + res->npts = p->npts; + + memcpy(res->bounds, p->bounds, sizeof(p->bounds)); + + res->closed = p->closed; + + return res; + +error: + if (res != NULL) { + free(res->pts); + free(res); + } + return NULL; +} + void nsvgDelete(NSVGimage* image) { NSVGshape *snext, *shape; diff --git a/src/nanosvgrast.h b/src/nanosvgrast.h index c71d7b4..af5da00 100644 --- a/src/nanosvgrast.h +++ b/src/nanosvgrast.h @@ -33,7 +33,8 @@ typedef struct NSVGrasterizer NSVGrasterizer; /* Example Usage: // Load SVG - struct SNVGImage* image = nsvgParseFromFile("test.svg."); + NSVGimage* image; + image = nsvgParseFromFile("test.svg", "px", 96); // Create rasterizer (can be used to render multiple images). struct NSVGrasterizer* rast = nsvgCreateRasterizer();