From 35b5b597293d3bf27d0213ecf00c1487ecef0502 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sat, 14 Jun 2014 01:09:04 +0300 Subject: [PATCH] Fixed bug when using close 'z' followed by relative move to 'm' - close path was not moving the current point to the end of the close line segment --- src/nanosvg.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index 8e9c57f..ba5ec3c 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -626,7 +626,12 @@ static void nsvg__addPoint(NSVGparser* p, float x, float y) static void nsvg__moveTo(NSVGparser* p, float x, float y) { - nsvg__addPoint(p, x, y); + if (p->npts > 0) { + p->pts[(p->npts-1)*2+0] = x; + p->pts[(p->npts-1)*2+1] = y; + } else { + nsvg__addPoint(p, x, y); + } } static void nsvg__lineTo(NSVGparser* p, float x, float y) @@ -826,7 +831,7 @@ static void nsvg__addPath(NSVGparser* p, char closed) float* curve; int i; - if (p->npts == 0) + if (p->npts < 4) return; if (closed) @@ -1268,6 +1273,7 @@ static int nsvg__parseTranslate(float* xform, const char* str) int na = 0; int len = nsvg__parseTransformArgs(str, args, 2, &na); if (na == 1) args[1] = 0.0; + nsvg__xformSetTranslation(t, args[0], args[1]); memcpy(xform, t, sizeof(float)*6); return len; @@ -1860,8 +1866,7 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr) } } - if(s) - { + if (s) { nsvg__resetPath(p); cpx = 0; cpy = 0; closedFlag = 0; @@ -1944,10 +1949,16 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr) } else if (cmd == 'Z' || cmd == 'z') { closedFlag = 1; // Commit path. - if (p->npts > 0) + if (p->npts > 0) { + // Move current point to first point + cpx = p->pts[0]; + cpy = p->pts[1]; + cpx2 = cpx; cpy2 = cpy; nsvg__addPath(p, closedFlag); + } // Start new subpath. nsvg__resetPath(p); + nsvg__moveTo(p, cpx, cpy); closedFlag = 0; nargs = 0; }