Update nanosvg library to current upstream version

See README.bundled-libs.txt
This commit is contained in:
Albrecht Schlosser 2019-01-31 19:06:06 +01:00
parent 39a8c72c86
commit 716a5067a9
3 changed files with 73 additions and 18 deletions

View File

@ -17,21 +17,21 @@ Current versions of bundled libraries:
Library Version Release date FLTK Version Library Version Release date FLTK Version
------------------------------------------------------------------ ------------------------------------------------------------------
jpeg jpeg-9c 2018-01-14 1.4.0 jpeg jpeg-9c 2018-01-14 1.4.0
nanosvg [1] 06c1f0f 2018-07-01 1.4.0 nanosvg e62285a43b [1] 2019-01-31 1.4.0
png libpng-1.6.34 2017-09-29 1.4.0 png libpng-1.6.34 2017-09-29 1.4.0
zlib zlib-1.2.11 2017-01-15 1.4.0 zlib zlib-1.2.11 2017-01-15 1.4.0
[1] Git commit: https://github.com/memononen/nanosvg
Previous versions of bundled libraries: Previous versions of bundled libraries:
Library Version Release date FLTK Version Library Version Release date FLTK Version
------------------------------------------------------------------ ------------------------------------------------------------------
nanosvg ce81a6577c [1] 2018-07-01 1.4.0
jpeg jpeg-9a 2014-01-19 1.3.4 jpeg jpeg-9a 2014-01-19 1.3.4
png libpng-1.6.16 2014-12-22 1.3.4 png libpng-1.6.16 2014-12-22 1.3.4
zlib zlib-1.2.8 2013-04-28 1.3.4 zlib zlib-1.2.8 2013-04-28 1.3.4
[1] Git commit in: https://github.com/fltk/nanosvg
See also git tag 'fltk_yyyy-mm-dd' where yyyy-mm-dd == "Release date".
General information: General information:
@ -49,7 +49,7 @@ General information:
later is aware of changes in the source code for FLTK. Additional comments later is aware of changes in the source code for FLTK. Additional comments
should be added to show the rationale, i.e. why a particular change was should be added to show the rationale, i.e. why a particular change was
necessary. If applicable, add a reference to a Software Trouble Report necessary. If applicable, add a reference to a Software Trouble Report
like "STR #3456". like "STR 3456", "Issue #123", or "PR #234".
How to update the bundled libraries: How to update the bundled libraries:

View File

