3 typedef struct _SWFSHAPEDRAWER
16 static void swf_ShapeDrawerSetLineStyle(drawer_t*draw, void*style);
17 static void swf_ShapeDrawerSetFillStyle(drawer_t*draw, void*style);
18 static void swf_ShapeDrawerMoveTo(drawer_t*draw, FPOINT * to);
19 static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to);
20 static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT* to);
21 static void swf_ShapeDrawerFinish(drawer_t*draw);
22 static void swf_ShapeDrawerClear(drawer_t*draw);
24 static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int linestylebits)
26 SWFSHAPEDRAWER*sdraw = malloc(sizeof(SWFSHAPEDRAWER));
27 memset(sdraw, 0, sizeof(SWFSHAPEDRAWER));
28 draw->internal = sdraw;
30 draw->setLineStyle = swf_ShapeDrawerSetLineStyle;
31 draw->setFillStyle = swf_ShapeDrawerSetFillStyle;
32 draw->moveTo = swf_ShapeDrawerMoveTo;
33 draw->lineTo = swf_ShapeDrawerLineTo;
34 draw->splineTo = swf_ShapeDrawerSplineTo;
35 draw->finish = swf_ShapeDrawerFinish;
36 draw->dealloc = swf_ShapeDrawerClear;
40 tag = swf_InsertTag(0, ST_DEFINESHAPE);
44 swf_ShapeNew(&sdraw->shape);
48 swf_SetU8(sdraw->tag,0);
49 sdraw->shape->bits.fill = fillstylebits;
50 sdraw->shape->bits.line = linestylebits;
52 sdraw->bbox.xmin = sdraw->bbox.ymin = SCOORD_MAX;
53 sdraw->bbox.xmax = sdraw->bbox.ymax = SCOORD_MIN;
55 sdraw->isfinished = 0;
57 swf_ShapeSetStyle(sdraw->tag,sdraw->shape,linestylebits?1:0,fillstylebits?1:0,0/*?*/);
60 void swf_Shape10DrawerInit(drawer_t*draw, TAG*tag)
62 swf_ShapeDrawerInit(draw, tag, 0, 1);
65 void swf_Shape01DrawerInit(drawer_t*draw, TAG*tag)
67 swf_ShapeDrawerInit(draw, tag, 1, 0);
70 void swf_Shape11DrawerInit(drawer_t*draw, TAG*tag)
72 swf_ShapeDrawerInit(draw, tag, 1, 1);
75 static void swf_ShapeDrawerSetLineStyle(drawer_t*draw, void*style)
77 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
79 static void swf_ShapeDrawerSetFillStyle(drawer_t*draw, void*style)
81 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
83 static void fixEndPoint(drawer_t*draw)
85 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
86 if( sdraw->firstx != sdraw->lastx
87 || sdraw->firsty != sdraw->lasty) {
88 /* fix non-closing shapes */
90 to.x = sdraw->firstx/20.0;
91 to.y = sdraw->firsty/20.0;
92 if(sdraw->shape->bits.fill) // do this only if the shape is filled
93 draw->lineTo(draw, &to);
96 static void swf_ShapeDrawerMoveTo(drawer_t*draw, FPOINT * to)
98 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
101 if(sdraw->lastx != x || sdraw->lasty != y) {
103 swf_ShapeSetMove(sdraw->tag,sdraw->shape,x,y);
104 sdraw->firstx = sdraw->lastx = x;
105 sdraw->firsty = sdraw->lasty = y;
109 static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to)
111 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
114 if(sdraw->lastx < sdraw->bbox.xmin) sdraw->bbox.xmin = sdraw->lastx;
115 if(sdraw->lasty < sdraw->bbox.ymin) sdraw->bbox.ymin = sdraw->lasty;
116 if(sdraw->lastx > sdraw->bbox.xmax) sdraw->bbox.xmax = sdraw->lastx;
117 if(sdraw->lasty > sdraw->bbox.ymax) sdraw->bbox.ymax = sdraw->lasty;
118 if(x < sdraw->bbox.xmin) sdraw->bbox.xmin = x;
119 if(y < sdraw->bbox.ymin) sdraw->bbox.ymin = y;
120 if(x > sdraw->bbox.xmax) sdraw->bbox.xmax = x;
121 if(y > sdraw->bbox.ymax) sdraw->bbox.ymax = y;
122 swf_ShapeSetLine(sdraw->tag,sdraw->shape,x-sdraw->lastx,y-sdraw->lasty);
127 static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT* to)
129 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
134 if(sdraw->lastx < sdraw->bbox.xmin) sdraw->bbox.xmin = sdraw->lastx;
135 if(sdraw->lasty < sdraw->bbox.ymin) sdraw->bbox.ymin = sdraw->lasty;
136 if(sdraw->lastx > sdraw->bbox.xmax) sdraw->bbox.xmax = sdraw->lastx;
137 if(sdraw->lasty > sdraw->bbox.ymax) sdraw->bbox.ymax = sdraw->lasty;
138 if(x < sdraw->bbox.xmin) sdraw->bbox.xmin = x;
139 if(y < sdraw->bbox.ymin) sdraw->bbox.ymin = y;
140 if(x > sdraw->bbox.xmax) sdraw->bbox.xmax = x;
141 if(y > sdraw->bbox.ymax) sdraw->bbox.ymax = y;
142 if(tx < sdraw->bbox.xmin) sdraw->bbox.xmin = tx;
143 if(ty < sdraw->bbox.ymin) sdraw->bbox.ymin = ty;
144 if(tx > sdraw->bbox.xmax) sdraw->bbox.xmax = tx;
145 if(ty > sdraw->bbox.ymax) sdraw->bbox.ymax = ty;
146 swf_ShapeSetCurve(sdraw->tag,sdraw->shape, tx-sdraw->lastx,ty-sdraw->lasty, x-tx,y-ty);
151 static void swf_ShapeDrawerFinish(drawer_t*draw)
153 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
157 if(sdraw->bbox.xmin == SCOORD_MAX) {
158 /* no points at all -> empty bounding box */
159 sdraw->bbox.xmin = sdraw->bbox.ymin =
160 sdraw->bbox.xmax = sdraw->bbox.ymax = 0;
162 sdraw->isfinished = 1;
163 swf_ShapeSetEnd(sdraw->tag);
166 static void swf_ShapeDrawerClear(drawer_t*draw)
168 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
170 swf_DeleteTag(sdraw->tag);
173 swf_ShapeFree(sdraw->shape);
176 free(draw->internal);
180 SRECT swf_ShapeDrawerGetBBox(drawer_t*draw)
182 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
186 SHAPE* swf_ShapeDrawerToShape(drawer_t*draw)
188 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
189 SHAPE* shape = malloc(sizeof(SHAPE));
190 if(!sdraw->isfinished) {
191 fprintf(stderr, "Warning: you should Finish() your drawer before calling DrawerToShape");
192 swf_ShapeDrawerFinish(draw);
194 memcpy(shape, sdraw->shape, sizeof(SHAPE));
195 shape->bitlen = (sdraw->tag->len-1)*8;
196 shape->data = (U8*)malloc(sdraw->tag->len-1);
197 memcpy(shape->data, &sdraw->tag->data[1], sdraw->tag->len-1);