+//#define NORMALIZE_POLYGON_POSITIONS
+
+static 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;
+ int type = gfxline_type(line);
+ int has_dots = gfxline_has_dots(line);
+ gfxbbox_t r = gfxline_getbbox(line);
+ int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
+
+ /* TODO: * split line into segments, and perform this check for all segments */
+
+ if(!has_dots &&
+ (width <= i->config_caplinewidth
+ || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
+ || (cap_style == gfx_capRound && type<=2))) {} else
+ {
+ /* convert line to polygon */
+ msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
+ if(has_dots)
+ gfxline_fix_short_edges(line);
+ /* 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);
+ free(gfxline);
+ art_svp_free(svp);
+ return;
+ }
+
+ msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
+ endtext(dev);
+
+#ifdef NORMALIZE_POLYGON_POSITIONS
+ endshape(dev);
+ double startx = 0, starty = 0;
+ if(line && line->type == gfx_moveTo) {
+ startx = line->x;
+ starty = line->y;
+ }
+ line = gfxline_move(line, -startx, -starty);
+ i->shapeposx = (int)(startx*20);
+ i->shapeposy = (int)(starty*20);
+#endif
+
+ swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a);
+ swfoutput_setlinewidth(dev, width);
+ startshape(dev);
+ stopFill(dev);
+ drawgfxline(dev, line);
+
+#ifdef NORMALIZE_POLYGON_POSITIONS
+ free(line); //account for _move
+#endif
+
+}
+static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ gfxbbox_t r = gfxline_getbbox(line);
+ int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
+
+ endtext(dev);
+ if(!i->config_ignoredraworder)
+ endshape(dev);
+
+#ifdef NORMALIZE_POLYGON_POSITIONS
+ endshape(dev);
+ double startx = 0, starty = 0;
+ if(line && line->type == gfx_moveTo) {
+ startx = line->x;
+ starty = line->y;
+ }
+ line = gfxline_move(line, -startx, -starty);
+ i->shapeposx = (int)(startx*20);
+ i->shapeposy = (int)(starty*20);
+#endif
+
+ swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a);
+ startshape(dev);
+ startFill(dev);
+ i->fill=1;
+ drawgfxline(dev, line);
+ msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
+
+#ifdef NORMALIZE_POLYGON_POSITIONS
+ free(line); //account for _move
+#endif
+}
+static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
+{
+ msg("<error> Gradient filling not implemented yet");
+}
+
+static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
+{
+ SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
+ int t;
+ swffont->id = -1;
+ swffont->version = 2;
+ swffont->name = (U8*)strdup(id);
+ swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
+ swffont->layout->ascent = 0; /* ? */
+ swffont->layout->descent = 0;
+ swffont->layout->leading = 0;
+ swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
+ swffont->encoding = FONT_ENCODING_UNICODE;
+ swffont->numchars = font->num_glyphs;
+ swffont->maxascii = font->max_unicode;
+ swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
+ swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
+ swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
+ swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
+ for(t=0;t<font->max_unicode;t++) {
+ swffont->ascii2glyph[t] = font->unicode2glyph[t];
+ }
+ for(t=0;t<font->num_glyphs;t++) {
+ drawer_t draw;
+ gfxline_t*line;
+ swffont->glyph2ascii[t] = font->glyphs[t].unicode;
+ if(font->glyphs[t].name) {
+ swffont->glyphnames[t] = strdup(font->glyphs[t].name);
+ } else {
+ swffont->glyphnames[t] = 0;
+ }
+ swffont->glyph[t].advance = (int)(font->glyphs[t].advance * 20);
+
+ swf_Shape01DrawerInit(&draw, 0);
+ line = font->glyphs[t].line;
+ while(line) {
+ FPOINT c,to;
+ c.x = line->sx; c.y = line->sy;
+ to.x = line->x; to.y = line->y;
+ if(line->type == gfx_moveTo) {
+ draw.moveTo(&draw, &to);
+ } else if(line->type == gfx_lineTo) {
+ draw.lineTo(&draw, &to);
+ } else if(line->type == gfx_splineTo) {
+ draw.splineTo(&draw, &c, &to);
+ }
+ line = line->next;