@ -29,9 +29,11 @@
#ifndef NANOSVG_H #ifndef NANOSVG_H
#define NANOSVG_H #define NANOSVG_H
#ifndef NANOSVG_CPLUSPLUS
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#endif
// NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes. // NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes.
// //
@ -45,15 +47,15 @@ extern "C" {
// NanoSVG can return the paths in few different units. For example if you want to render an image, you may choose // 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. // 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. // 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. // If you don't know or care about the units stuff, "px" and 96 should get you going.
/* Example Usage: /* Example Usage:
// Load // Load SVG
NSVGImage* image; NSVGimage* image;
image = nsvgParseFromFile("test.svg", "px", 96); image = nsvgParseFromFile("test.svg", "px", 96);
printf("size: %f x %f\n", image->width, image->height); printf("size: %f x %f\n", image->width, image->height);
// Use... // Use...
@ -167,12 +169,17 @@ NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi)
// Important note: changes the string. // Important note: changes the string.
NSVGimage* nsvgParse(char* input, const char* units, float dpi); 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); void nsvgDelete(NSVGimage* image);
#ifndef NANOSVG_CPLUSPLUS
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif
#endif // NANOSVG_H #endif // NANOSVG_H
@ -1423,8 +1430,7 @@ static unsigned int nsvg__parseColor(const char* str)
static float nsvg__parseOpacity(const char* str) static float nsvg__parseOpacity(const char* str)
{ {
float val = 0; float val = nsvg__atof(str);
sscanf(str, "%f", &val);
if (val < 0.0f) val = 0.0f; if (val < 0.0f) val = 0.0f;
if (val > 1.0f) val = 1.0f; if (val > 1.0f) val = 1.0f;
return val; return val;
@ -1432,8 +1438,7 @@ static float nsvg__parseOpacity(const char* str)
static float nsvg__parseMiterLimit(const char* str) static float nsvg__parseMiterLimit(const char* str)
{ {
float val = 0; float val = nsvg__atof(str);
sscanf(str, "%f", &val);
if (val < 0.0f) val = 0.0f; if (val < 0.0f) val = 0.0f;
return val; return val;
} }
@ -1464,9 +1469,9 @@ static int nsvg__parseUnits(const char* units)
static NSVGcoordinate nsvg__parseCoordinateRaw(const char* str) static NSVGcoordinate nsvg__parseCoordinateRaw(const char* str)
{ {
NSVGcoordinate coord = {0, NSVG_UNITS_USER}; NSVGcoordinate coord = {0, NSVG_UNITS_USER};
char units[32]=""; char buf[64];
sscanf(str, "%f%31s", &coord.value, units); coord.units = nsvg__parseUnits(nsvg__parseNumber(str, buf, 64));
coord.units = nsvg__parseUnits(units); coord.value = nsvg__atof(buf);
return coord; return coord;
} }
@ -2506,7 +2511,22 @@ static void nsvg__parseSVG(NSVGparser* p, const char** attr)
} else if (strcmp(attr[i], "height") == 0) { } else if (strcmp(attr[i], "height") == 0) {
p->image->height = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f); p->image->height = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f);
} else if (strcmp(attr[i], "viewBox") == 0) { } else if (strcmp(attr[i], "viewBox") == 0) {
sscanf(attr[i + 1], "%f%*[%%, \t]%f%*[%%, \t]%f%*[%%, \t]%f", &p->viewMinx, &p->viewMiny, &p->viewWidth, &p->viewHeight); const char *s = attr[i + 1];
char buf[64];
s = nsvg__parseNumber(s, buf, 64);
p->viewMinx = nsvg__atof(buf);
while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++;
if (!*s) return;
s = nsvg__parseNumber(s, buf, 64);
p->viewMiny = nsvg__atof(buf);
while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++;
if (!*s) return;
s = nsvg__parseNumber(s, buf, 64);
p->viewWidth = nsvg__atof(buf);
while (*s && (nsvg__isspace(*s) || *s == '%' || *s == ',')) s++;
if (!*s) return;
s = nsvg__parseNumber(s, buf, 64);
p->viewHeight = nsvg__atof(buf);
} else if (strcmp(attr[i], "preserveAspectRatio") == 0) { } else if (strcmp(attr[i], "preserveAspectRatio") == 0) {
if (strstr(attr[i + 1], "none") != 0) { if (strstr(attr[i + 1], "none") != 0) {
// No uniform scaling // No uniform scaling
@ -2914,6 +2934,36 @@ error:
return NULL; 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) void nsvgDelete(NSVGimage* image)
{ {
NSVGshape *snext, *shape; NSVGshape *snext, *shape;

View File

@ -31,15 +31,18 @@
#ifndef NANOSVGRAST_H #ifndef NANOSVGRAST_H
#define NANOSVGRAST_H #define NANOSVGRAST_H
#ifndef NANOSVGRAST_CPLUSPLUS
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#endif
typedef struct NSVGrasterizer NSVGrasterizer; typedef struct NSVGrasterizer NSVGrasterizer;
/* Example Usage: /* Example Usage:
// Load SVG // 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). // Create rasterizer (can be used to render multiple images).
struct NSVGrasterizer* rast = nsvgCreateRasterizer(); struct NSVGrasterizer* rast = nsvgCreateRasterizer();
@ -78,9 +81,11 @@ void nsvgRasterizeXY(NSVGrasterizer* r,
void nsvgDeleteRasterizer(NSVGrasterizer*); void nsvgDeleteRasterizer(NSVGrasterizer*);
#ifndef NANOSVGRAST_CPLUSPLUS
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif
#endif // NANOSVGRAST_H #endif // NANOSVGRAST_H