numerous bigfixes in stroke->polygon conversion
[swftools.git] / lib / gfxtools.c
index 8ee2ff4..f754379 100644 (file)
@@ -62,9 +62,10 @@ static void linedraw_lineTo(gfxdrawer_t*d, gfxcoord_t x, gfxcoord_t y)
     gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t));
 
     if(!i->start) {
-       /* starts with a line, not with a moveto. That needs we first
-          need an explicit moveto to (0,0) */
-       linedraw_moveTo(d, 0, 0);
+       /* starts with a line, not with a moveto. As this is the first
+          entry in the list, this is probably *meant* to be a moveto */
+       linedraw_moveTo(d, x, y);
+       return;
     }
 
     l->type = gfx_lineTo;
@@ -84,9 +85,9 @@ static void linedraw_splineTo(gfxdrawer_t*d, gfxcoord_t sx, gfxcoord_t sy, gfxco
     gfxline_t*l = (gfxline_t*)rfx_alloc(sizeof(gfxline_t));
 
     if(!i->start) {
-       /* starts with a line, not with a moveto. That needs we first
-          need an explicit moveto to (0,0) */
-       linedraw_moveTo(d, 0, 0);
+       fprintf(stderr, "Error: drawing startpoint is a spline\n");
+       linedraw_moveTo(d, x, y);
+       return;
     }
 
     l->type = gfx_splineTo;
@@ -839,21 +840,24 @@ gfxline_t*gfxline_makecircle(double x,double y,double rx, double ry)
     double C1 = 0.2930;    
     double C2 = 0.4140;   
     double begin = 0.7070; 
-    gfxline_t* line = (gfxline_t*)rfx_calloc(sizeof(gfxline_t)*9);
+    gfxline_t** line = (gfxline_t**)rfx_calloc(sizeof(gfxline_t*)*9);
     int t;
-    line[0].type = gfx_moveTo;
-    line[0].x = x+begin*rx;
-    line[0].y = y+begin*ry;
+    for(t=0;t<9;t++) {
+       line[t] = rfx_calloc(sizeof(gfxline_t));
+    }
+    line[0]->type = gfx_moveTo;
+    line[0]->x = x+begin*rx;
+    line[0]->y = y+begin*ry;
     for(t=1;t<9;t++) {
-       line[t-1].next = &line[t];
-       line[t].type = gfx_splineTo;
+       line[t-1]->next = line[t];
+       line[t]->type = gfx_splineTo;
     }
-    line[t].next = 0;
+    line[8]->next = 0;
 #define R(nr,cx,cy,mx,my) \
-    line[nr].sx = line[nr-1].x + (cx); \
-    line[nr].sy = line[nr-1].y + (cy); \
-    line[nr].x = line[nr].sx + (mx); \
-    line[nr].y = line[nr].sy + (my);
+    line[nr]->sx = line[nr-1]->x + (cx); \
+    line[nr]->sy = line[nr-1]->y + (cy); \
+    line[nr]->x = line[nr]->sx + (mx); \
+    line[nr]->y = line[nr]->sy + (my);
     R(1, -C1*rx,  C1*ry, -C2*rx,      0);
     R(2, -C2*rx,      0, -C1*rx, -C1*ry);
     R(3, -C1*rx, -C1*ry,      0, -C2*ry);
@@ -862,7 +866,9 @@ gfxline_t*gfxline_makecircle(double x,double y,double rx, double ry)
     R(6,  C2*rx,      0,  C1*rx,  C1*ry);
     R(7,  C1*rx,  C1*ry,      0,  C2*ry);
     R(8,      0,  C2*ry, -C1*rx,  C1*ry);
-    return line;
+    gfxline_t*l = line[0];
+    free(line);
+    return l;
 }
 
 gfxbbox_t* gfxline_isrectangle(gfxline_t*_l)