+void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+
+ endtext(obj);
+ endshape(obj);
+
+ if(i->clippos >= 127)
+ {
+ msg("<warning> Too many clip levels.");
+ i->clippos --;
+ }
+
+ int myshapeid = ++i->currentswfid;
+ i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
+ RGBA col;
+ memset(&col, 0, sizeof(RGBA));
+ SHAPE*shape;
+ swf_ShapeNew(&shape);
+ int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
+ swf_SetU16(i->tag,myshapeid);
+ SRECT r = gfxline_getSWFbbox(line);
+ swf_SetRect(i->tag,&r);
+ swf_SetShapeStyles(i->tag,shape);
+ swf_ShapeCountBits(shape,NULL,NULL);
+ swf_SetShapeBits(i->tag,shape);
+ swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
+ i->swflastx = i->swflasty = UNDEFINED_COORD;
+ drawgfxline(obj, line);
+ swf_ShapeSetEnd(i->tag);
+ swf_ShapeFree(shape);
+
+ /* TODO: remember the bbox, and check all shapes against it */
+
+ i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
+ i->cliptags[i->clippos] = i->tag;
+ i->clipshapes[i->clippos] = myshapeid;
+ i->clipdepths[i->clippos] = i->depth++;
+ i->clippos++;
+}
+
+void swf_endclip(gfxdevice_t*dev)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+ if(i->textid>=0)
+ endtext(obj);
+ if(i->shapeid>=0)
+ endshape(obj);
+
+ if(!i->clippos) {
+ msg("<error> Invalid end of clipping region");
+ return;
+ }
+ i->clippos--;
+ swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth++);
+}
+int swf_setparameter(gfxdevice_t*dev, const char*key, const char*value)
+{
+ if(!strcmp(key, "next_bitmap_is_jpeg")) {
+ ((swfoutput_internal*)dev->internal)->jpeg = 1;
+ return 1;
+ }
+ return 0;
+}
+
+int gfxline_type(gfxline_t*line)
+{
+ int tmplines=0;
+ int tmpsplines=0;
+ int lines=0;
+ int splines=0;
+ while(line) {
+ if(line->type == gfx_moveTo) {
+ tmplines=0;
+ tmpsplines=0;
+ } else if(line->type == gfx_lineTo) {
+ tmplines++;
+ if(tmplines>lines)
+ lines=tmplines;
+ } else if(line->type == gfx_splineTo) {
+ tmpsplines++;
+ if(tmpsplines>lines)
+ splines=tmpsplines;
+ }
+ line = line->next;
+ }
+ if(lines==0 && splines==0) return 0;
+ else if(lines==1 && splines==0) return 1;
+ else if(lines==0 && splines==1) return 2;
+ else if(splines==0) return 3;
+ else return 4;
+}
+
+void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+ int type = gfxline_type(line);
+
+ /* TODO: * split line into segments, and perform this check for all segments */
+ if(width <= config_caplinewidth
+ || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
+ || (cap_style == gfx_capRound && type<=2)) {
+ endtext(obj);
+ swfoutput_setstrokecolor(obj, color->r, color->g, color->b, color->a);
+ swfoutput_setlinewidth(obj, width);
+ startshape(obj);
+ stopFill(obj);
+ drawgfxline(obj, line);
+ } else {
+ /* we need to convert the line into a polygon */
+ ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
+ gfxline_t*gfxline = SVPtogfxline(svp);
+ dev->fill(dev, gfxline, color);
+ }
+}
+void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+ endtext(obj);
+ if(!config_ignoredraworder)
+ endshape(obj);
+ swfoutput_setfillcolor(obj, color->r, color->g, color->b, color->a);
+ startshape(obj);
+ startFill(obj);
+ i->fill=1;
+ drawgfxline(obj, line);
+}
+void swf_fillgradient(gfxdevice_t*dev, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
+{
+ msg("<error> Gradient filling not implemented yet");
+}