moved swf_RecodeShapeData to ../lib/modules/swfshape.c
[swftools.git] / src / swfc.c
index 3a2f7ed..cdb227a 100644 (file)
@@ -642,8 +642,11 @@ static void s_endSWF()
 
     swf = stack[stackpos].swf;
     filename = stack[stackpos].filename;
-   
+  
+    //if(tag->prev && tag->prev->id != ST_SHOWFRAME)
+    //    tag = swf_InsertTag(tag, ST_SHOWFRAME);
     tag = swf_InsertTag(tag, ST_SHOWFRAME);
+
     tag = swf_InsertTag(tag, ST_END);
 
     swf_OptimizeTagOrder(swf);
@@ -699,7 +702,7 @@ void s_close()
 
 int s_getframe()
 {
-    return currentframe;
+    return currentframe+1;
 }
 
 void s_frame(int nr, int cut, char*name)
@@ -707,13 +710,9 @@ void s_frame(int nr, int cut, char*name)
     int t;
     TAG*now = tag;
 
-    /* // enabling the following code will make the frame
-       handling much more intuitive, but also break old
-       code:
-       
-       if(nr<1) 
-       syntaxerror("Frame number need to be at least 1");
-    nr--;*/
+    if(nr<1) 
+       syntaxerror("Illegal frame number");
+    nr--; // internally, frame 1 is frame 0
 
     for(t=currentframe;t<nr;t++) {
        tag = swf_InsertTag(tag, ST_SHOWFRAME);
@@ -789,15 +788,15 @@ void s_box(char*name, int width, int height, RGBA color, int linewidth, char*tex
 {
     SRECT r,r2;
     SHAPE* s;
-    int ls1,fs1=0;
+    int ls1=0,fs1=0;
     r2.xmin = 0;
     r2.ymin = 0;
     r2.xmax = width;
     r2.ymax = height;
     tag = swf_InsertTag(tag, ST_DEFINESHAPE3);
     swf_ShapeNew(&s);
-    ls1 = swf_ShapeAddLineStyle(s,linewidth,&color);
-
+    if(linewidth)
+        ls1 = swf_ShapeAddLineStyle(s,linewidth,&color);
     if(texture)
        fs1 = addFillStyle(s, &r2, texture);
 
@@ -834,11 +833,11 @@ void s_filled(char*name, char*outlinename, RGBA color, int linewidth, char*textu
 
     tag = swf_InsertTag(tag, ST_DEFINESHAPE3);
     swf_ShapeNew(&s);
-    ls1 = swf_ShapeAddLineStyle(s,linewidth,&color);
+    if(linewidth)
+        ls1 = swf_ShapeAddLineStyle(s,linewidth,&color);
     if(texture)
        fs1 = addFillStyle(s, &r2, texture);
-    else 
-       syntaxerror("non filled outlines not yet supported- please supply a fill=<color/texture> argument");
+    
     swf_SetU16(tag,id);
     rect.xmin = r2.xmin-linewidth-linewidth/2;
     rect.ymin = r2.ymin-linewidth-linewidth/2;
@@ -847,8 +846,11 @@ void s_filled(char*name, char*outlinename, RGBA color, int linewidth, char*textu
 
     swf_SetRect(tag,&rect);
     swf_SetShapeStyles(tag, s);
-    swf_SetShapeBits(tag, outline->shape); //does not count bits!
-    swf_SetBlock(tag, outline->shape->data, (outline->shape->bitlen+7)/8);
+    swf_ShapeCountBits(s,0,0);
+    swf_RecodeShapeData(outline->shape->data, outline->shape->bitlen, 1,            1, 
+                        &s->data,             &s->bitlen,             s->bits.fill, s->bits.line);
+    swf_SetShapeBits(tag, s);
+    swf_SetBlock(tag, s->data, (s->bitlen+7)/8);
     swf_ShapeFree(s);
 
     s_addcharacter(name, id, tag, rect);
@@ -859,14 +861,15 @@ void s_circle(char*name, int r, RGBA color, int linewidth, char*texture)
 {
     SRECT rect,r2;
     SHAPE* s;
-    int ls1,fs1=0;
+    int ls1=0,fs1=0;
     r2.xmin = r2.ymin = 0;
     r2.xmax = 2*r;
     r2.ymax = 2*r;
 
     tag = swf_InsertTag(tag, ST_DEFINESHAPE3);
     swf_ShapeNew(&s);
-    ls1 = swf_ShapeAddLineStyle(s,linewidth,&color);
+    if(linewidth)
+        ls1 = swf_ShapeAddLineStyle(s,linewidth,&color);
     if(texture)
        fs1 = addFillStyle(s, &r2, texture);
     swf_SetU16(tag,id);
@@ -1242,14 +1245,10 @@ void s_outline(char*name, char*format, char*source)
     draw_string(&draw, source);
     draw.finish(&draw);
     shape = swf_ShapeDrawerToShape(&draw);
-    //shape2 = swf_ShapeToShape2(shape);
-    //bounds = swf_GetShapeBoundingBox(shape2);
-    //swf_Shape2Free(shape2);
     bounds = swf_ShapeDrawerGetBBox(&draw);
     draw.dealloc(&draw);
     
-    outline = (outline_t*)malloc(sizeof(outline_t));
-    memset(outline, 0, sizeof(outline_t));
+    outline = (outline_t*)rfx_calloc(sizeof(outline_t));
     outline->shape = shape;
     outline->bbox = bounds;
     
@@ -2230,7 +2229,7 @@ static int c_frame(map_t*args)
     else {
        frame = parseInt(framestr);
        if(s_getframe() >= frame
-               && !(frame==0 && s_getframe()==frame)) // equality is o.k. for frame 0
+               && !(frame==1 && s_getframe()==frame)) // equality is o.k. for frame 0
            syntaxerror("frame expression must be >%d (is:%s)", s_getframe(), framestr);
     }
     s_frame(frame, cut, name);
@@ -2748,7 +2747,7 @@ static map_t parseArguments(char*command, char*pattern)
            }
        }
        if(pos==len) {
-           syntaxerror("don't know what to do with \"%s\". (All parameters for .%s already set)", text, command);
+           syntaxerror("Illegal argument \"%s\" to .%s", text, command);
        }
     }
 #if 0//def DEBUG