-int opennewwindow=0;
-int ignoredraworder=0;
-int drawonlyshapes=0;
-int jpegquality=85;
-static int flag_protected = 0;
-
-typedef unsigned char u8;
-typedef unsigned short int u16;
-typedef unsigned long int u32;
-
-static int fi;
-static char* filename = 0;
-static SWF swf;
-static TAG *tag;
-static int currentswfid = 0;
-static int depth = 1;
-static int startdepth = 1;
-
-static SHAPE* shape;
-static int shapeid = -1;
-static int textid = -1;
-
-static int drawmode = -1;
-static char storefont = 0;
-static int fillstyleid;
-static int linestyleid;
-static int swflastx=0;
-static int swflasty=0;
-static int lastwasfill = 0;
-static char fill = 0;
-static int sizex;
-static int sizey;
-TAG* cliptags[128];
-int clipshapes[128];
-u32 clipdepths[128];
-int clippos = 0;
-
-int CHARMIDX = 0;
-int CHARMIDY = 0;
-
-void startshape(struct swfoutput* obj);
-void starttext(struct swfoutput* obj);
-void endshape();
-void endtext();
+#define CHARDATAMAX 8192
+#define CHARMIDX 0
+#define CHARMIDY 0
+
+typedef struct _chardata {
+ int charid;
+ int fontid; /* TODO: use a SWFFONT instead */
+ int x;
+ int y;
+ int size;
+ RGBA color;
+} chardata_t;
+
+struct fontlist_t
+{
+ SWFFONT *swffont;
+ fontlist_t*next;
+};
+
+double config_ppmsubpixels=0;
+double config_jpegsubpixels=0;
+int config_opennewwindow=0;
+int config_ignoredraworder=0;
+int config_drawonlyshapes=0;
+int config_jpegquality=85;
+int config_storeallcharacters=0;
+int config_enablezlib=0;
+int config_insertstoptag=0;
+int config_flashversion=5;
+int config_splinemaxerror=1;
+int config_fontsplinemaxerror=1;
+int config_filloverlap=0;
+int config_protect=0;
+float config_minlinewidth=0.05;
+double config_caplinewidth=1;
+
+typedef struct _swfoutput_internal
+{
+ swfoutput*obj; // the swfoutput object where this internal struct resides
+
+ SWF swf;
+
+ fontlist_t* fontlist;
+
+ char storefont;
+
+ MATRIX page_matrix;
+
+ TAG *tag;
+ int currentswfid;
+ int depth;
+ int startdepth;
+ int linewidth;
+
+ SHAPE* shape;
+ int shapeid;
+ int textid;
+
+ int fillstyleid;
+ int linestyleid;
+ int swflastx;
+ int swflasty;
+ int lastwasfill;
+ int shapeisempty;
+ char fill;
+ int min_x,max_x;
+ int min_y,max_y;
+ TAG* cliptags[128];
+ int clipshapes[128];
+ U32 clipdepths[128];
+ int clippos;
+
+ /* image cache */
+ int pic_xids[1024];
+ int pic_yids[1024];
+ int pic_ids[1024];
+ int pic_width[1024];
+ int pic_height[1024];
+ int picpos;
+
+ int frameno;
+ int lastframeno;
+
+ char fillstylechanged;
+
+ int jpeg; //next image type
+
+ int bboxrectpos;
+ SRECT bboxrect;
+
+ TAG*cliptag;
+
+ chardata_t chardata[CHARDATAMAX];
+ int chardatapos;
+ int firstpage;
+ char pagefinished;
+
+ /* during the transition to the gfxdevice interface:
+ a device which uses this swfoutput as target */
+ gfxdevice_t device;
+
+} swfoutput_internal;
+
+void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
+int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
+void swf_drawstroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit);
+void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
+void swf_endclip(gfxdevice_t*dev);
+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);
+void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
+void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
+void swf_fillgradient(gfxdevice_t*dev, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
+
+static swfoutput_internal* init_internal_struct()
+{
+ swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
+ memset(i, 0, sizeof(swfoutput_internal));
+
+ i->storefont = 0;
+ i->currentswfid = 0;
+ i->depth = 0;
+ i->startdepth = 0;
+ i->linewidth = 0;
+ i->shapeid = -1;
+ i->textid = -1;
+ i->frameno = 0;
+ i->lastframeno = 0;
+
+ i->fillstyleid;
+ i->linestyleid;
+ i->swflastx=0;
+ i->swflasty=0;
+ i->lastwasfill = 0;
+ i->shapeisempty = 1;
+ i->fill = 0;
+ i->clippos = 0;
+
+ i->fillstylechanged = 0;
+
+ i->bboxrectpos = -1;
+ i->chardatapos = 0;
+ i->firstpage = 1;
+ i->pagefinished = 1;
+
+ i->device.internal = (void*)i;
+ i->device.fillbitmap = swf_fillbitmap;
+ i->device.setparameter = swf_setparameter;
+ i->device.stroke = swf_stroke;
+ i->device.startclip = swf_startclip;
+ i->device.endclip = swf_endclip;
+ i->device.fill = swf_fill;
+ i->device.fillbitmap = swf_fillbitmap;
+ i->device.fillgradient = swf_fillgradient;
+
+ return i;
+};
+
+static int id_error = 0;
+
+static U16 getNewID(struct swfoutput* obj)
+{
+ swfoutput_internal*i = (swfoutput_internal*)obj->internal;
+ if(i->currentswfid == 65535) {
+ if(!id_error)
+ msg("<error> ID Table overflow");
+ id_error=1;
+ }
+ return ++i->currentswfid;
+}
+
+static void startshape(struct swfoutput* obj);
+static void starttext(struct swfoutput* obj);
+static void endshape(struct swfoutput* obj);
+static void endtext(struct swfoutput* obj);