Updated NanoSVG to latest version (22 April 2019) 24/222224/2
authorRichard Huang <r.huang@samsung.com>
Fri, 10 Jan 2020 14:10:23 +0000 (14:10 +0000)
committerRichard Huang <r.huang@samsung.com>
Fri, 10 Jan 2020 15:01:18 +0000 (15:01 +0000)
Change-Id: I3a4082a0afe6411ac197d87bf5a706d8b97e5ab6

dali-toolkit/third-party/nanosvg/nanosvg.cc
dali-toolkit/third-party/nanosvg/nanosvg.h
dali-toolkit/third-party/nanosvg/nanosvgrast.cc
dali-toolkit/third-party/nanosvg/nanosvgrast.h

index a99d1dd..31f5f44 100755 (executable)
@@ -39,7 +39,7 @@
 #include <math.h>
 
 #define NSVG_PI (3.14159265358979323846264338327f)
 #include <math.h>
 
 #define NSVG_PI (3.14159265358979323846264338327f)
-#define NSVG_KAPPA90 (0.5522847493f)    // Lenght proportional to radius of a cubic bezier handle for 90deg arcs.
+#define NSVG_KAPPA90 (0.5522847493f)   // Length proportional to radius of a cubic bezier handle for 90deg arcs.
 
 #define NSVG_ALIGN_MIN 0
 #define NSVG_ALIGN_MID 1
 
 #define NSVG_ALIGN_MIN 0
 #define NSVG_ALIGN_MID 1
 #define NSVG_NOTUSED(v) do { (void)(1 ? (void)0 : ( (void)(v) ) ); } while(0)
 #define NSVG_RGB(r, g, b) (((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16))
 
 #define NSVG_NOTUSED(v) do { (void)(1 ? (void)0 : ( (void)(v) ) ); } while(0)
 #define NSVG_RGB(r, g, b) (((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16))
 
-#define NSVG_INLINE inline
+#ifdef _MSC_VER
+       #pragma warning (disable: 4996) // Switch off security warnings
+       #pragma warning (disable: 4100) // Switch off unreferenced formal parameter warnings
+       #ifdef __cplusplus
+       #define NSVG_INLINE inline
+       #else
+       #define NSVG_INLINE
+       #endif
+#else
+       #define NSVG_INLINE inline
+#endif
 
 
 static int nsvg__isspace(char c)
 
 
 static int nsvg__isspace(char c)
