Skip to content

Commit

Permalink
Added nsvgDuplicatePath . Also, fixed some minor typos into the tutor…
Browse files Browse the repository at this point in the history
…ial. Ref memononen#62
  • Loading branch information
alecive committed Feb 18, 2016
1 parent a523e02 commit 3d8f848
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
41 changes: 37 additions & 4 deletions src/nanosvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2830,6 +2833,36 @@ NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
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;
Expand Down
3 changes: 2 additions & 1 deletion src/nanosvgrast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3d8f848

Please sign in to comment.