2 Implements generation of swf files using the rfxswf lib. The routines
3 in this file are called from pdf2swf.
5 This file is part of swftools.
7 Swftools is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Swftools is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with swftools; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "../config.h"
33 #include "swfoutput.h"
36 #include "../lib/log.h"
37 #include "../lib/rfxswf.h"
38 #include "../lib/gfxdevice.h"
39 #include "../lib/gfxtools.h"
41 #include "../lib/art/libart.h"
43 #define CHARDATAMAX 8192
47 typedef struct _chardata {
49 int fontid; /* TODO: use a SWFFONT instead */
62 double config_ppmsubpixels=0;
63 double config_jpegsubpixels=0;
64 int config_opennewwindow=1;
65 int config_ignoredraworder=0;
66 int config_drawonlyshapes=0;
67 int config_jpegquality=85;
68 int config_storeallcharacters=0;
69 int config_enablezlib=0;
70 int config_insertstoptag=0;
71 int config_flashversion=5;
72 int config_splinemaxerror=1;
73 int config_fontsplinemaxerror=1;
74 int config_filloverlap=0;
76 float config_minlinewidth=0.05;
77 double config_caplinewidth=1;
79 typedef struct _swfoutput_internal
81 swfoutput*obj; // the swfoutput object where this internal struct resides
120 int pic_height[1024];
126 char fillstylechanged;
128 int jpeg; //next image type
135 chardata_t chardata[CHARDATAMAX];
142 /* during the transition to the gfxdevice interface:
143 a device which uses this swfoutput as target */
146 } swfoutput_internal;
148 void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
149 int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
150 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);
151 void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
152 void swf_endclip(gfxdevice_t*dev);
153 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);
154 void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
155 void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
156 void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
158 static swfoutput_internal* init_internal_struct()
160 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
161 memset(i, 0, sizeof(swfoutput_internal));
183 i->fillstylechanged = 0;
190 i->device.internal = (void*)i;
191 i->device.fillbitmap = swf_fillbitmap;
192 i->device.setparameter = swf_setparameter;
193 i->device.stroke = swf_stroke;
194 i->device.startclip = swf_startclip;
195 i->device.endclip = swf_endclip;
196 i->device.fill = swf_fill;
197 i->device.fillbitmap = swf_fillbitmap;
198 i->device.fillgradient = swf_fillgradient;
203 static int id_error = 0;
205 static U16 getNewID(struct swfoutput* obj)
207 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
208 if(i->currentswfid == 65535) {
210 msg("<error> ID Table overflow");
214 return ++i->currentswfid;
216 static U16 getNewDepth(struct swfoutput* obj)
218 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
219 if(i->depth == 65535) {
221 msg("<error> Depth Table overflow");
228 static void startshape(struct swfoutput* obj);
229 static void starttext(struct swfoutput* obj);
230 static void endshape(struct swfoutput* obj);
231 static void endtext(struct swfoutput* obj);
233 // matrix multiplication. changes p0
234 static void transform (plotxy*p0,struct swfmatrix*m)
237 x = m->m11*p0->x+m->m12*p0->y;
238 y = m->m21*p0->x+m->m22*p0->y;
243 // write a move-to command into the swf
244 static int moveto(struct swfoutput*obj, TAG*tag, plotxy p0)
246 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
247 int rx = (int)(p0.x*20);
248 int ry = (int)(p0.y*20);
249 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
250 swf_ShapeSetMove (tag, i->shape, rx,ry);
251 i->fillstylechanged = 0;
258 static int moveto(struct swfoutput*obj, TAG*tag, double x, double y)
260 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
264 return moveto(obj, tag, p);
266 static void addPointToBBox(struct swfoutput*obj, int px, int py)
268 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
274 swf_ExpandRect(&i->bboxrect, p);
276 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
280 /*static void plot(struct swfoutput*obj, int x, int y, TAG*tag)
282 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
283 int width = i->linewidth/4;
287 //swf_ShapeSetLine(tag, i->shape,-width,-width);
288 //swf_ShapeSetLine(tag, i->shape,width*2,0);
289 //swf_ShapeSetLine(tag, i->shape,0,width*2);
290 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
291 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
292 //swf_ShapeSetLine(tag, i->shape,width,width);
295 swf_ShapeSetLine(tag, i->shape,-width,0);
296 swf_ShapeSetLine(tag, i->shape,width,-width);
297 swf_ShapeSetLine(tag, i->shape,width,width);
298 swf_ShapeSetLine(tag, i->shape,-width,width);
299 swf_ShapeSetLine(tag, i->shape,-width,-width);
300 swf_ShapeSetLine(tag, i->shape,width,0);
302 addPointToBBox(obj, x-width ,y-width);
303 addPointToBBox(obj, x+width ,y+width);
306 // write a line-to command into the swf
307 static void lineto(struct swfoutput*obj, TAG*tag, plotxy p0)
309 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
310 int px = (int)(p0.x*20);
311 int py = (int)(p0.y*20);
312 int rx = (px-i->swflastx);
313 int ry = (py-i->swflasty);
315 swf_ShapeSetLine (tag, i->shape, rx,ry);
316 addPointToBBox(obj, i->swflastx,i->swflasty);
317 addPointToBBox(obj, px,py);
318 }/* else if(!i->fill) {
319 // treat lines of length 0 as plots, making them
320 // at least 1 twip wide so Flash will display them
321 plot(obj, i->swflastx, i->swflasty, tag);
328 static void lineto(struct swfoutput*obj, TAG*tag, double x, double y)
336 // write a spline-to command into the swf
337 static void splineto(struct swfoutput*obj, TAG*tag, plotxy control,plotxy end)
339 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
340 int lastlastx = i->swflastx;
341 int lastlasty = i->swflasty;
343 int cx = ((int)(control.x*20)-i->swflastx);
344 int cy = ((int)(control.y*20)-i->swflasty);
347 int ex = ((int)(end.x*20)-i->swflastx);
348 int ey = ((int)(end.y*20)-i->swflasty);
352 if(cx || cy || ex || ey) {
353 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
354 addPointToBBox(obj, lastlastx ,lastlasty );
355 addPointToBBox(obj, lastlastx+cx,lastlasty+cy);
356 addPointToBBox(obj, lastlastx+cx+ex,lastlasty+cy+ey);
357 }/* else if(!i->fill) {
358 // treat splines of length 0 as plots
359 plot(obj, lastlastx, lastlasty, tag);
364 /* write a line, given two points and the transformation
366 /*static void line(struct swfoutput*obj, TAG*tag, plotxy p0, plotxy p1)
368 moveto(obj, tag, p0);
369 lineto(obj, tag, p1);
372 void resetdrawer(struct swfoutput*obj)
374 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
379 static void stopFill(struct swfoutput*obj)
381 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
384 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
385 i->fillstylechanged = 1;
389 static void startFill(struct swfoutput*obj)
391 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
394 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
395 i->fillstylechanged = 1;
400 /* draw an outline. These are generated by pdf2swf and by t1lib
401 (representing characters). */
402 /*void drawpath(struct swfoutput*obj, SWF_OUTLINE*outline, struct swfmatrix*m, int log)
404 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
405 if( i->tag->id != ST_DEFINESHAPE &&
406 i->tag->id != ST_DEFINESHAPE2 &&
407 i->tag->id != ST_DEFINESHAPE3)
409 msg("<error> internal error: drawpath needs a shape tag, not %d\n",i->tag->id);
413 double lastx=0,lasty=0;
414 double firstx=0,firsty=0;
419 x += (outline->dest.x/(float)0xffff);
420 y += (outline->dest.y/(float)0xffff);
421 if(outline->type == SWF_PATHTYPE_MOVE)
423 //if(!init && fill && obj->drawmode != DRAWMODE_EOFILL && !ignoredraworder)
424 if(config_filloverlap && !init && i->fill && obj->drawmode != DRAWMODE_EOFILL) {
425 // drawmode=FILL (not EOFILL) means that
426 // seperate shapes do not cancel each other out.
427 // On SWF side, we need to start a new shape for each
428 // closed polygon, because SWF only knows EOFILL.
435 if(((int)(lastx*20) != (int)(firstx*20) ||
436 (int)(lasty*20) != (int)(firsty*20)) &&
445 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
446 line(obj,i->tag, p0, p1);
452 else if(outline->type == SWF_PATHTYPE_LINE)
460 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
461 line(obj,i->tag, p0,p1);
464 msg("<error> drawpath: unknown outline type:%d\n", outline->type);
468 outline = outline->link;
470 if(((int)(lastx*20) != (int)(firstx*20) ||
471 (int)(lasty*20) != (int)(firsty*20)) &&
480 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
481 line(obj, i->tag, p0, p1);
485 static inline int colorcompare(struct swfoutput*obj, RGBA*a,RGBA*b)
497 static SRECT getcharacterbbox(struct swfoutput*obj, SWFFONT*font)
499 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
502 memset(&r, 0, sizeof(r));
505 if(debug) printf("\n");
506 for(t=0;t<i->chardatapos;t++)
508 if(i->chardata[t].fontid != font->id) {
509 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
512 SRECT b = font->layout->bounds[i->chardata[t].charid];
513 b.xmin *= i->chardata[t].size;
514 b.ymin *= i->chardata[t].size;
515 b.xmax *= i->chardata[t].size;
516 b.ymax *= i->chardata[t].size;
521 b.xmin += i->chardata[t].x;
522 b.ymin += i->chardata[t].y;
523 b.xmax += i->chardata[t].x;
524 b.ymax += i->chardata[t].y;
526 /* until we solve the INTERNAL_SCALING problem (see below)
527 make sure the bounding box is big enough */
533 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
534 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
535 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
536 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
537 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
542 i->chardata[t].fontid,
544 i->chardata[t].charid
546 swf_ExpandRect2(&r, &b);
548 if(debug) printf("-----> (%f,%f,%f,%f)\n",
556 static void putcharacters(struct swfoutput*obj, TAG*tag)
558 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
562 color.r = i->chardata[0].color.r^255;
571 int charadvance[128];
574 int glyphbits=1; //TODO: can this be zero?
577 if(tag->id != ST_DEFINETEXT &&
578 tag->id != ST_DEFINETEXT2) {
579 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
582 if(!i->chardatapos) {
583 msg("<warning> putcharacters called with zero characters");
586 for(pass = 0; pass < 2; pass++)
596 advancebits++; // add sign bit
597 swf_SetU8(tag, glyphbits);
598 swf_SetU8(tag, advancebits);
601 for(t=0;t<=i->chardatapos;t++)
603 if(lastfontid != i->chardata[t].fontid ||
604 lastx!=i->chardata[t].x ||
605 lasty!=i->chardata[t].y ||
606 !colorcompare(obj,&color, &i->chardata[t].color) ||
608 lastsize != i->chardata[t].size ||
611 if(charstorepos && pass==0)
614 for(s=0;s<charstorepos;s++)
616 while(charids[s]>=(1<<glyphbits))
618 while(charadvance[s]>=(1<<advancebits))
622 if(charstorepos && pass==1)
624 tag->writeBit = 0; // Q&D
625 swf_SetBits(tag, 0, 1); // GLYPH Record
626 swf_SetBits(tag, charstorepos, 7); // number of glyphs
628 for(s=0;s<charstorepos;s++)
630 swf_SetBits(tag, charids[s], glyphbits);
631 swf_SetBits(tag, charadvance[s], advancebits);
636 if(pass == 1 && t<i->chardatapos)
642 if(lastx != i->chardata[t].x ||
643 lasty != i->chardata[t].y)
645 newx = i->chardata[t].x;
646 newy = i->chardata[t].y;
652 if(!colorcompare(obj,&color, &i->chardata[t].color))
654 color = i->chardata[t].color;
657 font.id = i->chardata[t].fontid;
658 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
661 tag->writeBit = 0; // Q&D
662 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
665 lastfontid = i->chardata[t].fontid;
666 lastx = i->chardata[t].x;
667 lasty = i->chardata[t].y;
668 lastsize = i->chardata[t].size;
671 if(t==i->chardatapos)
675 int nextt = t==i->chardatapos-1?t:t+1;
676 int rel = i->chardata[nextt].x-i->chardata[t].x;
677 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
679 lastx=i->chardata[nextt].x;
683 lastx=i->chardata[t].x;
685 charids[charstorepos] = i->chardata[t].charid;
686 charadvance[charstorepos] = advance;
693 static void putcharacter(struct swfoutput*obj, int fontid, int charid, int x,int y, int size, RGBA color)
695 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
696 if(i->chardatapos == CHARDATAMAX)
698 msg("<warning> Character buffer too small. SWF will be slightly bigger");
702 i->chardata[i->chardatapos].fontid = fontid;
703 i->chardata[i->chardatapos].charid = charid;
704 i->chardata[i->chardatapos].x = x;
705 i->chardata[i->chardatapos].y = y;
706 i->chardata[i->chardatapos].color = color;
707 i->chardata[i->chardatapos].size = size;
711 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
712 So if we set this value to high, the char coordinates will overflow.
713 If we set it to low, however, the char positions will be inaccurate */
714 #define FONT_INTERNAL_SIZE 4
716 /* process a character. */
717 static int drawchar(struct swfoutput*obj, SWFFONT *swffont, char*character, int charnr, int u, swfmatrix*m, gfxcolor_t*col)
719 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
721 msg("<warning> Font is NULL");
725 int charid = getCharID(swffont, charnr, character, u);
728 msg("<warning> Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)",
729 FIXNULL(character),charnr, u, FIXNULL((char*)swffont->name), swffont->numchars);
732 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
733 msg("<warning> Character '%s' (c=%d,u=%d), glyph %d in current charset (%s, %d characters) is empty",
734 FIXNULL(character),charnr, u, charid, FIXNULL((char*)swffont->name), swffont->numchars);
746 float det = ((m->m11*m->m22)-(m->m21*m->m12));
747 if(fabs(det) < 0.0005) {
748 /* x direction equals y direction- the text is invisible */
751 det = 20*FONT_INTERNAL_SIZE / det;
754 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
755 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
757 RGBA rgba = *(RGBA*)col;
758 putcharacter(obj, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
759 swf_FontUseGlyph(swffont, charid);
764 SWF_OUTLINE*outline = font->getOutline(character, charnr);
765 char* charname = character;
768 msg("<warning> Didn't find character '%s' (%d) in current charset (%s)",
769 FIXNULL(character),charnr,FIXNULL(font->getName()));
788 drawpath(tag, outline, &m2, 0);
793 static void endtext(swfoutput*obj)
795 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
799 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
800 swf_SetU16(i->tag, i->textid);
803 r = getcharacterbbox(obj, obj->swffont);
805 swf_SetRect(i->tag,&r);
808 swf_GetMatrix(0, &m); /* set unit matrix- the real matrix is in the placeobject */
809 swf_SetMatrix(i->tag,&m);
811 msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
813 putcharacters(obj, i->tag);
815 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
817 swf_MatrixJoin(&m2,&obj->fontmatrix, &i->page_matrix);
819 swf_ObjectPlace(i->tag,i->textid,getNewDepth(obj),&m2,NULL,NULL);
823 int getCharID(SWFFONT *font, int charnr, char *charname, int u)
826 if(charname && font->glyphnames) {
827 for(t=0;t<font->numchars;t++) {
828 if(font->glyphnames[t] && !strcmp(font->glyphnames[t],charname)) {
829 msg("<debug> Char [%d,>%s<,%d] maps to %d\n", charnr, charname, u, t);
833 /* if we didn't find the character, maybe
834 we can find the capitalized version */
835 for(t=0;t<font->numchars;t++) {
836 if(font->glyphnames[t] && !strcasecmp(font->glyphnames[t],charname)) {
837 msg("<debug> Char [%d,>>%s<<,%d] maps to %d\n", charnr, charname, u, t);
843 if(u>0 && font->encoding != 255) {
844 /* try to use the unicode id */
845 if(u>=0 && u<font->maxascii && font->ascii2glyph[u]>=0) {
846 msg("<debug> Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->ascii2glyph[u]);
847 return font->ascii2glyph[u];
851 if(font->encoding != FONT_ENCODING_UNICODE) {
852 /* the following only works if the font encoding
853 is US-ASCII based. It's needed for fonts which return broken unicode
855 if(charnr>=0 && charnr<font->maxascii && font->ascii2glyph[charnr]>=0) {
856 msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, font->ascii2glyph[charnr]);
857 return font->ascii2glyph[charnr];
861 if(charnr>=0 && charnr<font->numchars) {
862 msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr);
870 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
871 void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename)
873 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
874 fontlist_t*last=0,*iterator;
876 msg("<error> No fontid");
880 if(obj->swffont && obj->swffont->name && !strcmp((char*)obj->swffont->name,fontid))
883 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
884 with multiple fonts */
887 iterator = i->fontlist;
889 if(!strcmp((char*)iterator->swffont->name,fontid)) {
890 obj->swffont = iterator->swffont;
894 iterator = iterator->next;
898 msg("<error> No filename given for font- internal error?");
902 swf_SetLoadFontParameters(64,/*skip unused*/0,/*full unicode*/1);
903 SWFFONT*swffont = swf_LoadFont(filename);
906 msg("<warning> Couldn't load font %s (%s)", fontid, filename);
907 swffont = swf_LoadFont(0);
910 if(swffont->glyph2ascii) {
913 /* check whether the Unicode indices look o.k.
914 If they don't, disable the unicode lookup by setting
915 the encoding to 255 */
916 for(t=0;t<swffont->numchars;t++) {
917 int c = swffont->glyph2ascii[t];
918 if(c && c < 32 && swffont->glyph[t].shape->bitlen > 16) {
919 // the character maps into the unicode control character range
920 // between 0001-001f. Yet it is not empty. Treat the one
921 // mapping as broken, and look how many of those we find.
926 msg("<warning> Font %s has bad unicode mapping", fontid);
927 swffont->encoding = 255;
931 swf_FontSetID(swffont, getNewID(obj));
933 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
934 // print font information
935 msg("<debug> Font %s (%s)",fontid, filename);
936 msg("<debug> | ID: %d", swffont->id);
937 msg("<debug> | Version: %d", swffont->version);
938 msg("<debug> | Name: %s", swffont->name);
939 msg("<debug> | Numchars: %d", swffont->numchars);
940 msg("<debug> | Maxascii: %d", swffont->maxascii);
941 msg("<debug> | Style: %d", swffont->style);
942 msg("<debug> | Encoding: %d", swffont->encoding);
943 for(int iii=0; iii<swffont->numchars;iii++) {
944 msg("<debug> | Glyph %d) name=%s, unicode=%d size=%d bbox=(%.2f,%.2f,%.2f,%.2f)\n", iii, swffont->glyphnames?swffont->glyphnames[iii]:"<nonames>", swffont->glyph2ascii[iii], swffont->glyph[iii].shape->bitlen,
945 swffont->layout->bounds[iii].xmin/20.0,
946 swffont->layout->bounds[iii].ymin/20.0,
947 swffont->layout->bounds[iii].xmax/20.0,
948 swffont->layout->bounds[iii].ymax/20.0
951 for(t=0;t<swffont->maxascii;t++) {
952 if(swffont->ascii2glyph[t] == iii)
953 msg("<debug> | - maps to %d",t);
958 /* set the font name to the ID we use here */
959 if(swffont->name) free(swffont->name);
960 swffont->name = (U8*)strdup(fontid);
962 iterator = new fontlist_t;
963 iterator->swffont = swffont;
967 last->next = iterator;
969 i->fontlist = iterator;
971 obj->swffont = swffont;
974 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
976 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
977 fontlist_t *iterator = i->fontlist;
979 if(!strcmp((char*)iterator->swffont->name,fontid))
981 iterator = iterator->next;
986 /* set's the matrix which is to be applied to characters drawn by
987 swfoutput_drawchar() */
988 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
989 double m21,double m22)
991 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
992 if(obj->fontm11 == m11 &&
993 obj->fontm12 == m12 &&
994 obj->fontm21 == m21 &&
1005 m.sx = (U32)(((obj->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((obj->fontm12)*65536)/FONT_INTERNAL_SIZE);
1006 m.r0 = (U32)(((obj->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((obj->fontm22)*65536)/FONT_INTERNAL_SIZE);
1009 obj->fontmatrix = m;
1012 /* draws a character at x,y. */
1013 int swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr, int u, gfxcolor_t* color)
1015 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1017 m.m11 = obj->fontm11;
1018 m.m12 = obj->fontm12;
1019 m.m21 = obj->fontm21;
1020 m.m22 = obj->fontm22;
1023 return drawchar(obj, obj->swffont, character, charnr, u, &m, color);
1026 static void endpage(struct swfoutput*obj)
1028 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1034 swfoutput_endclip(obj);
1035 i->pagefinished = 1;
1038 void swfoutput_pagefeed(struct swfoutput*obj)
1040 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1042 if(!i->pagefinished)
1045 if(config_insertstoptag) {
1047 atag = action_Stop(atag);
1048 atag = action_End(atag);
1049 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
1050 swf_ActionSet(i->tag,atag);
1052 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
1055 for(i->depth;i->depth>i->startdepth;i->depth--) {
1056 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
1057 swf_SetU16(i->tag,i->depth);
1059 i->depth = i->startdepth;
1062 static void setBackground(struct swfoutput*obj, int x1, int y1, int x2, int y2)
1064 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1066 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
1070 int shapeid = getNewID(obj);
1075 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
1077 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
1078 swf_SetU16(i->tag,shapeid);
1079 swf_SetRect(i->tag,&r);
1080 swf_SetShapeHeader(i->tag,s);
1081 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
1082 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
1083 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
1084 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
1085 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
1086 swf_ShapeSetEnd(i->tag);
1088 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
1089 swf_ObjectPlace(i->tag,shapeid,getNewDepth(obj),0,0,0);
1090 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
1091 swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(obj),0,0,0,65535);
1092 i->cliptag = i->tag;
1095 void swfoutput_newpage(struct swfoutput*obj, int pageNum, int movex, int movey, int x1, int y1, int x2, int y2)
1097 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1098 if(!i->firstpage && !i->pagefinished)
1101 swf_GetMatrix(0, &i->page_matrix);
1102 i->page_matrix.tx = movex*20;
1103 i->page_matrix.ty = movey*20;
1105 if(i->cliptag && i->frameno == i->lastframeno) {
1107 swf_GetPlaceObject(i->cliptag, &obj);
1108 obj.clipdepth = i->depth;
1109 swf_ResetTag(i->cliptag, i->cliptag->id);
1110 swf_SetPlaceObject(i->cliptag, &obj);
1111 swf_PlaceObjectFree(&obj);
1119 msg("<notice> processing page %d (%dx%d:%d:%d)", pageNum,x2-x1,y2-y1, x1, y1);
1121 x1*=20;y1*=20;x2*=20;y2*=20;
1123 /* set clipping/background rectangle */
1124 /* TODO: this should all be done in SWFOutputDev */
1125 setBackground(obj, x1, y1, x2, y2);
1127 /* increase SWF's bounding box */
1133 swf_ExpandRect2(&i->swf.movieSize, &r);
1135 i->lastframeno = i->frameno;
1137 i->pagefinished = 0;
1140 /* initialize the swf writer */
1141 void swfoutput_init(struct swfoutput* obj)
1143 memset(obj, 0, sizeof(struct swfoutput));
1144 obj->internal = init_internal_struct();
1145 ((swfoutput_internal*)obj->internal)->obj = obj;
1147 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1152 msg("<verbose> initializing swf output for size %d*%d\n", i->max_x,i->max_y);
1156 memset(&i->swf,0x00,sizeof(SWF));
1158 i->swf.fileVersion = config_flashversion;
1159 i->swf.frameRate = 0x0040; // 1 frame per 4 seconds
1160 i->swf.movieSize.xmin = 0;
1161 i->swf.movieSize.ymin = 0;
1162 i->swf.movieSize.xmax = 0;
1163 i->swf.movieSize.ymax = 0;
1165 i->swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
1166 i->tag = i->swf.firstTag;
1167 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
1168 swf_SetRGB(i->tag,&rgb);
1170 i->startdepth = i->depth = 0;
1173 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1176 static void startshape(struct swfoutput*obj)
1178 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1187 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
1189 swf_ShapeNew(&i->shape);
1190 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&obj->strokergb);
1191 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&obj->fillrgb);
1193 i->shapeid = getNewID(obj);
1195 msg("<debug> Using shape id %d", i->shapeid);
1197 swf_SetU16(i->tag,i->shapeid); // ID
1199 i->bboxrectpos = i->tag->len;
1203 r.xmax = 20*i->max_x;
1204 r.ymax = 20*i->max_y;
1205 swf_SetRect(i->tag,&r);
1207 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
1209 swf_SetShapeStyles(i->tag,i->shape);
1210 swf_ShapeCountBits(i->shape,NULL,NULL);
1211 swf_SetShapeBits(i->tag,i->shape);
1213 /* TODO: do we really need this? */
1214 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
1215 i->swflastx=i->swflasty=0;
1217 i->shapeisempty = 1;
1220 static void starttext(struct swfoutput*obj)
1222 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1226 i->textid = getNewID(obj);
1228 i->swflastx=i->swflasty=0;
1232 /* TODO: move to ../lib/rfxswf */
1233 void changeRect(struct swfoutput*obj, TAG*tag, int pos, SRECT*newrect)
1235 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1236 /* determine length of old rect */
1240 swf_GetRect(tag, &old);
1241 swf_ResetReadBits(tag);
1242 int pos_end = tag->pos;
1244 int len = tag->len - pos_end;
1245 U8*data = (U8*)malloc(len);
1246 memcpy(data, &tag->data[pos_end], len);
1249 swf_SetRect(tag, newrect);
1250 swf_SetBlock(tag, data, len);
1252 tag->pos = tag->readBit = 0;
1255 void cancelshape(swfoutput*obj)
1257 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1258 /* delete old shape tag */
1260 i->tag = i->tag->prev;
1261 swf_DeleteTag(todel);
1262 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
1264 i->bboxrectpos = -1;
1267 void fixAreas(swfoutput*obj)
1269 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1270 if(!i->shapeisempty && i->fill &&
1271 (i->bboxrect.xmin == i->bboxrect.xmax ||
1272 i->bboxrect.ymin == i->bboxrect.ymax) &&
1273 config_minlinewidth >= 0.001
1275 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1276 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1277 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1280 SRECT r = i->bboxrect;
1282 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1283 /* this thing comes down to a single dot- nothing to fix here */
1289 RGBA save_col = obj->strokergb;
1290 int save_width = i->linewidth;
1292 obj->strokergb = obj->fillrgb;
1293 i->linewidth = (int)(config_minlinewidth*20);
1294 if(i->linewidth==0) i->linewidth = 1;
1298 moveto(obj, i->tag, r.xmin/20.0,r.ymin/20.0);
1299 lineto(obj, i->tag, r.xmax/20.0,r.ymax/20.0);
1301 obj->strokergb = save_col;
1302 i->linewidth = save_width;
1307 static void endshape_noput(swfoutput*obj)
1309 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1312 //changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect);
1315 swf_ShapeFree(i->shape);
1321 static void endshape(swfoutput*obj)
1323 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1329 if(i->shapeisempty ||
1331 (i->bboxrect.xmin == i->bboxrect.xmax &&
1332 i->bboxrect.ymin == i->bboxrect.ymax))
1334 // delete the shape again, we didn't do anything
1335 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1336 i->bboxrect.xmin /20.0,
1337 i->bboxrect.ymin /20.0,
1338 i->bboxrect.xmax /20.0,
1339 i->bboxrect.ymax /20.0
1345 swf_ShapeSetEnd(i->tag);
1347 changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect);
1349 msg("<trace> Placing shape id %d", i->shapeid);
1351 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1352 swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(obj),&i->page_matrix,NULL,NULL);
1354 swf_ShapeFree(i->shape);
1357 i->bboxrectpos = -1;
1363 sprintf(text, "id%d", i->shapeid);
1365 points[0].x = i->bboxrect.xmin;
1366 points[0].y = i->bboxrect.ymin;
1367 points[1].x = i->bboxrect.xmax;
1368 points[1].y = i->bboxrect.ymin;
1369 points[2].x = i->bboxrect.xmax;
1370 points[2].y = i->bboxrect.ymax;
1371 points[3].x = i->bboxrect.xmin;
1372 points[3].y = i->bboxrect.ymax;
1373 swfoutput_namedlink(obj,text,points);
1377 void swfoutput_finalize(struct swfoutput*obj)
1379 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1381 if(i->tag && i->tag->id == ST_END)
1382 return; //already done
1384 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1385 swfoutput_pagefeed(obj);
1388 fontlist_t *tmp,*iterator = i->fontlist;
1390 TAG*mtag = i->swf.firstTag;
1391 if(iterator->swffont) {
1392 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1393 /*if(!storeallcharacters)
1394 swf_FontReduce(iterator->swffont);*/
1395 swf_FontSetDefine2(mtag, iterator->swffont);
1398 iterator = iterator->next;
1400 i->tag = swf_InsertTag(i->tag,ST_END);
1401 TAG* tag = i->tag->prev;
1403 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1404 and the ST_END- they confuse the flash player */
1405 while(tag->id == ST_REMOVEOBJECT2) {
1406 TAG* prev = tag->prev;
1416 SWF* swfoutput_get(struct swfoutput*obj)
1418 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1420 swfoutput_finalize(obj);
1422 return swf_CopySWF(&i->swf);
1425 void swfoutput_getdimensions(struct swfoutput*obj, int*x1, int*y1, int*x2, int*y2)
1427 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1428 if(x1) *x1 = i->swf.movieSize.xmin/20;
1429 if(y1) *y1 = i->swf.movieSize.ymin/20;
1430 if(x2) *x2 = i->swf.movieSize.xmax/20;
1431 if(y2) *y2 = i->swf.movieSize.ymax/20;
1434 void wipeSWF(SWF*swf)
1436 TAG*tag = swf->firstTag;
1438 TAG*next = tag->next;
1439 if(tag->id != ST_SETBACKGROUNDCOLOR &&
1440 tag->id != ST_END &&
1441 tag->id != ST_SHOWFRAME) {
1448 int swfoutput_save(struct swfoutput* obj, char*filename)
1450 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1451 swfoutput_finalize(obj);
1455 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1460 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1464 if(config_enablezlib || config_flashversion>=6) {
1465 if FAILED(swf_WriteSWC(fi,&i->swf))
1466 msg("<error> WriteSWC() failed.\n");
1468 if FAILED(swf_WriteSWF(fi,&i->swf))
1469 msg("<error> WriteSWF() failed.\n");
1477 /* Perform cleaning up, complete the swf, and write it out. */
1478 void swfoutput_destroy(struct swfoutput* obj)
1480 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1482 /* not initialized yet- nothing to destroy */
1486 fontlist_t *tmp,*iterator = i->fontlist;
1488 if(iterator->swffont) {
1489 swf_FontFree(iterator->swffont);iterator->swffont=0;
1492 iterator = iterator->next;
1495 swf_FreeTags(&i->swf);
1498 memset(obj, 0, sizeof(swfoutput));
1501 static void swfoutput_setfillcolor(swfoutput* obj, U8 r, U8 g, U8 b, U8 a)
1503 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1504 if(obj->fillrgb.r == r &&
1505 obj->fillrgb.g == g &&
1506 obj->fillrgb.b == b &&
1507 obj->fillrgb.a == a) return;
1517 static void swfoutput_setstrokecolor(swfoutput* obj, U8 r, U8 g, U8 b, U8 a)
1519 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1520 if(obj->strokergb.r == r &&
1521 obj->strokergb.g == g &&
1522 obj->strokergb.b == b &&
1523 obj->strokergb.a == a) return;
1527 obj->strokergb.r = r;
1528 obj->strokergb.g = g;
1529 obj->strokergb.b = b;
1530 obj->strokergb.a = a;
1533 static void swfoutput_setlinewidth(struct swfoutput*obj, double _linewidth)
1535 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1536 if(i->linewidth == (U16)(_linewidth*20))
1541 i->linewidth = (U16)(_linewidth*20);
1545 static void drawlink(struct swfoutput*obj, ActionTAG*,ActionTAG*, swfcoord*points, char mouseover);
1547 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1549 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1551 if(!strncmp("http://pdf2swf:", url, 15)) {
1552 char*tmp = strdup(url);
1553 int l = strlen(tmp);
1556 swfoutput_namedlink(obj, tmp+15, points);
1566 if(!config_opennewwindow)
1567 actions = action_GetUrl(0, url, "_parent");
1569 actions = action_GetUrl(0, url, "_this");
1570 actions = action_End(actions);
1572 drawlink(obj, actions, 0, points,0);
1574 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1576 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1584 actions = action_GotoFrame(0, page);
1585 actions = action_End(actions);
1587 drawlink(obj, actions, 0, points,0);
1590 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1591 of the viewer objects, like subtitles, index elements etc.
1593 void swfoutput_namedlink(struct swfoutput*obj, char*name, swfcoord*points)
1595 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1596 ActionTAG *actions1,*actions2;
1597 char*tmp = strdup(name);
1605 if(!strncmp(tmp, "call:", 5))
1607 char*x = strchr(&tmp[5], ':');
1609 actions1 = action_PushInt(0, 0); //number of parameters (0)
1610 actions1 = action_PushString(actions1, &tmp[5]); //function name
1611 actions1 = action_CallFunction(actions1);
1614 actions1 = action_PushString(0, x+1); //parameter
1615 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1616 actions1 = action_PushString(actions1, &tmp[5]); //function name
1617 actions1 = action_CallFunction(actions1);
1619 actions2 = action_End(0);
1624 actions1 = action_PushString(0, "/:subtitle");
1625 actions1 = action_PushString(actions1, name);
1626 actions1 = action_SetVariable(actions1);
1627 actions1 = action_End(actions1);
1629 actions2 = action_PushString(0, "/:subtitle");
1630 actions2 = action_PushString(actions2, "");
1631 actions2 = action_SetVariable(actions2);
1632 actions2 = action_End(actions2);
1635 drawlink(obj, actions1, actions2, points,mouseover);
1637 swf_ActionFree(actions1);
1638 swf_ActionFree(actions2);
1642 static void drawlink(struct swfoutput*obj, ActionTAG*actions1, ActionTAG*actions2, swfcoord*points, char mouseover)
1644 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1649 struct plotxy p1,p2,p3,p4;
1653 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1657 int buttonid = getNewID(obj);
1660 if(points[t].x>xmax) xmax=points[t].x;
1661 if(points[t].y>ymax) ymax=points[t].y;
1662 if(points[t].x<xmin) xmin=points[t].x;
1663 if(points[t].y<ymin) ymin=points[t].y;
1666 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1667 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1669 /* the following code subtracts the upper left edge from all coordinates,
1670 and set's posx,posy so that ST_PLACEOBJECT is used with a matrix.
1671 Necessary for preprocessing with swfcombine. */
1672 posx = xmin; posy = ymin;
1673 p1.x-=posx;p2.x-=posx;p3.x-=posx;p4.x-=posx;
1674 p1.y-=posy;p2.y-=posy;p3.y-=posy;p4.y-=posy;
1675 xmin -= posx; ymin -= posy;
1676 xmax -= posx; ymax -= posy;
1679 myshapeid = getNewID(obj);
1680 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1681 swf_ShapeNew(&i->shape);
1682 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1683 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1684 swf_SetU16(i->tag, myshapeid);
1685 r.xmin = (int)(xmin*20);
1686 r.ymin = (int)(ymin*20);
1687 r.xmax = (int)(xmax*20);
1688 r.ymax = (int)(ymax*20);
1689 swf_SetRect(i->tag,&r);
1690 swf_SetShapeStyles(i->tag,i->shape);
1691 swf_ShapeCountBits(i->shape,NULL,NULL);
1692 swf_SetShapeBits(i->tag,i->shape);
1693 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1694 i->swflastx = i->swflasty = 0;
1695 moveto(obj, i->tag, p1);
1696 lineto(obj, i->tag, p2);
1697 lineto(obj, i->tag, p3);
1698 lineto(obj, i->tag, p4);
1699 lineto(obj, i->tag, p1);
1700 swf_ShapeSetEnd(i->tag);
1703 myshapeid2 = getNewID(obj);
1704 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1705 swf_ShapeNew(&i->shape);
1706 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1708 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1709 swf_SetU16(i->tag, myshapeid2);
1710 r.xmin = (int)(xmin*20);
1711 r.ymin = (int)(ymin*20);
1712 r.xmax = (int)(xmax*20);
1713 r.ymax = (int)(ymax*20);
1714 swf_SetRect(i->tag,&r);
1715 swf_SetShapeStyles(i->tag,i->shape);
1716 swf_ShapeCountBits(i->shape,NULL,NULL);
1717 swf_SetShapeBits(i->tag,i->shape);
1718 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1719 i->swflastx = i->swflasty = 0;
1720 moveto(obj, i->tag, p1);
1721 lineto(obj, i->tag, p2);
1722 lineto(obj, i->tag, p3);
1723 lineto(obj, i->tag, p4);
1724 lineto(obj, i->tag, p1);
1725 swf_ShapeSetEnd(i->tag);
1729 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1730 swf_SetU16(i->tag,buttonid); //id
1731 swf_ButtonSetFlags(i->tag, 0); //menu=no
1732 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1733 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1734 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1735 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1736 swf_SetU8(i->tag,0);
1737 swf_ActionSet(i->tag,actions1);
1738 swf_SetU8(i->tag,0);
1742 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1743 swf_SetU16(i->tag,buttonid); //id
1744 swf_ButtonSetFlags(i->tag, 0); //menu=no
1745 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1746 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1747 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1748 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1749 swf_SetU8(i->tag,0); // end of button records
1750 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1751 swf_ActionSet(i->tag,actions1);
1753 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1754 swf_ActionSet(i->tag,actions2);
1755 swf_SetU8(i->tag,0);
1756 swf_ButtonPostProcess(i->tag, 2);
1758 swf_SetU8(i->tag,0);
1759 swf_ButtonPostProcess(i->tag, 1);
1763 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1765 if(posx!=0 || posy!=0) {
1767 p.x = (int)(posx*20);
1768 p.y = (int)(posy*20);
1769 p = swf_TurnPoint(p, &i->page_matrix);
1774 swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&m,0,0);
1776 swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&i->page_matrix,0,0);
1783 for(t=0;t<picpos;t++)
1785 if(pic_xids[t] == xid &&
1786 pic_yids[t] == yid) {
1787 width = pic_width[t];
1788 height = pic_height[t];
1792 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1793 pic_xids[picpos] = xid;
1794 pic_yids[picpos] = yid;
1795 pic_width[picpos] = width;
1796 pic_height[picpos] = height;
1799 pic[width*y+x] = buf[0];
1803 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1804 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1808 xid += x*r+x*b*3+x*g*7+x*a*11;
1809 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1811 for(t=0;t<picpos;t++)
1813 if(pic_xids[t] == xid &&
1814 pic_yids[t] == yid) {
1822 static void drawgfxline(struct swfoutput*obj, gfxline_t*line)
1824 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1825 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1830 /* check whether the next segment is zero */
1831 if(line->type == gfx_moveTo) {
1832 msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
1833 moveto(obj, i->tag, line->x, line->y);
1834 px = lastx = line->x;
1835 py = lasty = line->y;
1837 } if(line->type == gfx_lineTo) {
1838 msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
1839 lineto(obj, i->tag, line->x, line->y);
1843 } else if(line->type == gfx_splineTo) {
1844 msg("<trace> ======== splineTo %.2f %.2f", line->x, line->y);
1846 s.x = line->sx;p.x = line->x;
1847 s.y = line->sy;p.y = line->y;
1848 splineto(obj, i->tag, s, p);
1857 void swfoutput_drawgfxline(struct swfoutput*obj, gfxline_t*line, gfxcoord_t width, gfxcolor_t*col, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
1859 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1860 gfxdevice_t*dev = &i->device;
1861 dev->stroke(dev, line, width, col, cap_style, joint_style, miterLimit);
1863 void swfoutput_fillgfxline(struct swfoutput*obj, gfxline_t*line, gfxcolor_t*col)
1865 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1866 gfxdevice_t*dev = &i->device;
1867 dev->fill(dev, line, col);
1869 void swfoutput_startclip(struct swfoutput*obj, gfxline_t*line)
1871 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1872 gfxdevice_t*dev = &i->device;
1873 dev->startclip(dev, line);
1875 void swfoutput_endclip(struct swfoutput*obj)
1877 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1878 gfxdevice_t*dev = &i->device;
1882 #define IMAGE_TYPE_JPEG 0
1883 #define IMAGE_TYPE_LOSSLESS 1
1885 static void swfoutput_drawimage(struct swfoutput*obj, RGBA* data, int sizex,int sizey,
1886 double x1,double y1,
1887 double x2,double y2,
1888 double x3,double y3,
1889 double x4,double y4, int type)
1891 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1895 double l1 = sqrt((x4-x1)*(x4-x1) + (y4-y1)*(y4-y1));
1896 double l2 = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
1898 gfxline_t p1,p2,p3,p4,p5;
1899 p1.type=gfx_moveTo;p1.x=x1; p1.y=y1;p1.next=&p2;
1900 p2.type=gfx_lineTo;p2.x=x2; p2.y=y2;p2.next=&p3;
1901 p3.type=gfx_lineTo;p3.x=x3; p3.y=y3;p3.next=&p4;
1902 p4.type=gfx_lineTo;p4.x=x4; p4.y=y4;p4.next=&p5;
1903 p5.type=gfx_lineTo;p5.x=x1; p5.y=y1;p5.next=0;
1905 {p1.x = (int)(p1.x*20)/20.0;
1906 p1.y = (int)(p1.y*20)/20.0;
1907 p2.x = (int)(p2.x*20)/20.0;
1908 p2.y = (int)(p2.y*20)/20.0;
1909 p3.x = (int)(p3.x*20)/20.0;
1910 p3.y = (int)(p3.y*20)/20.0;
1911 p4.x = (int)(p4.x*20)/20.0;
1912 p4.y = (int)(p4.y*20)/20.0;
1913 p5.x = (int)(p5.x*20)/20.0;
1914 p5.y = (int)(p5.y*20)/20.0;
1921 m.m00 = (p4.x-p1.x)/sizex; m.m10 = (p2.x-p1.x)/sizey;
1922 m.m01 = (p4.y-p1.y)/sizex; m.m11 = (p2.y-p1.y)/sizey;
1927 img.data = (gfxcolor_t*)data;
1931 if(type == IMAGE_TYPE_JPEG)
1932 /* TODO: pass image_dpi to device instead */
1933 i->device.setparameter(&i->device, "next_bitmap_is_jpeg", "1");
1935 i->device.fillbitmap(&i->device, &p1, &img, &m, 0);
1938 void swfoutput_drawimagejpeg(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1939 double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
1941 swfoutput_drawimage(obj,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_JPEG);
1944 void swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1945 double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
1947 swfoutput_drawimage(obj,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_LOSSLESS);
1950 void swfoutput_setparameter(char*name, char*value)
1952 if(!strcmp(name, "jpegsubpixels")) {
1953 config_jpegsubpixels = atof(value);
1954 } else if(!strcmp(name, "ppmsubpixels")) {
1955 config_ppmsubpixels = atof(value);
1956 } else if(!strcmp(name, "drawonlyshapes")) {
1957 config_drawonlyshapes = atoi(value);
1958 } else if(!strcmp(name, "ignoredraworder")) {
1959 config_ignoredraworder = atoi(value);
1960 } else if(!strcmp(name, "filloverlap")) {
1961 config_filloverlap = atoi(value);
1962 } else if(!strcmp(name, "linksopennewwindow")) {
1963 config_opennewwindow = atoi(value);
1964 } else if(!strcmp(name, "opennewwindow")) {
1965 config_opennewwindow = atoi(value);
1966 } else if(!strcmp(name, "storeallcharacters")) {
1967 config_storeallcharacters = atoi(value);
1968 } else if(!strcmp(name, "enablezlib")) {
1969 config_enablezlib = atoi(value);
1970 } else if(!strcmp(name, "insertstop")) {
1971 config_insertstoptag = atoi(value);
1972 } else if(!strcmp(name, "protected")) {
1973 config_protect = atoi(value);
1974 } else if(!strcmp(name, "flashversion")) {
1975 config_flashversion = atoi(value);
1976 } else if(!strcmp(name, "minlinewidth")) {
1977 config_minlinewidth = atof(value);
1978 } else if(!strcmp(name, "caplinewidth")) {
1979 config_caplinewidth = atof(value);
1980 } else if(!strcmp(name, "jpegquality")) {
1981 int val = atoi(value);
1983 if(val>100) val=100;
1984 config_jpegquality = val;
1985 } else if(!strcmp(name, "splinequality")) {
1986 int v = atoi(value);
1987 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1989 config_splinemaxerror = v;
1990 } else if(!strcmp(name, "fontquality")) {
1991 int v = atoi(value);
1992 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1994 config_fontsplinemaxerror = v;
1996 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
2000 // --------------------------------------------------------------------
2002 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
2005 swf_GetCXForm(0, &cx, 1);
2008 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
2009 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
2010 c->br!=0 || c->bg!=0 || c->ba!=0 ||
2011 c->ar!=0 || c->ag!=0 || c->ab!=0)
2012 msg("<warning> CXForm not SWF-compatible");
2014 cx.a0 = (S16)(c->aa*256);
2015 cx.r0 = (S16)(c->rr*256);
2016 cx.g0 = (S16)(c->gg*256);
2017 cx.b0 = (S16)(c->bb*256);
2025 ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
2027 ArtVpath *vec = NULL;
2035 if(l2->type == gfx_moveTo) {
2037 } if(l2->type == gfx_lineTo) {
2039 } if(l2->type == gfx_splineTo) {
2040 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
2041 if(!parts) parts = 1;
2051 vec = art_new (ArtVpath, len);
2056 if(l2->type == gfx_moveTo) {
2057 vec[pos].code = ART_MOVETO;
2062 } else if(l2->type == gfx_lineTo) {
2063 vec[pos].code = ART_LINETO;
2068 } else if(l2->type == gfx_splineTo) {
2070 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
2071 if(!parts) parts = 1;
2072 for(i=0;i<=parts;i++) {
2073 double t = (double)i/(double)parts;
2074 vec[pos].code = ART_LINETO;
2075 vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
2076 vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
2085 vec[pos].code = ART_END;
2087 svp = art_svp_vpath_stroke (vec,
2088 (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
2089 ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
2090 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
2091 (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
2092 ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
2093 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
2095 miterLimit, //miter_limit
2102 gfxline_t* SVPtogfxline(ArtSVP*svp)
2107 for(t=0;t<svp->n_segs;t++) {
2108 size += svp->segs[t].n_points + 1;
2110 gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
2112 for(t=0;t<svp->n_segs;t++) {
2113 ArtSVPSeg* seg = &svp->segs[t];
2115 for(p=0;p<seg->n_points;p++) {
2116 lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
2117 ArtPoint* point = &seg->points[p];
2118 lines[pos].x = point->x;
2119 lines[pos].y = point->y;
2120 lines[pos].next = &lines[pos+1];
2125 lines[pos-1].next = 0;
2133 static int imageInCache(swfoutput*obj, void*data, int width, int height)
2137 static void addImageToCache(swfoutput*obj, void*data, int width, int height)
2141 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
2143 swfoutput*obj = i->obj;
2145 RGBA*mem = (RGBA*)img->data;
2147 int sizex = img->width;
2148 int sizey = img->height;
2149 int is_jpeg = i->jpeg;
2152 int newsizex=sizex, newsizey=sizey;
2155 if(is_jpeg && config_jpegsubpixels) {
2156 newsizex = (int)(targetwidth*config_jpegsubpixels+0.5);
2157 newsizey = (int)(targetheight*config_jpegsubpixels+0.5);
2158 } else if(!is_jpeg && config_ppmsubpixels) {
2159 newsizex = (int)(targetwidth*config_ppmsubpixels+0.5);
2160 newsizey = (int)(targetheight*config_ppmsubpixels+0.5);
2164 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
2167 /* TODO: cache images */
2171 if(newsizex<sizex || newsizey<sizey) {
2172 msg("<notice> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
2173 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
2174 *newwidth = sizex = newsizex;
2175 *newheight = sizey = newsizey;
2180 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
2181 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
2183 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
2185 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
2188 targetwidth, targetheight,
2189 /*newsizex, newsizey,*/
2190 num_colors>256?">":"", num_colors>256?256:num_colors);
2192 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
2193 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
2195 for(t=0;t<num_colors;t++) {
2196 printf("%02x%02x%02x%02x ",
2197 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
2204 int cacheid = imageInCache(obj, mem, sizex, sizey);
2207 bitid = getNewID(obj);
2208 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, config_jpegquality);
2209 addImageToCache(obj, mem, sizex, sizey);
2219 static SRECT gfxline_getSWFbbox(gfxline_t*line)
2221 gfxbbox_t bbox = gfxline_getbbox(line);
2223 r.xmin = (int)(bbox.xmin*20);
2224 r.ymin = (int)(bbox.ymin*20);
2225 r.xmax = (int)(bbox.xmax*20);
2226 r.ymax = (int)(bbox.ymax*20);
2230 void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
2232 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2233 swfoutput*obj = i->obj;
2238 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
2239 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
2241 int newwidth=0,newheight=0;
2242 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
2245 double fx = (double)img->width / (double)newwidth;
2246 double fy = (double)img->height / (double)newheight;
2251 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
2252 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
2253 m.tx = (int)(matrix->tx*20);
2254 m.ty = (int)(matrix->ty*20);
2257 int myshapeid = getNewID(obj);
2258 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2260 swf_ShapeNew(&shape);
2261 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
2262 swf_SetU16(i->tag, myshapeid);
2263 SRECT r = gfxline_getSWFbbox(line);
2264 swf_SetRect(i->tag,&r);
2265 swf_SetShapeStyles(i->tag,shape);
2266 swf_ShapeCountBits(shape,NULL,NULL);
2267 swf_SetShapeBits(i->tag,shape);
2268 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2269 i->swflastx = i->swflasty = UNDEFINED_COORD;
2270 drawgfxline(obj, line);
2271 swf_ShapeSetEnd(i->tag);
2272 swf_ShapeFree(shape);
2274 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2275 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
2276 swf_ObjectPlace(i->tag,myshapeid,getNewDepth(obj),&i->page_matrix,&cxform2,NULL);
2279 void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
2281 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2282 swfoutput*obj = i->obj;
2287 if(i->clippos >= 127)
2289 msg("<warning> Too many clip levels.");
2293 int myshapeid = getNewID(obj);
2294 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2296 memset(&col, 0, sizeof(RGBA));
2298 swf_ShapeNew(&shape);
2299 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2300 swf_SetU16(i->tag,myshapeid);
2301 SRECT r = gfxline_getSWFbbox(line);
2302 swf_SetRect(i->tag,&r);
2303 swf_SetShapeStyles(i->tag,shape);
2304 swf_ShapeCountBits(shape,NULL,NULL);
2305 swf_SetShapeBits(i->tag,shape);
2306 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2307 i->swflastx = i->swflasty = UNDEFINED_COORD;
2308 drawgfxline(obj, line);
2309 swf_ShapeSetEnd(i->tag);
2310 swf_ShapeFree(shape);
2312 /* TODO: remember the bbox, and check all shapes against it */
2314 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2315 i->cliptags[i->clippos] = i->tag;
2316 i->clipshapes[i->clippos] = myshapeid;
2317 i->clipdepths[i->clippos] = getNewDepth(obj);
2321 void swf_endclip(gfxdevice_t*dev)
2323 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2324 swfoutput*obj = i->obj;
2331 msg("<error> Invalid end of clipping region");
2335 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2336 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2338 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2340 int swf_setparameter(gfxdevice_t*dev, const char*key, const char*value)
2342 if(!strcmp(key, "next_bitmap_is_jpeg")) {
2343 ((swfoutput_internal*)dev->internal)->jpeg = 1;
2349 int gfxline_type(gfxline_t*line)
2355 int haszerosegments=0;
2357 if(line->type == gfx_moveTo) {
2360 } else if(line->type == gfx_lineTo) {
2364 } else if(line->type == gfx_splineTo) {
2366 if(tmpsplines>lines)
2371 if(lines==0 && splines==0) return 0;
2372 else if(lines==1 && splines==0) return 1;
2373 else if(lines==0 && splines==1) return 2;
2374 else if(splines==0) return 3;
2378 int gfxline_has_dots(gfxline_t*line)
2385 if(line->type == gfx_moveTo) {
2386 if(isline && dist < 1) {
2391 } else if(line->type == gfx_lineTo) {
2392 dist += fabs(line->x - x) + fabs(line->y - y);
2394 } else if(line->type == gfx_splineTo) {
2395 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2396 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2403 if(isline && dist < 1) {
2409 int gfxline_fix_short_edges(gfxline_t*line)
2413 if(line->type == gfx_lineTo) {
2414 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2417 } else if(line->type == gfx_splineTo) {
2418 if(fabs(line->sx - x) + fabs(line->sy - y) +
2419 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2432 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)
2434 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2435 swfoutput*obj = i->obj;
2436 int type = gfxline_type(line);
2437 int has_dots = gfxline_has_dots(line);
2439 /* TODO: * split line into segments, and perform this check for all segments */
2441 (width <= config_caplinewidth
2442 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2443 || (cap_style == gfx_capRound && type<=2))) {
2444 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2446 swfoutput_setstrokecolor(obj, color->r, color->g, color->b, color->a);
2447 swfoutput_setlinewidth(obj, width);
2450 drawgfxline(obj, line);
2452 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2454 gfxline_fix_short_edges(line);
2455 /* we need to convert the line into a polygon */
2456 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2457 gfxline_t*gfxline = SVPtogfxline(svp);
2458 dev->fill(dev, gfxline, color);
2463 void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2465 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2466 swfoutput*obj = i->obj;
2468 if(!config_ignoredraworder)
2470 swfoutput_setfillcolor(obj, color->r, color->g, color->b, color->a);
2474 drawgfxline(obj, line);
2475 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2477 void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2479 msg("<error> Gradient filling not implemented yet");