@@ -839,7 +849,6 @@ static void nsvg__addShape(NSVGparser* p)
                shape->fill.color = attr->fillColor;
                shape->fill.color |= (unsigned int)(attr->fillOpacity*255) << 24;
        } else if (attr->hasFill == 2) {
                shape->fill.color = attr->fillColor;
                shape->fill.color |= (unsigned int)(attr->fillOpacity*255) << 24;
        } else if (attr->hasFill == 2) {
-               shape->opacity *= attr->fillOpacity;
                float inv[6], localBounds[4];
                nsvg__xformInverse(inv, attr->xform);
                nsvg__getLocalBounds(localBounds, shape, inv);
                float inv[6], localBounds[4];
                nsvg__xformInverse(inv, attr->xform);
                nsvg__getLocalBounds(localBounds, shape, inv);
@@ -957,7 +966,7 @@ static double nsvg__atof(const char* s)
        // Parse integer part
        if (nsvg__isdigit(*cur)) {
                // Parse digit sequence
        // Parse integer part
        if (nsvg__isdigit(*cur)) {
                // Parse digit sequence
-               intPart = (double)strtoll(cur, &end, 10);
+               intPart = strtoll(cur, &end, 10);
                if (cur != end) {
                        res = (double)intPart;
                        hasIntPart = 1;
                if (cur != end) {
                        res = (double)intPart;
                        hasIntPart = 1;
@@ -985,7 +994,7 @@ static double nsvg__atof(const char* s)
 
        // Parse optional exponent
        if (*cur == 'e' || *cur == 'E') {
 
        // Parse optional exponent
        if (*cur == 'e' || *cur == 'E') {
-               int expPart = 0;
+               long expPart = 0;
                cur++; // skip 'E'
                expPart = strtol(cur, &end, 10); // Parse digit sequence with sign
                if (cur != end) {
                cur++; // skip 'E'
                expPart = strtol(cur, &end, 10); // Parse digit sequence with sign
                if (cur != end) {
@@ -1023,7 +1032,7 @@ static const char* nsvg__parseNumber(const char* s, char* it, const int size)
                }
        }
        // exponent
                }
        }
        // exponent
-       if (*s == 'e' || *s == 'E') {
+       if ((*s == 'e' || *s == 'E') && (s[1] != 'm' && s[1] != 'x')) {
                if (i < last) it[i++] = *s;
                s++;
                if (*s == '-' || *s == '+') {
                if (i < last) it[i++] = *s;
                s++;
                if (*s == '-' || *s == '+') {
@@ -1113,6 +1122,10 @@ NSVGNamedColor nsvg__colors[] = {
        { "gray", NSVG_RGB(128, 128, 128) },
        { "white", NSVG_RGB(255, 255, 255) },
 
        { "gray", NSVG_RGB(128, 128, 128) },
        { "white", NSVG_RGB(255, 255, 255) },
 
+/**
+ * In the original software, it needs to define "NANOSVG_ALL_COLOR_KEYWORDS" in order to support
+ * the following colors. We have removed this because we want to support all the colors.
+ */
        { "aliceblue", NSVG_RGB(240, 248, 255) },
        { "antiquewhite", NSVG_RGB(250, 235, 215) },
        { "aqua", NSVG_RGB( 0, 255, 255) },
        { "aliceblue", NSVG_RGB(240, 248, 255) },
        { "antiquewhite", NSVG_RGB(250, 235, 215) },
        { "aqua", NSVG_RGB( 0, 255, 255) },
@@ -1279,7 +1292,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 = nsvg__atof(str);\r
+       float val = nsvg__atof(str);
        if (val < 0.0f) val = 0.0f;
        if (val > 1.0f) val = 1.0f;
        return val;
        if (val < 0.0f) val = 0.0f;
        if (val > 1.0f) val = 1.0f;
        return val;
@@ -1512,7 +1525,7 @@ static char nsvg__parseLineJoin(const char* str)
        else if (strcmp(str, "bevel") == 0)
                return NSVG_JOIN_BEVEL;
        // TODO: handle inherit.
        else if (strcmp(str, "bevel") == 0)
                return NSVG_JOIN_BEVEL;
        // TODO: handle inherit.
-       return NSVG_CAP_BUTT;
+       return NSVG_JOIN_MITER;
 }
 
 static char nsvg__parseFillRule(const char* str)
 }
 
 static char nsvg__parseFillRule(const char* str)
@@ -2356,9 +2369,9 @@ static void nsvg__parseSVG(NSVGparser* p, const char** attr)
        for (i = 0; attr[i]; i += 2) {
                if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
                        if (strcmp(attr[i], "width") == 0) {
        for (i = 0; attr[i]; i += 2) {
                if (!nsvg__parseAttr(p, attr[i], attr[i + 1])) {
                        if (strcmp(attr[i], "width") == 0) {
-                               p->image->width = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 1.0f);
+                               p->image->width = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f);
                        } 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, 1.0f);
+                               p->image->height = nsvg__parseCoordinate(p, attr[i + 1], 0.0f, 0.0f);
                        } else if (strcmp(attr[i], "viewBox") == 0) {
                                const char *s = attr[i + 1];
                                char buf[64];
                        } else if (strcmp(attr[i], "viewBox") == 0) {
                                const char *s = attr[i + 1];
                                char buf[64];
@@ -2795,10 +2808,40 @@ 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)
 {
-    if (image == NULL) return;
        NSVGshape *snext, *shape;
        NSVGshape *snext, *shape;
+       if (image == NULL) return;
        shape = image->shapes;
        while (shape != NULL) {
                snext = shape->next;
        shape = image->shapes;
        while (shape != NULL) {
                snext = shape->next;
index 0e2bad8..27f8ac0 100644 (file)
 // 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.
 //
 // 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:
 // 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...
   image = nsvgParseFromFile("test.svg", "px", 96);
   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) {
+  for (NSVGshape *shape = image->shapes; shape != NULL; shape = shape->next) {
+    for (NSVGpath *path = shape->paths; path != NULL; path = path->next) {
+      for (int 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]);
       }
         float* p = &path->pts[i*2];
         drawCubicBez(p[0],p[1], p[2],p[3], p[4],p[5], p[6],p[7]);
       }
@@ -69,30 +69,30 @@ enum NSVGpaintType {
   NSVG_PAINT_NONE = 0,
   NSVG_PAINT_COLOR = 1,
   NSVG_PAINT_LINEAR_GRADIENT = 2,
   NSVG_PAINT_NONE = 0,
   NSVG_PAINT_COLOR = 1,
   NSVG_PAINT_LINEAR_GRADIENT = 2,
-  NSVG_PAINT_RADIAL_GRADIENT = 3,
+  NSVG_PAINT_RADIAL_GRADIENT = 3
 };
 
 enum NSVGspreadType {
   NSVG_SPREAD_PAD = 0,
   NSVG_SPREAD_REFLECT = 1,
 };
 
 enum NSVGspreadType {
   NSVG_SPREAD_PAD = 0,
   NSVG_SPREAD_REFLECT = 1,
-  NSVG_SPREAD_REPEAT = 2,
+  NSVG_SPREAD_REPEAT = 2
 };
 
 enum NSVGlineJoin {
   NSVG_JOIN_MITER = 0,
   NSVG_JOIN_ROUND = 1,
 };
 
 enum NSVGlineJoin {
   NSVG_JOIN_MITER = 0,
   NSVG_JOIN_ROUND = 1,
-  NSVG_JOIN_BEVEL = 2,
+  NSVG_JOIN_BEVEL = 2
 };
 
 enum NSVGlineCap {
   NSVG_CAP_BUTT = 0,
   NSVG_CAP_ROUND = 1,
 };
 
 enum NSVGlineCap {
   NSVG_CAP_BUTT = 0,
   NSVG_CAP_ROUND = 1,
-  NSVG_CAP_SQUARE = 2,
+  NSVG_CAP_SQUARE = 2
 };
 
 enum NSVGfillRule {
   NSVG_FILLRULE_NONZERO = 0,
 };
 
 enum NSVGfillRule {
   NSVG_FILLRULE_NONZERO = 0,
-  NSVG_FILLRULE_EVENODD = 1,
+  NSVG_FILLRULE_EVENODD = 1
 };
 
 enum NSVGflags {
 };
 
 enum NSVGflags {
@@ -168,7 +168,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);
 
 // 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);
 
 #endif // NANOSVG_H
 void nsvgDelete(NSVGimage* image);
 
 #endif // NANOSVG_H
index f0bff2e..259f695 100644 (file)
@@ -127,10 +127,10 @@ error:
 
 void nsvgDeleteRasterizer(NSVGrasterizer* r)
 {
 
 void nsvgDeleteRasterizer(NSVGrasterizer* r)
 {
-       if (r == NULL) return;
-
        NSVGmemPage* p;
 
        NSVGmemPage* p;
 
+       if (r == NULL) return;
+
        p = r->pages;
        while (p != NULL) {
                NSVGmemPage* next = p->next;
        p = r->pages;
        while (p != NULL) {
                NSVGmemPage* next = p->next;
index 92f31ea..4d6ea47 100644 (file)
@@ -10,7 +10,7 @@
  * freely, subject to the following restrictions:
  *
  * 1. The origin of this software must not be misrepresented; you must not
  * freely, subject to the following restrictions:
  *
  * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this softwarue
+ * claim that you wrote the original software. If you use this software
  * in a product, an acknowledgment in the product documentation would be
  * appreciated but is not required.
  * 2. Altered source versions must be plainly marked as such, and must not be
  * in a product, an acknowledgment in the product documentation would be
  * appreciated but is not required.
  * 2. Altered source versions must be plainly marked as such, and must not be
@@ -31,7 +31,8 @@ typedef struct NSVGrasterizer NSVGrasterizer;
 
 /* Example Usage:
   // Load SVG
 
 /* 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();
 
   // Create rasterizer (can be used to render multiple images).
   struct NSVGrasterizer* rast = nsvgCreateRasterizer();
@@ -44,7 +45,7 @@ typedef struct NSVGrasterizer NSVGrasterizer;
 // Allocated rasterizer context.
 NSVGrasterizer* nsvgCreateRasterizer();
 
 // Allocated rasterizer context.
 NSVGrasterizer* nsvgCreateRasterizer();
 
-// Rasterizes SVG image, returns RGBA image (premultiplied alpha)
+// Rasterizes SVG image, returns RGBA image (non-premultiplied alpha)
 //   r - pointer to rasterizer context
 //   image - pointer to image to rasterize
 //   tx,ty - image offset (applied after scaling)
 //   r - pointer to rasterizer context
 //   image - pointer to image to rasterize
 //   tx,ty - image offset (applied after scaling)