5 typedef struct _SWFSHAPEDRAWER
18 static void swf_ShapeDrawerSetLineStyle(drawer_t*draw, void*style);
19 static void swf_ShapeDrawerSetFillStyle(drawer_t*draw, void*style);
20 static void swf_ShapeDrawerMoveTo(drawer_t*draw, FPOINT * to);
21 static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to);
22 static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT* to);
23 static void swf_ShapeDrawerFinish(drawer_t*draw);
24 static void swf_ShapeDrawerClear(drawer_t*draw);
26 static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int linestylebits)
28 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)rfx_calloc(sizeof(SWFSHAPEDRAWER));
29 draw->internal = sdraw;
31 draw->setLineStyle = swf_ShapeDrawerSetLineStyle;
32 draw->setFillStyle = swf_ShapeDrawerSetFillStyle;
33 draw->moveTo = swf_ShapeDrawerMoveTo;
34 draw->lineTo = swf_ShapeDrawerLineTo;
35 draw->splineTo = swf_ShapeDrawerSplineTo;
36 draw->finish = swf_ShapeDrawerFinish;
37 draw->dealloc = swf_ShapeDrawerClear;
41 tag = swf_InsertTag(0, ST_DEFINESHAPE);
45 swf_ShapeNew(&sdraw->shape);
49 swf_SetU8(sdraw->tag,0);
50 sdraw->shape->bits.fill = fillstylebits;
51 sdraw->shape->bits.line = linestylebits;
53 sdraw->bbox.xmin = sdraw->bbox.ymin = SCOORD_MAX;
54 sdraw->bbox.xmax = sdraw->bbox.ymax = SCOORD_MIN;
56 sdraw->isfinished = 0;
58 swf_ShapeSetStyle(sdraw->tag,sdraw->shape,linestylebits?1:0,fillstylebits?1:0,0/*?*/);
61 void swf_Shape10DrawerInit(drawer_t*draw, TAG*tag)
63 swf_ShapeDrawerInit(draw, tag, 0, 1);
66 void swf_Shape01DrawerInit(drawer_t*draw, TAG*tag)
68 swf_ShapeDrawerInit(draw, tag, 1, 0);
71 void swf_Shape11DrawerInit(drawer_t*draw, TAG*tag)
73 swf_ShapeDrawerInit(draw, tag, 1, 1);
76 static void swf_ShapeDrawerSetLineStyle(drawer_t*draw, void*style)
78 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
80 static void swf_ShapeDrawerSetFillStyle(drawer_t*draw, void*style)
82 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
84 static void fixEndPoint(drawer_t*draw)
86 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
87 if( sdraw->firstx != sdraw->lastx
88 || sdraw->firsty != sdraw->lasty) {
89 /* fix non-closing shapes */
91 to.x = sdraw->firstx/20.0;
92 to.y = sdraw->firsty/20.0;
93 if(sdraw->shape->bits.fill) // do this only if the shape is filled
94 draw->lineTo(draw, &to);
97 static void swf_ShapeDrawerMoveTo(drawer_t*draw, FPOINT * to)
99 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
100 int x = to->x*20+0.001;
101 int y = to->y*20+0.001;
103 /* we need to write moveto always- it
104 might be that it signals the end of a polygon, otherwise
105 we would end up connecting two polygons which should
107 TODO: check if the last operation was a moveTo- if
108 yes we *can* skip it.
111 //if(sdraw->lastx != x || sdraw->lasty != y) {
113 swf_ShapeSetMove(sdraw->tag,sdraw->shape,x,y);
114 sdraw->firstx = sdraw->lastx = x;
115 sdraw->firsty = sdraw->lasty = y;
119 static void swf_ShapeDrawerLineTo(drawer_t*draw, FPOINT * to)
121 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
122 int x = to->x*20+0.001;
123 int y = to->y*20+0.001;
124 if(sdraw->lastx < sdraw->bbox.xmin) sdraw->bbox.xmin = sdraw->lastx;
125 if(sdraw->lasty < sdraw->bbox.ymin) sdraw->bbox.ymin = sdraw->lasty;
126 if(sdraw->lastx > sdraw->bbox.xmax) sdraw->bbox.xmax = sdraw->lastx;
127 if(sdraw->lasty > sdraw->bbox.ymax) sdraw->bbox.ymax = sdraw->lasty;
128 if(x < sdraw->bbox.xmin) sdraw->bbox.xmin = x;
129 if(y < sdraw->bbox.ymin) sdraw->bbox.ymin = y;
130 if(x > sdraw->bbox.xmax) sdraw->bbox.xmax = x;
131 if(y > sdraw->bbox.ymax) sdraw->bbox.ymax = y;
132 swf_ShapeSetLine(sdraw->tag,sdraw->shape,x-sdraw->lastx,y-sdraw->lasty);
137 static void swf_ShapeDrawerSplineTo(drawer_t*draw, FPOINT * c1, FPOINT* to)
139 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
140 int tx = c1->x*20+0.001;
141 int ty = c1->y*20+0.001;
142 int x = to->x*20+0.001;
143 int y = to->y*20+0.001;
144 if(sdraw->lastx < sdraw->bbox.xmin) sdraw->bbox.xmin = sdraw->lastx;
145 if(sdraw->lasty < sdraw->bbox.ymin) sdraw->bbox.ymin = sdraw->lasty;
146 if(sdraw->lastx > sdraw->bbox.xmax) sdraw->bbox.xmax = sdraw->lastx;
147 if(sdraw->lasty > sdraw->bbox.ymax) sdraw->bbox.ymax = sdraw->lasty;
148 if(x < sdraw->bbox.xmin) sdraw->bbox.xmin = x;
149 if(y < sdraw->bbox.ymin) sdraw->bbox.ymin = y;
150 if(x > sdraw->bbox.xmax) sdraw->bbox.xmax = x;
151 if(y > sdraw->bbox.ymax) sdraw->bbox.ymax = y;
152 if(tx < sdraw->bbox.xmin) sdraw->bbox.xmin = tx;
153 if(ty < sdraw->bbox.ymin) sdraw->bbox.ymin = ty;
154 if(tx > sdraw->bbox.xmax) sdraw->bbox.xmax = tx;
155 if(ty > sdraw->bbox.ymax) sdraw->bbox.ymax = ty;
156 swf_ShapeSetCurve(sdraw->tag,sdraw->shape, tx-sdraw->lastx,ty-sdraw->lasty, x-tx,y-ty);
161 static void swf_ShapeDrawerFinish(drawer_t*draw)
163 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
164 if(sdraw->isfinished)
169 if(sdraw->bbox.xmin == SCOORD_MAX) {
170 /* no points at all -> empty bounding box */
171 sdraw->bbox.xmin = sdraw->bbox.ymin =
172 sdraw->bbox.xmax = sdraw->bbox.ymax = 0;
174 sdraw->isfinished = 1;
175 swf_ShapeSetEnd(sdraw->tag);
178 static void swf_ShapeDrawerClear(drawer_t*draw)
180 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
182 swf_DeleteTag(sdraw->tag);
185 swf_ShapeFree(sdraw->shape);
188 rfx_free(draw->internal);
192 SRECT swf_ShapeDrawerGetBBox(drawer_t*draw)
194 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
198 SHAPE* swf_ShapeDrawerToShape(drawer_t*draw)
200 SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
201 SHAPE* shape = (SHAPE*)rfx_alloc(sizeof(SHAPE));
202 if(!sdraw->isfinished) {
203 fprintf(stderr, "Warning: you should Finish() your drawer before calling DrawerToShape");
204 swf_ShapeDrawerFinish(draw);
206 memcpy(shape, sdraw->shape, sizeof(SHAPE));
207 shape->bitlen = (sdraw->tag->len-1)*8;
208 shape->data = (U8*)rfx_alloc(sdraw->tag->len-1);
209 memcpy(shape->data, &sdraw->tag->data[1], sdraw->tag->len-1);