From 64c8b0c00ccf17af0cc929dd5f273d5a6317dd43 Mon Sep 17 00:00:00 2001 From: lieff Date: Fri, 21 Apr 2017 19:28:06 +0300 Subject: [PATCH 1/2] fix shapes order --- src/nanosvg.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index 40ebac7..ddaefd9 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -435,6 +435,7 @@ typedef struct NSVGparser NSVGpath* plist; NSVGimage* image; NSVGgradientData* gradients; + NSVGshape *shapesTail; float viewMinx, viewMiny, viewWidth, viewHeight; int alignX, alignY, alignType; float dpi; @@ -996,9 +997,13 @@ static void nsvg__addShape(NSVGparser* p) // Set flags shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00); - // Add to head due to performance, reverse list later - shape->next = p->image->shapes; - p->image->shapes = shape; + // Add to tail + if (NULL == p->image->shapes) { + p->image->shapes = shape; + } else { + p->shapesTail->next = shape; + } + p->shapesTail = shape; return; @@ -2797,16 +2802,6 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi) nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p); - //reverse the list of shapes to match svg order - cur = p->image->shapes; - while (cur && cur->next != NULL) { - tmp = cur->next; - cur->next = cur->next->next; - tmp->next = p->image->shapes; - p->image->shapes = tmp; - cur = cur->next; - } - // Scale to viewBox nsvg__scaleToViewbox(p, units); From c28363f9fb7ad0b31a37f6e053ca0f218548a3cf Mon Sep 17 00:00:00 2001 From: lieff Date: Fri, 21 Apr 2017 21:42:46 +0300 Subject: [PATCH 2/2] coding style --- src/nanosvg.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index ddaefd9..395ffa6 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -145,7 +145,7 @@ typedef struct NSVGshape char strokeDashCount; // Number of dash values in dash array. char strokeLineJoin; // Stroke join type. char strokeLineCap; // Stroke cap type. - float miterLimit; // Miter limit + float miterLimit; // Miter limit char fillRule; // Fill rule, see NSVGfillRule. unsigned char flags; // Logical or of NSVG_FLAGS_* flags float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy]. @@ -414,7 +414,7 @@ typedef struct NSVGattrib int strokeDashCount; char strokeLineJoin; char strokeLineCap; - float miterLimit; + float miterLimit; char fillRule; float fontSize; unsigned int stopColor; @@ -435,7 +435,7 @@ typedef struct NSVGparser NSVGpath* plist; NSVGimage* image; NSVGgradientData* gradients; - NSVGshape *shapesTail; + NSVGshape* shapesTail; float viewMinx, viewMiny, viewWidth, viewHeight; int alignX, alignY, alignType; float dpi; @@ -998,11 +998,10 @@ static void nsvg__addShape(NSVGparser* p) shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00); // Add to tail - if (NULL == p->image->shapes) { + if (p->image->shapes == NULL) p->image->shapes = shape; - } else { + else p->shapesTail->next = shape; - } p->shapesTail = shape; return; @@ -2156,23 +2155,23 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr) // Moveto can be followed by multiple coordinate pairs, // which should be treated as linetos. cmd = (cmd == 'm') ? 'l' : 'L'; - rargs = nsvg__getArgsPerElement(cmd); - cpx2 = cpx; cpy2 = cpy; + rargs = nsvg__getArgsPerElement(cmd); + cpx2 = cpx; cpy2 = cpy; break; case 'l': case 'L': nsvg__pathLineTo(p, &cpx, &cpy, args, cmd == 'l' ? 1 : 0); - cpx2 = cpx; cpy2 = cpy; + cpx2 = cpx; cpy2 = cpy; break; case 'H': case 'h': nsvg__pathHLineTo(p, &cpx, &cpy, args, cmd == 'h' ? 1 : 0); - cpx2 = cpx; cpy2 = cpy; + cpx2 = cpx; cpy2 = cpy; break; case 'V': case 'v': nsvg__pathVLineTo(p, &cpx, &cpy, args, cmd == 'v' ? 1 : 0); - cpx2 = cpx; cpy2 = cpy; + cpx2 = cpx; cpy2 = cpy; break; case 'C': case 'c': @@ -2193,13 +2192,13 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr) case 'A': case 'a': nsvg__pathArcTo(p, &cpx, &cpy, args, cmd == 'a' ? 1 : 0); - cpx2 = cpx; cpy2 = cpy; + cpx2 = cpx; cpy2 = cpy; break; default: if (nargs >= 2) { cpx = args[nargs-2]; cpy = args[nargs-1]; - cpx2 = cpx; cpy2 = cpy; + cpx2 = cpx; cpy2 = cpy; } break; }