moved fillstyle definitions to ../rfxswf.c
[swftools.git] / lib / modules / swfshape.c
index 9753dfc..cbc1389 100644 (file)
 #define SF_LINE         0x08
 #define SF_NEWSTYLE     0x10
 
-#define FILL_SOLID      0x00
-#define FILL_LINEAR     0x10  // Gradient
-#define FILL_RADIAL     0x12
-#define FILL_TILED      0x40  // Bitmap
-#define FILL_CLIPPED    0x41
-
 void swf_ShapeFree(SHAPE * s)
-{ if (s)
-  { if (s->linestyle.data) free(s->linestyle.data);
+{ 
+    if(!s)
+        return;
+    if (s->linestyle.data) free(s->linestyle.data);
     s->linestyle.data = NULL;
     s->linestyle.n    = 0;
     if (s->fillstyle.data) free(s->fillstyle.data);
@@ -43,16 +39,17 @@ void swf_ShapeFree(SHAPE * s)
     s->fillstyle.n    = 0;
     if (s->data) free(s->data);
     s->data = NULL;
-  }
-  free(s);
+    free(s);
 }
 
 int swf_ShapeNew(SHAPE * * s)
-{ SHAPE * sh;
-  if (!s) return -1;
-  sh = (SHAPE *)malloc(sizeof(SHAPE)); s[0] = sh;
-  if (sh) memset(sh,0x00,sizeof(SHAPE));
-  return sh?0:-1;
+{ 
+    SHAPE * sh;
+    if (!s) return -1;
+    sh = (SHAPE *)malloc(sizeof(SHAPE)); 
+    *s = sh;
+    memset(sh,0,sizeof(SHAPE));
+    return 0;
 }
 
 int swf_GetSimpleShape(TAG * t,SHAPE * * s) // without Linestyle/Fillstyle Record
@@ -169,8 +166,6 @@ int swf_SetFillStyle(TAG * t,FILLSTYLE * f)
 { if ((!t)||(!f)) return -1;
   swf_SetU8(t,f->type);
   
-  // no gradients yet!
-  
   switch (f->type)
   { case FILL_SOLID:
       if (swf_GetTagID(t)!=ST_DEFINESHAPE3) swf_SetRGB(t,&f->color);
@@ -293,7 +288,7 @@ int swf_ShapeAddFillStyle(SHAPE * s,U8 type,MATRIX * m,RGBA * color,U16 id_bitma
     if (!s->fillstyle.data) return -1;
   }
 
-  // set fillstyle  (no gradients yet!)
+  // set fillstyle
   
   s->fillstyle.data[s->fillstyle.n].type = type; 
   s->fillstyle.data[s->fillstyle.n].id_bitmap = id_bitmap;
@@ -412,71 +407,73 @@ int swf_ShapeSetEnd(TAG * t)
 }
 
 int swf_ShapeSetLine(TAG * t,SHAPE * s,S32 x,S32 y)
-{ U8 b;
-  if (!t) return -1;
-  swf_SetBits(t,3,2); // Straight Edge
-
-  if ((!s)||((x!=0)&&(y!=0)))
-  { b = swf_CountBits(x,2);
+{ 
+    U8 b;
+    if (!t) return -1;
+   
+    b = swf_CountBits(x,2);
     b = swf_CountBits(y,b);
     if (b<2) b=2;
-    if(b-2 >= 16) {
-       fprintf(stderr, "Bit overflow in swf_ShapeSetLine(1)- %d\n", b);
-       fflush(stdout);
-       b = 17;
+    if(b >= 18) {
+        if(b >= 18 + 4) {
+            /* do not split into more than 16 segments. If the line is *that* long, something's broken */
+            fprintf(stderr, "Warning: Line to %.2f,%.2f is too long", (double)x,(double)y);
+            return -1;
+        } else {
+            /* split line */
+            int x1,y1,x2,y2;
+            if(x>=0) { x1 = x/2;x2 = (x+1)/2;} 
+            else     { x1 = x/2;x2 = (x-1)/2;}
+            if(y>=0) { y1 = y/2;y2 = (y+1)/2;} 
+            else     { y1 = y/2;y2 = (y-1)/2;}
+            swf_ShapeSetLine(t, s, x1,y1);
+            swf_ShapeSetLine(t, s, x2,y2);
+            return 0;
+        }
     }
-    swf_SetBits(t, b-2, 4);
-    swf_SetBits(t,1,1);
-    swf_SetBits(t,x,b);
-    swf_SetBits(t,y,b);
-    return 0;
-  }
 
-  if (x==0)
-  { b = swf_CountBits(y,2);
-    if(b<2) 
-        b=2;
-    if(b-2 >= 16) {
-       fprintf(stderr, "Bit overflow in swf_ShapeSetLine(2)- %d\n", b);
-       b = 17;
-    }
-    swf_SetBits(t, b-2, 4);
-    swf_SetBits(t,1,2);
-    swf_SetBits(t,y,b);
-  } 
-  else
-  { b = swf_CountBits(x,2);
-    if(b<2) 
-        b=2;
-    if(b-2 >= 16) {
-       fprintf(stderr, "Bit overflow in swf_ShapeSetLine(3)- %d\n", b);
-       b = 17;
+    if(x!=0 && y!=0) { //(!s)||((x!=0)&&(y!=0)))
+        swf_SetBits(t,3,2); // Straight Edge
+        swf_SetBits(t, b-2, 4); //Number of Bits in x/y
+        swf_SetBits(t,1,1); // Diagonal
+        swf_SetBits(t,x,b);
+        swf_SetBits(t,y,b);
+    } else if (x==0) {
+        swf_SetBits(t,3,2); // Straight Edge
+        swf_SetBits(t, b-2, 4); //Number of Bits in y
+        swf_SetBits(t,1,2); // Vertical
+        swf_SetBits(t,y,b);
+    } else {
+        swf_SetBits(t,3,2); // Straight Edge
+        swf_SetBits(t, b-2, 4); //Number of Bits in x
+        swf_SetBits(t,0,2); // Horizontal
+        swf_SetBits(t,x,b);
     }
-    swf_SetBits(t, b-2, 4);
-    swf_SetBits(t,0,2);
-    swf_SetBits(t,x,b);
-  }
-  return 0;
+    return 0;
 }
 
 int swf_ShapeSetCurve(TAG * t,SHAPE * s,S32 x,S32 y,S32 ax,S32 ay)
-{ U8 b;
-  if (!t) return -1;
+{ 
+    U8 b;
+    if (!t) return -1;
 
-  swf_SetBits(t,2,2);
-
-  b = swf_CountBits(ax,2);
-  b = swf_CountBits(ay,b);
-  b = swf_CountBits(x,b);
-  b = swf_CountBits(y,b);
+    b = swf_CountBits(ax,2);
+    b = swf_CountBits(ay,b);
+    b = swf_CountBits(x,b);
+    b = swf_CountBits(y,b);
 
-  swf_SetBits(t,b-2,4);
-  swf_SetBits(t,x,b);
-  swf_SetBits(t,y,b);
-  swf_SetBits(t,ax,b);
-  swf_SetBits(t,ay,b);
+    if(b >= 18) {
+          fprintf(stderr, "Bit overflow in swf_ShapeSetCurve- %d (%d,%d,%d,%d)\n", b, ax,ay,x,y);
+          b = 17;
+    }
 
-  return 0;
+    swf_SetBits(t,2,2);
+    swf_SetBits(t,b-2,4);
+    swf_SetBits(t,x,b);
+    swf_SetBits(t,y,b);
+    swf_SetBits(t,ax,b);
+    swf_SetBits(t,ay,b);
+    return 0;
 }
 
 int swf_ShapeSetCircle(TAG * t,SHAPE * s,S32 x,S32 y,S32 rx,S32 ry)