pointers which are freed are now cleanly set to 0 afterwards.
[swftools.git] / lib / modules / swfdraw.c
1 // swfdraw.c
2 void swf_DrawerInit(SWFSHAPEDRAWER*draw, TAG*tag)
3 {
4     draw->tagfree = 0;
5     if(tag == 0) {
6         tag = swf_InsertTag(0, ST_DEFINESHAPE);
7         draw->tagfree = 1;
8     }
9     draw->tag = tag;
10     swf_ShapeNew(&draw->shape);
11     draw->pos = to;
12
13     swf_SetU8(draw->tag,0);
14     draw->shape->bits.fill = 1;
15     draw->shape->bits.line = 0;
16     swf_ShapeSetStyle(draw->tag,draw->shape,0,1,0);
17 }
18 void swf_DrawerMoveTo(SWFSHAPEDRAWER*draw, FPOINT * to)
19 {
20     swf_ShapeSetMove(draw->tag,draw->shape,(int)(to->x*20), (int)(to->y*20));
21     draw->pos = to;
22 }
23 void swf_DrawerLineTo(SWFSHAPEDRAWER*draw, FPOINT * to)
24 {
25     swf_ShapeSetMove(draw->tag,draw->shape,(int)(to->x*20), (int)(to->y*20));
26     draw->pos = to;
27 }
28 void swf_DrawerSplineTo(SWFSHAPEDRAWER*draw, FPOINT * c1, FPOINT*  to)
29 {
30     swf_ShapeSetSpline(draw->tag,draw->shape,
31             (int)(c1->x*20), (int)(c1->y*20),
32             (int)(to->x*20), (int)(to->y*20),
33             );
34     draw->pos = to;
35 }
36 void swf_DrawerCubicTo(SWFSHAPEDRAWER*draw, FPOINT*  c1, FPOINT* c2, FPOINT*  to)
37 {
38     draw->pos = to;
39 }
40 void swf_DrawerConicTo(SWFSHAPEDRAWER*draw, FPOINT* c, FPOINT*  to)
41 {
42     FPOINT* pos = draw->pos;
43     FPOINT c1,c2;
44     c1.x = (pos->x + 2 * c->x) / 3;
45     c1.y = (pos->y + 2 * c->y) / 3;
46     c2.x = (2 * c->x + to->x) / 3;
47     c2.y = (2 * c->y + to->y) / 3;
48     swf_DrawerCubicTo(draw, &c1,&c2,to);
49     draw->pos = to;
50     return 0;
51 }
52 void swf_DrawerFinish(SWFSHAPEDRAWER*draw)
53 {
54     swf_ShapeSetEnd(draw->tag);
55 }
56 void swf_Drawer2Shape(SWFSHAPEDRAWER*draw, SHAPE*shape)
57 {
58     memset(shape, 0, sizeof(SHAPE));
59     shape->bitlen = (draw->tag->len-1)*8;
60     shape->data = (U8*)malloc(draw->tag->len-1);
61     memcpy(shape->data, &draw->tag->data[1], draw->tag->len-1);
62 }
63 void swf_DrawerFree(SWFSHAPEDRAWER*draw)
64 {
65     if(draw->tagfree) {
66         swf_DeleteTag(tag);
67         draw->tag = 0;
68     }
69     swf_ShapeFree(draw->s);
70     draw->s = 0;
71 }