fixed "bad code offset" bug.
[swftools.git] / lib / modules / swfdraw.c
index b54a0e4..723b253 100644 (file)
@@ -5,6 +5,8 @@ typedef struct _SWFSHAPEDRAWER
     SHAPE*shape;
     TAG*tag;
     int tagfree;
+    SCOORD firstx;
+    SCOORD firsty;
     SCOORD lastx;
     SCOORD lasty;
     SRECT bbox;
@@ -55,6 +57,11 @@ static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int l
     swf_ShapeSetStyle(sdraw->tag,sdraw->shape,linestylebits?1:0,fillstylebits?1:0,0/*?*/);
 }
 
+void swf_Shape10DrawerInit(drawer_t*draw, TAG*tag)
+{
+    swf_ShapeDrawerInit(draw, tag, 0, 1);
+}
+
 void swf_Shape01DrawerInit(drawer_t*draw, TAG*tag)
 {
     swf_ShapeDrawerInit(draw, tag, 1, 0);
@@ -73,15 +80,40 @@ static void swf_ShapeDrawerSetFillStyle(drawer_t*draw, void*style)
 {
     SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
 }
+static void fixEndPoint(drawer_t*draw)
+{
+    SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
+    if(   sdraw->firstx != sdraw->lastx 
+       || sdraw->firsty != sdraw->lasty) {
+       /* fix non-closing shapes */
+       FPOINT to;
+       to.x = sdraw->firstx/20.0;
+       to.y = sdraw->firsty/20.0;
+       if(sdraw->shape->bits.fill) // do this only if the shape is filled
+           draw->lineTo(draw, &to);
+    }
+}
 static void swf_ShapeDrawerMoveTo(drawer_t*draw, FPOINT * to)
 {
     SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
     int x = to->x*20;
     int y = to->y*20;
-    swf_ShapeSetMove(sdraw->tag,sdraw->shape,x,y);
-    sdraw->lastx = x;
-    sdraw->lasty = y;
-    draw->pos = *to;
+
+    /* we need to write moveto always- it
+       might be that it signals the end of a polygon, otherwise
+       we would end up connecting two polygons which should
+       be seperate 
+       TODO: check if the last operation was a moveTo- if
+             yes we *can* skip it.
+     */
+
+    //if(sdraw->lastx != x || sdraw->lasty != y) {
+       fixEndPoint(draw);
+       swf_ShapeSetMove(sdraw->tag,sdraw->shape,x,y);
+       sdraw->firstx = sdraw->lastx = x;
+       sdraw->firsty = sdraw->lasty = y;
+       draw->pos = *to;
+    //}
 }
 static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to)
 {
@@ -128,6 +160,11 @@ static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT*  to)
 static void swf_ShapeDrawerFinish(drawer_t*draw)
 {
     SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
+    if(sdraw->isfinished)
+       return;
+       
+    fixEndPoint(draw);
+
     if(sdraw->bbox.xmin == SCOORD_MAX) {
        /* no points at all -> empty bounding box */
        sdraw->bbox.xmin = sdraw->bbox.ymin =