4747#include " ../include/OneLinerMacros.h"
4848
4949#ifndef DEBUG_ALL
50- #define DEBUG_SVG 0
50+ #define DEBUG_SVG 1
5151#else
5252#define DEBUG_SVG DEBUG_ALL
5353#endif
@@ -224,6 +224,7 @@ void nsvg__deleteShapes(NSVGshape* shape);
224224
225225void nsvg__dumpFloat (CONST char * s, float * t, int N)
226226{
227+ #if DEBUG_SVG
227228 DBG (" %s: " , s);
228229 for (int i=0 ; i<N;i++)
229230 {
@@ -233,6 +234,7 @@ void nsvg__dumpFloat(CONST char* s, float* t, int N)
233234 DBG (" %c%d.%06d " , ((b == 0 ) && sign)?' -' :' ' , b, (int )(fabsf ((a-(float )b)*1 .0e6f)));
234235 }
235236 DBG (" \n " );
237+ #endif
236238}
237239
238240static int nsvg__getIntegerDict (const char * s)
@@ -622,7 +624,7 @@ NSVGparser* nsvg__createParser()
622624 p->attr [0 ].strokeLineJoin = NSVG_JOIN_MITER ;
623625 p->attr [0 ].strokeLineCap = NSVG_CAP_BUTT ;
624626 p->attr [0 ].miterLimit = 4 ;
625- p->attr [0 ].fillRule = NSVG_FILLRULE_NONZERO ;
627+ p->attr [0 ].fillRule = NSVG_FILLRULE_EVENODD ;
626628 p->attr [0 ].hasFill = 1 ;
627629 p->attr [0 ].visible = NSVG_VIS_DISPLAY | NSVG_VIS_VISIBLE ;
628630 p->isText = false ;
@@ -834,7 +836,7 @@ static void nsvg__lineTo(NSVGparser* p, float x, float y)
834836 dy = y - py;
835837
836838 // ===== ОТЛАДКА =====
837- DBG (" LINE_TO: from (%f,%f) to (%f,%f), dx=%f, dy=%f\n " , px, py, x, y, dx, dy);
839+ // DBG("LINE_TO: from (%f,%f) to (%f,%f), dx=%f, dy=%f\n", px, py, x, y, dx, dy);
838840 // ===== КОНЕЦ ОТЛАДКИ =====
839841
840842 nsvg__addPoint (p, px + dx/3 .0f , py + dy/3 .0f );
@@ -847,8 +849,8 @@ static void nsvg__cubicBezTo(NSVGparser* p, float cpx1, float cpy1, float cpx2,
847849{
848850 if (p->npts > 0 ) {
849851 // ===== ОТЛАДКА =====
850- DBG (" CUBIC_TO: cp1=(%f,%f), cp2=(%f,%f), end=(%f,%f)\n " ,
851- cpx1, cpy1, cpx2, cpy2, x, y);
852+ // DBG("CUBIC_TO: cp1=(%f,%f), cp2=(%f,%f), end=(%f,%f)\n",
853+ // cpx1, cpy1, cpx2, cpy2, x, y);
852854 // ===== КОНЕЦ ОТЛАДКИ =====
853855 nsvg__addPoint (p, cpx1, cpy1);
854856 nsvg__addPoint (p, cpx2, cpy2);
@@ -1014,7 +1016,23 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, NSVGshape* shape, NSVGg
10141016 // The shape width and height.
10151017 if (data->units == NSVG_OBJECT_SPACE ) {
10161018 float localBounds[4 ];
1017- nsvg__getLocalBounds (localBounds, shape, false ); // , inv); //before any transform
1019+ // Если у shape есть clipList, берем bounds первого clipPath
1020+ if (shape->clipList )
1021+ {
1022+ NSVGclipPath *clipPath = nsvg__getClipPathWithIndex (p->image , shape->clipList ->index );
1023+ if (clipPath && clipPath->shapes )
1024+ {
1025+ nsvg__getLocalBounds (localBounds, clipPath->shapes , false );
1026+ }
1027+ else
1028+ {
1029+ nsvg__getLocalBounds (localBounds, shape, false );
1030+ }
1031+ }
1032+ else
1033+ {
1034+ nsvg__getLocalBounds (localBounds, shape, false );
1035+ }
10181036
10191037 ox = localBounds[0 ];
10201038 oy = localBounds[1 ];
@@ -1287,6 +1305,11 @@ static void nsvg__addPath(NSVGparser* p, char closed, const char* fromWhere)
12871305 nsvg__delete (path, " nsvg__addPath3" _XS8);
12881306 return ;
12891307 }
1308+
1309+ NSVGattrib* attr = nsvg__getAttr (p);
1310+ DBG (" nsvg__addPath: shape=%s, added path with %d points, closed=%d\n " ,
1311+ attr->id , p->npts , closed);
1312+
12901313 path->closed = closed;
12911314 path->npts = p->npts ;
12921315
@@ -1308,8 +1331,17 @@ static void nsvg__addPath(NSVGparser* p, char closed, const char* fromWhere)
13081331 path->bounds [3 ] = nsvg__maxf (path->bounds [3 ], bounds[3 ]);
13091332 }
13101333 }
1311- path->next = p->pathList ;
1312- p->pathList = path;
1334+ // path->next = p->pathList;
1335+ // p->pathList = path;
1336+ if (p->pathList == NULL ) {
1337+ p->pathList = path;
1338+ } else {
1339+ NSVGpath* last = p->pathList ;
1340+ while (last->next ) last = last->next ;
1341+ last->next = path;
1342+ }
1343+
1344+ DBG (" nsvg__addPath: added path with %d points, closed=%d\n " , p->npts , closed);
13131345 return ;
13141346}
13151347
@@ -2025,7 +2057,7 @@ static char nsvg__parseFillRule(const char* str)
20252057 else if (strcmp (str, " evenodd" ) == 0 )
20262058 return NSVG_FILLRULE_EVENODD ;
20272059 // TODO: handle inherit.
2028- return NSVG_FILLRULE_NONZERO ;
2060+ return NSVG_FILLRULE_EVENODD ;
20292061}
20302062
20312063static const char * nsvg__getNextDashItem (const char * s, char * it)
@@ -3017,9 +3049,12 @@ static void nsvg__parsePath(NSVGparser* p, char** attr, bool addShape)
30173049 cmd = item[0 ];
30183050// rargs = nsvg__getArgsPerElement(cmd);
30193051 if (cmd == ' M' || cmd == ' m' ) {
3020- if (p->npts > 0 )
3052+ if (p->npts > 0 ) {
3053+ DBG (" nsvg__parsePath: closing subpath with %d points\n " , p->npts );
30213054 nsvg__addPath (p, closedFlag, " nsvg__parsePath" );
3055+ }
30223056 // Start new subpath.
3057+ DBG (" nsvg__parsePath: starting new subpath\n " );
30233058 nsvg__resetPath (p);
30243059 closedFlag = 0 ;
30253060 nargs = 0 ;
@@ -3831,6 +3866,7 @@ static void nsvg__parseGroup(NSVGparser* p, char** dict)
38313866 if (!curAttr) {
38323867 return ;
38333868 }
3869+
38343870 // DBG("parse group\n");
38353871 NSVGgroup* group = (NSVGgroup*)nsvg__alloczero (sizeof (NSVGgroup), " nsvg__parseGroup" _XS8);
38363872 group->next = p->image ->groups ;
@@ -4347,20 +4383,20 @@ static void nsvg__startElement(void* ud, const char* el, char** dict)
43474383 newNode->next = curAttr->clipList ;
43484384 curAttr->clipList = newNode;
43494385 }
4350- DBG (" ENTER CLIPPATH: id=%s, index=%d\n " , dict[i+1 ], p->clipPath ->index );
4386+ // DBG("ENTER CLIPPATH: id=%s, index=%d\n", dict[i+1], p->clipPath->index);
43514387 }
43524388 break ;
43534389 }
43544390 }
43554391
43564392 // Отладочный вывод
4357- DBG (" ENTER CLIPPATH: stack list=[" );
4358- NSVGclipNode* node = curAttr->clipList ;
4359- while (node) {
4360- DBG (" %d " , node->index );
4361- node = node->next ;
4362- }
4363- DBG (" ]\n " );
4393+ // DBG("ENTER CLIPPATH: stack list=[");
4394+ // NSVGclipNode* node = curAttr->clipList;
4395+ // while (node) {
4396+ // DBG("%d ", node->index);
4397+ // node = node->next;
4398+ // }
4399+ // DBG("]\n");
43644400
43654401 } else if (strcmp (el, " image" ) == 0 ) {
43664402 nsvg__parseEmbeddedPNG (p, dict);
0 commit comments