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=0;
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];
140 /* during the transition to the gfxdevice interface:
141 a device which uses this swfoutput as target */
144 } swfoutput_internal;
146 void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
147 int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
148 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);
149 void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
150 void swf_endclip(gfxdevice_t*dev);
151 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);
152 void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
153 void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
154 void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
156 static swfoutput_internal* init_internal_struct()
158 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
159 memset(i, 0, sizeof(swfoutput_internal));
180 i->fillstylechanged = 0;
187 i->device.internal = (void*)i;
188 i->device.fillbitmap = swf_fillbitmap;
189 i->device.setparameter = swf_setparameter;
190 i->device.stroke = swf_stroke;
191 i->device.startclip = swf_startclip;
192 i->device.endclip = swf_endclip;
193 i->device.fill = swf_fill;
194 i->device.fillbitmap = swf_fillbitmap;
195 i->device.fillgradient = swf_fillgradient;
200 static int id_error = 0;
202 static U16 getNewID(struct swfoutput* obj)
204 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
205 if(i->currentswfid == 65535) {
207 msg("<error> ID Table overflow");
210 return ++i->currentswfid;
213 static void startshape(struct swfoutput* obj);
214 static void starttext(struct swfoutput* obj);
215 static void endshape(struct swfoutput* obj);
216 static void endtext(struct swfoutput* obj);
218 // matrix multiplication. changes p0
219 static void transform (plotxy*p0,struct swfmatrix*m)
222 x = m->m11*p0->x+m->m12*p0->y;
223 y = m->m21*p0->x+m->m22*p0->y;
228 // write a move-to command into the swf
229 static int moveto(struct swfoutput*obj, TAG*tag, plotxy p0)
231 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
232 int rx = (int)(p0.x*20);
233 int ry = (int)(p0.y*20);
234 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
235 swf_ShapeSetMove (tag, i->shape, rx,ry);
236 i->fillstylechanged = 0;
243 static int moveto(struct swfoutput*obj, TAG*tag, double x, double y)
245 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
249 return moveto(obj, tag, p);
251 static void addPointToBBox(struct swfoutput*obj, int px, int py)
253 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
259 swf_ExpandRect(&i->bboxrect, p);
261 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
265 /*static void plot(struct swfoutput*obj, int x, int y, TAG*tag)
267 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
268 int width = i->linewidth/4;
272 //swf_ShapeSetLine(tag, i->shape,-width,-width);
273 //swf_ShapeSetLine(tag, i->shape,width*2,0);
274 //swf_ShapeSetLine(tag, i->shape,0,width*2);
275 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
276 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
277 //swf_ShapeSetLine(tag, i->shape,width,width);
280 swf_ShapeSetLine(tag, i->shape,-width,0);
281 swf_ShapeSetLine(tag, i->shape,width,-width);
282 swf_ShapeSetLine(tag, i->shape,width,width);
283 swf_ShapeSetLine(tag, i->shape,-width,width);
284 swf_ShapeSetLine(tag, i->shape,-width,-width);
285 swf_ShapeSetLine(tag, i->shape,width,0);
287 addPointToBBox(obj, x-width ,y-width);
288 addPointToBBox(obj, x+width ,y+width);
291 // write a line-to command into the swf
292 static void lineto(struct swfoutput*obj, TAG*tag, plotxy p0)
294 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
295 int px = (int)(p0.x*20);
296 int py = (int)(p0.y*20);
297 int rx = (px-i->swflastx);
298 int ry = (py-i->swflasty);
300 swf_ShapeSetLine (tag, i->shape, rx,ry);
301 addPointToBBox(obj, i->swflastx,i->swflasty);
302 addPointToBBox(obj, px,py);
303 }/* else if(!i->fill) {
304 // treat lines of length 0 as plots, making them
305 // at least 1 twip wide so Flash will display them
306 plot(obj, i->swflastx, i->swflasty, tag);
313 static void lineto(struct swfoutput*obj, TAG*tag, double x, double y)
321 // write a spline-to command into the swf
322 static void splineto(struct swfoutput*obj, TAG*tag, plotxy control,plotxy end)
324 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
325 int lastlastx = i->swflastx;
326 int lastlasty = i->swflasty;
328 int cx = ((int)(control.x*20)-i->swflastx);
329 int cy = ((int)(control.y*20)-i->swflasty);
332 int ex = ((int)(end.x*20)-i->swflastx);
333 int ey = ((int)(end.y*20)-i->swflasty);
337 if(cx || cy || ex || ey) {
338 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
339 addPointToBBox(obj, lastlastx ,lastlasty );
340 addPointToBBox(obj, lastlastx+cx,lastlasty+cy);
341 addPointToBBox(obj, lastlastx+cx+ex,lastlasty+cy+ey);
342 }/* else if(!i->fill) {
343 // treat splines of length 0 as plots
344 plot(obj, lastlastx, lastlasty, tag);
349 /* write a line, given two points and the transformation
351 /*static void line(struct swfoutput*obj, TAG*tag, plotxy p0, plotxy p1)
353 moveto(obj, tag, p0);
354 lineto(obj, tag, p1);
357 void resetdrawer(struct swfoutput*obj)
359 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
364 static void stopFill(struct swfoutput*obj)
366 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
369 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
370 i->fillstylechanged = 1;
374 static void startFill(struct swfoutput*obj)
376 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
379 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
380 i->fillstylechanged = 1;
385 /* draw an outline. These are generated by pdf2swf and by t1lib
386 (representing characters). */
387 /*void drawpath(struct swfoutput*obj, SWF_OUTLINE*outline, struct swfmatrix*m, int log)
389 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
390 if( i->tag->id != ST_DEFINESHAPE &&
391 i->tag->id != ST_DEFINESHAPE2 &&
392 i->tag->id != ST_DEFINESHAPE3)
394 msg("<error> internal error: drawpath needs a shape tag, not %d\n",i->tag->id);
398 double lastx=0,lasty=0;
399 double firstx=0,firsty=0;
404 x += (outline->dest.x/(float)0xffff);
405 y += (outline->dest.y/(float)0xffff);
406 if(outline->type == SWF_PATHTYPE_MOVE)
408 //if(!init && fill && obj->drawmode != DRAWMODE_EOFILL && !ignoredraworder)
409 if(config_filloverlap && !init && i->fill && obj->drawmode != DRAWMODE_EOFILL) {
410 // drawmode=FILL (not EOFILL) means that
411 // seperate shapes do not cancel each other out.
412 // On SWF side, we need to start a new shape for each
413 // closed polygon, because SWF only knows EOFILL.
420 if(((int)(lastx*20) != (int)(firstx*20) ||
421 (int)(lasty*20) != (int)(firsty*20)) &&
430 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
431 line(obj,i->tag, p0, p1);
437 else if(outline->type == SWF_PATHTYPE_LINE)
445 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
446 line(obj,i->tag, p0,p1);
449 msg("<error> drawpath: unknown outline type:%d\n", outline->type);
453 outline = outline->link;
455 if(((int)(lastx*20) != (int)(firstx*20) ||
456 (int)(lasty*20) != (int)(firsty*20)) &&
465 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
466 line(obj, i->tag, p0, p1);
470 static inline int colorcompare(struct swfoutput*obj, RGBA*a,RGBA*b)
482 static SRECT getcharacterbbox(struct swfoutput*obj, SWFFONT*font)
484 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
487 memset(&r, 0, sizeof(r));
490 if(debug) printf("\n");
491 for(t=0;t<i->chardatapos;t++)
493 if(i->chardata[t].fontid != font->id) {
494 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
497 SRECT b = font->layout->bounds[i->chardata[t].charid];
498 b.xmin *= i->chardata[t].size;
499 b.ymin *= i->chardata[t].size;
500 b.xmax *= i->chardata[t].size;
501 b.ymax *= i->chardata[t].size;
506 b.xmin += i->chardata[t].x;
507 b.ymin += i->chardata[t].y;
508 b.xmax += i->chardata[t].x;
509 b.ymax += i->chardata[t].y;
511 /* until we solve the INTERNAL_SCALING problem (see below)
512 make sure the bounding box is big enough */
518 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
519 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
520 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
521 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
522 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
527 i->chardata[t].fontid,
529 i->chardata[t].charid
531 swf_ExpandRect2(&r, &b);
533 if(debug) printf("-----> (%f,%f,%f,%f)\n",
541 static void putcharacters(struct swfoutput*obj, TAG*tag)
543 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
547 color.r = i->chardata[0].color.r^255;
556 int charadvance[128];
559 int glyphbits=1; //TODO: can this be zero?
562 if(tag->id != ST_DEFINETEXT &&
563 tag->id != ST_DEFINETEXT2) {
564 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
567 if(!i->chardatapos) {
568 msg("<warning> putcharacters called with zero characters");
571 for(pass = 0; pass < 2; pass++)
581 advancebits++; // add sign bit
582 swf_SetU8(tag, glyphbits);
583 swf_SetU8(tag, advancebits);
586 for(t=0;t<=i->chardatapos;t++)
588 if(lastfontid != i->chardata[t].fontid ||
589 lastx!=i->chardata[t].x ||
590 lasty!=i->chardata[t].y ||
591 !colorcompare(obj,&color, &i->chardata[t].color) ||
593 lastsize != i->chardata[t].size ||
596 if(charstorepos && pass==0)
599 for(s=0;s<charstorepos;s++)
601 while(charids[s]>=(1<<glyphbits))
603 while(charadvance[s]>=(1<<advancebits))
607 if(charstorepos && pass==1)
609 tag->writeBit = 0; // Q&D
610 swf_SetBits(tag, 0, 1); // GLYPH Record
611 swf_SetBits(tag, charstorepos, 7); // number of glyphs
613 for(s=0;s<charstorepos;s++)
615 swf_SetBits(tag, charids[s], glyphbits);
616 swf_SetBits(tag, charadvance[s], advancebits);
621 if(pass == 1 && t<i->chardatapos)
627 if(lastx != i->chardata[t].x ||
628 lasty != i->chardata[t].y)
630 newx = i->chardata[t].x;
631 newy = i->chardata[t].y;
637 if(!colorcompare(obj,&color, &i->chardata[t].color))
639 color = i->chardata[t].color;
642 font.id = i->chardata[t].fontid;
643 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
646 tag->writeBit = 0; // Q&D
647 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
650 lastfontid = i->chardata[t].fontid;
651 lastx = i->chardata[t].x;
652 lasty = i->chardata[t].y;
653 lastsize = i->chardata[t].size;
656 if(t==i->chardatapos)
660 int nextt = t==i->chardatapos-1?t:t+1;
661 int rel = i->chardata[nextt].x-i->chardata[t].x;
662 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
664 lastx=i->chardata[nextt].x;
668 lastx=i->chardata[t].x;
670 charids[charstorepos] = i->chardata[t].charid;
671 charadvance[charstorepos] = advance;
678 static void putcharacter(struct swfoutput*obj, int fontid, int charid, int x,int y, int size, RGBA color)
680 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
681 if(i->chardatapos == CHARDATAMAX)
683 msg("<warning> Character buffer too small. SWF will be slightly bigger");
687 i->chardata[i->chardatapos].fontid = fontid;
688 i->chardata[i->chardatapos].charid = charid;
689 i->chardata[i->chardatapos].x = x;
690 i->chardata[i->chardatapos].y = y;
691 i->chardata[i->chardatapos].color = color;
692 i->chardata[i->chardatapos].size = size;
696 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
697 So if we set this value to high, the char coordinates will overflow.
698 If we set it to low, however, the char positions will be inaccurate */
699 #define FONT_INTERNAL_SIZE 4
701 /* process a character. */
702 static int drawchar(struct swfoutput*obj, SWFFONT *swffont, char*character, int charnr, int u, swfmatrix*m, gfxcolor_t*col)
704 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
706 msg("<warning> Font is NULL");
710 int charid = getCharID(swffont, charnr, character, u);
713 msg("<warning> Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)",
714 FIXNULL(character),charnr, u, FIXNULL((char*)swffont->name), swffont->numchars);
717 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
718 msg("<warning> Character '%s' (c=%d,u=%d), glyph %d in current charset (%s, %d characters) is empty",
719 FIXNULL(character),charnr, u, charid, FIXNULL((char*)swffont->name), swffont->numchars);
731 float det = ((m->m11*m->m22)-(m->m21*m->m12));
732 if(fabs(det) < 0.0005) {
733 /* x direction equals y direction- the text is invisible */
736 det = 20*FONT_INTERNAL_SIZE / det;
739 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
740 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
742 RGBA rgba = *(RGBA*)col;
743 putcharacter(obj, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
744 swf_FontUseGlyph(swffont, charid);
749 SWF_OUTLINE*outline = font->getOutline(character, charnr);
750 char* charname = character;
753 msg("<warning> Didn't find character '%s' (%d) in current charset (%s)",
754 FIXNULL(character),charnr,FIXNULL(font->getName()));
773 drawpath(tag, outline, &m2, 0);
778 static void endtext(swfoutput*obj)
780 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
784 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
785 swf_SetU16(i->tag, i->textid);
788 r = getcharacterbbox(obj, obj->swffont);
790 swf_SetRect(i->tag,&r);
793 swf_GetMatrix(0, &m); /* set unit matrix- the real matrix is in the placeobject */
794 swf_SetMatrix(i->tag,&m);
796 putcharacters(obj, i->tag);
798 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
799 //swf_ObjectPlace(i->tag,i->textid,/*depth*/i->depth++,&i->page_matrix,NULL,NULL);
801 swf_MatrixJoin(&m2,&obj->fontmatrix, &i->page_matrix);
803 swf_ObjectPlace(i->tag,i->textid,/*depth*/++i->depth,&m2,NULL,NULL);
807 int getCharID(SWFFONT *font, int charnr, char *charname, int u)
810 if(charname && font->glyphnames) {
811 for(t=0;t<font->numchars;t++) {
812 if(font->glyphnames[t] && !strcmp(font->glyphnames[t],charname)) {
813 msg("<debug> Char [%d,>%s<,%d] maps to %d\n", charnr, charname, u, t);
817 /* if we didn't find the character, maybe
818 we can find the capitalized version */
819 for(t=0;t<font->numchars;t++) {
820 if(font->glyphnames[t] && !strcasecmp(font->glyphnames[t],charname)) {
821 msg("<debug> Char [%d,>>%s<<,%d] maps to %d\n", charnr, charname, u, t);
827 if(u>0 && font->encoding != 255) {
828 /* try to use the unicode id */
829 if(u>=0 && u<font->maxascii && font->ascii2glyph[u]>=0) {
830 msg("<debug> Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->ascii2glyph[u]);
831 return font->ascii2glyph[u];
835 if(font->encoding != FONT_ENCODING_UNICODE) {
836 /* the following only works if the font encoding
837 is US-ASCII based. It's needed for fonts which return broken unicode
839 if(charnr>=0 && charnr<font->maxascii && font->ascii2glyph[charnr]>=0) {
840 msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, font->ascii2glyph[charnr]);
841 return font->ascii2glyph[charnr];
845 if(charnr>=0 && charnr<font->numchars) {
846 msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr);
854 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
855 void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename)
857 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
858 fontlist_t*last=0,*iterator;
860 msg("<error> No fontid");
864 if(obj->swffont && obj->swffont->name && !strcmp((char*)obj->swffont->name,fontid))
867 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
868 with multiple fonts */
871 iterator = i->fontlist;
873 if(!strcmp((char*)iterator->swffont->name,fontid)) {
874 obj->swffont = iterator->swffont;
878 iterator = iterator->next;
882 msg("<error> No filename given for font- internal error?");
886 swf_SetLoadFontParameters(64,/*skip unused*/0,/*full unicode*/1);
887 SWFFONT*swffont = swf_LoadFont(filename);
890 msg("<warning> Couldn't load font %s (%s)", fontid, filename);
891 swffont = swf_LoadFont(0);
894 if(swffont->glyph2ascii) {
897 /* check whether the Unicode indices look o.k.
898 If they don't, disable the unicode lookup by setting
899 the encoding to 255 */
900 for(t=0;t<swffont->numchars;t++) {
901 int c = swffont->glyph2ascii[t];
902 if(c && c < 32 && swffont->glyph[t].shape->bitlen > 16) {
903 // the character maps into the unicode control character range
904 // between 0001-001f. Yet it is not empty. Treat the one
905 // mapping as broken, and look how many of those we find.
910 msg("<warning> Font %s has bad unicode mapping", fontid);
911 swffont->encoding = 255;
915 swf_FontSetID(swffont, getNewID(obj));
917 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
918 // print font information
919 msg("<debug> Font %s (%s)",swffont->name, filename);
920 msg("<debug> | ID: %d", swffont->id);
921 msg("<debug> | Version: %d", swffont->version);
922 msg("<debug> | Name: %s", fontid);
923 msg("<debug> | Numchars: %d", swffont->numchars);
924 msg("<debug> | Maxascii: %d", swffont->maxascii);
925 msg("<debug> | Style: %d", swffont->style);
926 msg("<debug> | Encoding: %d", swffont->encoding);
927 for(int iii=0; iii<swffont->numchars;iii++) {
928 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,
929 swffont->layout->bounds[iii].xmin/20.0,
930 swffont->layout->bounds[iii].ymin/20.0,
931 swffont->layout->bounds[iii].xmax/20.0,
932 swffont->layout->bounds[iii].ymax/20.0
935 for(t=0;t<swffont->maxascii;t++) {
936 if(swffont->ascii2glyph[t] == iii)
937 msg("<debug> | - maps to %d",t);
942 /* set the font name to the ID we use here */
943 if(swffont->name) free(swffont->name);
944 swffont->name = (U8*)strdup(fontid);
946 iterator = new fontlist_t;
947 iterator->swffont = swffont;
951 last->next = iterator;
953 i->fontlist = iterator;
955 obj->swffont = swffont;
958 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
960 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
961 fontlist_t *iterator = i->fontlist;
963 if(!strcmp((char*)iterator->swffont->name,fontid))
965 iterator = iterator->next;
970 /* set's the matrix which is to be applied to characters drawn by
971 swfoutput_drawchar() */
972 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
973 double m21,double m22)
975 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
976 if(obj->fontm11 == m11 &&
977 obj->fontm12 == m12 &&
978 obj->fontm21 == m21 &&
989 m.sx = (U32)(((obj->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((obj->fontm12)*65536)/FONT_INTERNAL_SIZE);
990 m.r0 = (U32)(((obj->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((obj->fontm22)*65536)/FONT_INTERNAL_SIZE);
996 /* draws a character at x,y. */
997 int swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr, int u, gfxcolor_t* color)
999 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1001 m.m11 = obj->fontm11;
1002 m.m12 = obj->fontm12;
1003 m.m21 = obj->fontm21;
1004 m.m22 = obj->fontm22;
1007 return drawchar(obj, obj->swffont, character, charnr, u, &m, color);
1010 static void endpage(struct swfoutput*obj)
1012 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1018 swfoutput_endclip(obj);
1019 i->pagefinished = 1;
1022 void swfoutput_pagefeed(struct swfoutput*obj)
1024 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1026 if(!i->pagefinished)
1029 if(config_insertstoptag) {
1031 atag = action_Stop(atag);
1032 atag = action_End(atag);
1033 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
1034 swf_ActionSet(i->tag,atag);
1036 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
1039 for(i->depth;i->depth>i->startdepth;i->depth--) {
1040 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
1041 swf_SetU16(i->tag,i->depth);
1043 i->depth = i->startdepth;
1046 static void setBackground(struct swfoutput*obj, int x1, int y1, int x2, int y2)
1048 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1050 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
1054 int shapeid = getNewID(obj);
1059 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
1061 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
1062 swf_SetU16(i->tag,shapeid);
1063 swf_SetRect(i->tag,&r);
1064 swf_SetShapeHeader(i->tag,s);
1065 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
1066 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
1067 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
1068 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
1069 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
1070 swf_ShapeSetEnd(i->tag);
1072 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
1073 swf_ObjectPlace(i->tag,shapeid,++i->depth,0,0,0);
1074 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
1075 swf_ObjectPlaceClip(i->tag,shapeid,++i->depth,0,0,0,65535);
1076 i->cliptag = i->tag;
1079 void swfoutput_newpage(struct swfoutput*obj, int pageNum, int movex, int movey, int x1, int y1, int x2, int y2)
1081 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1082 if(!i->firstpage && !i->pagefinished)
1085 swf_GetMatrix(0, &i->page_matrix);
1086 i->page_matrix.tx = movex*20;
1087 i->page_matrix.ty = movey*20;
1089 if(i->cliptag && i->frameno == i->lastframeno) {
1091 swf_GetPlaceObject(i->cliptag, &obj);
1092 obj.clipdepth = i->depth;
1093 swf_ResetTag(i->cliptag, i->cliptag->id);
1094 swf_SetPlaceObject(i->cliptag, &obj);
1095 swf_PlaceObjectFree(&obj);
1103 msg("<notice> processing page %d (%dx%d:%d:%d)", pageNum,x2-x1,y2-y1, x1, y1);
1105 x1*=20;y1*=20;x2*=20;y2*=20;
1107 /* set clipping/background rectangle */
1108 /* TODO: this should all be done in SWFOutputDev */
1109 setBackground(obj, x1, y1, x2, y2);
1111 /* increase SWF's bounding box */
1117 swf_ExpandRect2(&i->swf.movieSize, &r);
1119 i->lastframeno = i->frameno;
1121 i->pagefinished = 0;
1124 /* initialize the swf writer */
1125 void swfoutput_init(struct swfoutput* obj)
1127 memset(obj, 0, sizeof(struct swfoutput));
1128 obj->internal = init_internal_struct();
1129 ((swfoutput_internal*)obj->internal)->obj = obj;
1131 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1136 msg("<verbose> initializing swf output for size %d*%d\n", i->max_x,i->max_y);
1140 memset(&i->swf,0x00,sizeof(SWF));
1142 i->swf.fileVersion = config_flashversion;
1143 i->swf.frameRate = 0x0040; // 1 frame per 4 seconds
1144 i->swf.movieSize.xmin = 0;
1145 i->swf.movieSize.ymin = 0;
1146 i->swf.movieSize.xmax = 0;
1147 i->swf.movieSize.ymax = 0;
1149 i->swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
1150 i->tag = i->swf.firstTag;
1151 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
1152 swf_SetRGB(i->tag,&rgb);
1154 i->startdepth = i->depth = 0;
1157 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1160 static void startshape(struct swfoutput*obj)
1162 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1171 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
1173 swf_ShapeNew(&i->shape);
1174 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&obj->strokergb);
1175 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&obj->fillrgb);
1177 i->shapeid = getNewID(obj);
1179 msg("<debug> Using shape id %d", i->shapeid);
1181 swf_SetU16(i->tag,i->shapeid); // ID
1183 i->bboxrectpos = i->tag->len;
1187 r.xmax = 20*i->max_x;
1188 r.ymax = 20*i->max_y;
1189 swf_SetRect(i->tag,&r);
1191 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
1193 swf_SetShapeStyles(i->tag,i->shape);
1194 swf_ShapeCountBits(i->shape,NULL,NULL);
1195 swf_SetShapeBits(i->tag,i->shape);
1197 /* TODO: do we really need this? */
1198 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
1199 i->swflastx=i->swflasty=0;
1201 i->shapeisempty = 1;
1204 static void starttext(struct swfoutput*obj)
1206 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1210 i->textid = getNewID(obj);
1212 i->swflastx=i->swflasty=0;
1216 /* TODO: move to ../lib/rfxswf */
1217 void changeRect(struct swfoutput*obj, TAG*tag, int pos, SRECT*newrect)
1219 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1220 /* determine length of old rect */
1224 swf_GetRect(tag, &old);
1225 swf_ResetReadBits(tag);
1226 int pos_end = tag->pos;
1228 int len = tag->len - pos_end;
1229 U8*data = (U8*)malloc(len);
1230 memcpy(data, &tag->data[pos_end], len);
1233 swf_SetRect(tag, newrect);
1234 swf_SetBlock(tag, data, len);
1236 tag->pos = tag->readBit = 0;
1239 void cancelshape(swfoutput*obj)
1241 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1242 /* delete old shape tag */
1244 i->tag = i->tag->prev;
1245 swf_DeleteTag(todel);
1246 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
1248 i->bboxrectpos = -1;
1251 void fixAreas(swfoutput*obj)
1253 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1254 if(!i->shapeisempty && i->fill &&
1255 (i->bboxrect.xmin == i->bboxrect.xmax ||
1256 i->bboxrect.ymin == i->bboxrect.ymax) &&
1257 config_minlinewidth >= 0.001
1259 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1260 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1261 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1264 SRECT r = i->bboxrect;
1266 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1267 /* this thing comes down to a single dot- nothing to fix here */
1273 RGBA save_col = obj->strokergb;
1274 int save_width = i->linewidth;
1276 obj->strokergb = obj->fillrgb;
1277 i->linewidth = (int)(config_minlinewidth*20);
1278 if(i->linewidth==0) i->linewidth = 1;
1282 moveto(obj, i->tag, r.xmin/20.0,r.ymin/20.0);
1283 lineto(obj, i->tag, r.xmax/20.0,r.ymax/20.0);
1285 obj->strokergb = save_col;
1286 i->linewidth = save_width;
1291 static void endshape_noput(swfoutput*obj)
1293 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1296 //changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect);
1299 swf_ShapeFree(i->shape);
1305 static void endshape(swfoutput*obj)
1307 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1313 if(i->shapeisempty ||
1315 (i->bboxrect.xmin == i->bboxrect.xmax &&
1316 i->bboxrect.ymin == i->bboxrect.ymax))
1318 // delete the shape again, we didn't do anything
1319 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1320 i->bboxrect.xmin /20.0,
1321 i->bboxrect.ymin /20.0,
1322 i->bboxrect.xmax /20.0,
1323 i->bboxrect.ymax /20.0
1329 swf_ShapeSetEnd(i->tag);
1331 changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect);
1333 msg("<trace> Placing shape id %d", i->shapeid);
1335 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1336 swf_ObjectPlace(i->tag,i->shapeid,/*depth*/++i->depth,&i->page_matrix,NULL,NULL);
1338 swf_ShapeFree(i->shape);
1341 i->bboxrectpos = -1;
1347 sprintf(text, "id%d", i->shapeid);
1349 points[0].x = i->bboxrect.xmin;
1350 points[0].y = i->bboxrect.ymin;
1351 points[1].x = i->bboxrect.xmax;
1352 points[1].y = i->bboxrect.ymin;
1353 points[2].x = i->bboxrect.xmax;
1354 points[2].y = i->bboxrect.ymax;
1355 points[3].x = i->bboxrect.xmin;
1356 points[3].y = i->bboxrect.ymax;
1357 swfoutput_namedlink(obj,text,points);
1361 void swfoutput_finalize(struct swfoutput*obj)
1363 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1365 if(i->tag && i->tag->id == ST_END)
1366 return; //already done
1368 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1369 swfoutput_pagefeed(obj);
1372 fontlist_t *tmp,*iterator = i->fontlist;
1374 TAG*mtag = i->swf.firstTag;
1375 if(iterator->swffont) {
1376 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1377 /*if(!storeallcharacters)
1378 swf_FontReduce(iterator->swffont);*/
1379 swf_FontSetDefine2(mtag, iterator->swffont);
1382 iterator = iterator->next;
1384 i->tag = swf_InsertTag(i->tag,ST_END);
1385 TAG* tag = i->tag->prev;
1387 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1388 and the ST_END- they confuse the flash player */
1389 while(tag->id == ST_REMOVEOBJECT2) {
1390 TAG* prev = tag->prev;
1396 SWF* swfoutput_get(struct swfoutput*obj)
1398 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1400 swfoutput_finalize(obj);
1402 return swf_CopySWF(&i->swf);
1405 void swfoutput_getdimensions(struct swfoutput*obj, int*x1, int*y1, int*x2, int*y2)
1407 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1408 if(x1) *x1 = i->swf.movieSize.xmin/20;
1409 if(y1) *y1 = i->swf.movieSize.ymin/20;
1410 if(x2) *x2 = i->swf.movieSize.xmax/20;
1411 if(y2) *y2 = i->swf.movieSize.ymax/20;
1414 int swfoutput_save(struct swfoutput* obj, char*filename)
1416 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1417 swfoutput_finalize(obj);
1421 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1426 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1430 if(config_enablezlib || config_flashversion>=6) {
1431 if FAILED(swf_WriteSWC(fi,&i->swf))
1432 msg("<error> WriteSWC() failed.\n");
1434 if FAILED(swf_WriteSWF(fi,&i->swf))
1435 msg("<error> WriteSWF() failed.\n");
1440 msg("<notice> SWF written\n");
1444 /* Perform cleaning up, complete the swf, and write it out. */
1445 void swfoutput_destroy(struct swfoutput* obj)
1447 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1449 /* not initialized yet- nothing to destroy */
1453 fontlist_t *tmp,*iterator = i->fontlist;
1455 if(iterator->swffont) {
1456 swf_FontFree(iterator->swffont);iterator->swffont=0;
1459 iterator = iterator->next;
1462 swf_FreeTags(&i->swf);
1465 memset(obj, 0, sizeof(swfoutput));
1468 static void swfoutput_setfillcolor(swfoutput* obj, U8 r, U8 g, U8 b, U8 a)
1470 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1471 if(obj->fillrgb.r == r &&
1472 obj->fillrgb.g == g &&
1473 obj->fillrgb.b == b &&
1474 obj->fillrgb.a == a) return;
1484 static void swfoutput_setstrokecolor(swfoutput* obj, U8 r, U8 g, U8 b, U8 a)
1486 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1487 if(obj->strokergb.r == r &&
1488 obj->strokergb.g == g &&
1489 obj->strokergb.b == b &&
1490 obj->strokergb.a == a) return;
1494 obj->strokergb.r = r;
1495 obj->strokergb.g = g;
1496 obj->strokergb.b = b;
1497 obj->strokergb.a = a;
1500 static void swfoutput_setlinewidth(struct swfoutput*obj, double _linewidth)
1502 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1503 if(i->linewidth == (U16)(_linewidth*20))
1508 i->linewidth = (U16)(_linewidth*20);
1512 static void drawlink(struct swfoutput*obj, ActionTAG*,ActionTAG*, swfcoord*points, char mouseover);
1514 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1516 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1518 if(!strncmp("http://pdf2swf:", url, 15)) {
1519 char*tmp = strdup(url);
1520 int l = strlen(tmp);
1523 swfoutput_namedlink(obj, tmp+15, points);
1533 if(config_opennewwindow)
1534 actions = action_GetUrl(0, url, "_parent");
1536 actions = action_GetUrl(0, url, "_this");
1537 actions = action_End(actions);
1539 drawlink(obj, actions, 0, points,0);
1541 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1543 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1551 actions = action_GotoFrame(0, page);
1552 actions = action_End(actions);
1554 drawlink(obj, actions, 0, points,0);
1557 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1558 of the viewer objects, like subtitles, index elements etc.
1560 void swfoutput_namedlink(struct swfoutput*obj, char*name, swfcoord*points)
1562 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1563 ActionTAG *actions1,*actions2;
1564 char*tmp = strdup(name);
1572 if(!strncmp(tmp, "call:", 5))
1574 char*x = strchr(&tmp[5], ':');
1576 actions1 = action_PushInt(0, 0); //number of parameters (0)
1577 actions1 = action_PushString(actions1, &tmp[5]); //function name
1578 actions1 = action_CallFunction(actions1);
1581 actions1 = action_PushString(0, x+1); //parameter
1582 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1583 actions1 = action_PushString(actions1, &tmp[5]); //function name
1584 actions1 = action_CallFunction(actions1);
1586 actions2 = action_End(0);
1591 actions1 = action_PushString(0, "/:subtitle");
1592 actions1 = action_PushString(actions1, name);
1593 actions1 = action_SetVariable(actions1);
1594 actions1 = action_End(actions1);
1596 actions2 = action_PushString(0, "/:subtitle");
1597 actions2 = action_PushString(actions2, "");
1598 actions2 = action_SetVariable(actions2);
1599 actions2 = action_End(actions2);
1602 drawlink(obj, actions1, actions2, points,mouseover);
1604 swf_ActionFree(actions1);
1605 swf_ActionFree(actions2);
1609 static void drawlink(struct swfoutput*obj, ActionTAG*actions1, ActionTAG*actions2, swfcoord*points, char mouseover)
1611 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1616 struct plotxy p1,p2,p3,p4;
1620 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1624 int buttonid = getNewID(obj);
1627 if(points[t].x>xmax) xmax=points[t].x;
1628 if(points[t].y>ymax) ymax=points[t].y;
1629 if(points[t].x<xmin) xmin=points[t].x;
1630 if(points[t].y<ymin) ymin=points[t].y;
1633 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1634 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1636 /* the following code subtracts the upper left edge from all coordinates,
1637 and set's posx,posy so that ST_PLACEOBJECT is used with a matrix.
1638 Necessary for preprocessing with swfcombine. */
1639 posx = xmin; posy = ymin;
1640 p1.x-=posx;p2.x-=posx;p3.x-=posx;p4.x-=posx;
1641 p1.y-=posy;p2.y-=posy;p3.y-=posy;p4.y-=posy;
1642 xmin -= posx; ymin -= posy;
1643 xmax -= posx; ymax -= posy;
1646 myshapeid = getNewID(obj);
1647 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1648 swf_ShapeNew(&i->shape);
1649 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1650 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1651 swf_SetU16(i->tag, myshapeid);
1652 r.xmin = (int)(xmin*20);
1653 r.ymin = (int)(ymin*20);
1654 r.xmax = (int)(xmax*20);
1655 r.ymax = (int)(ymax*20);
1656 swf_SetRect(i->tag,&r);
1657 swf_SetShapeStyles(i->tag,i->shape);
1658 swf_ShapeCountBits(i->shape,NULL,NULL);
1659 swf_SetShapeBits(i->tag,i->shape);
1660 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1661 i->swflastx = i->swflasty = 0;
1662 moveto(obj, i->tag, p1);
1663 lineto(obj, i->tag, p2);
1664 lineto(obj, i->tag, p3);
1665 lineto(obj, i->tag, p4);
1666 lineto(obj, i->tag, p1);
1667 swf_ShapeSetEnd(i->tag);
1670 myshapeid2 = getNewID(obj);
1671 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1672 swf_ShapeNew(&i->shape);
1673 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1675 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1676 swf_SetU16(i->tag, myshapeid2);
1677 r.xmin = (int)(xmin*20);
1678 r.ymin = (int)(ymin*20);
1679 r.xmax = (int)(xmax*20);
1680 r.ymax = (int)(ymax*20);
1681 swf_SetRect(i->tag,&r);
1682 swf_SetShapeStyles(i->tag,i->shape);
1683 swf_ShapeCountBits(i->shape,NULL,NULL);
1684 swf_SetShapeBits(i->tag,i->shape);
1685 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1686 i->swflastx = i->swflasty = 0;
1687 moveto(obj, i->tag, p1);
1688 lineto(obj, i->tag, p2);
1689 lineto(obj, i->tag, p3);
1690 lineto(obj, i->tag, p4);
1691 lineto(obj, i->tag, p1);
1692 swf_ShapeSetEnd(i->tag);
1696 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1697 swf_SetU16(i->tag,buttonid); //id
1698 swf_ButtonSetFlags(i->tag, 0); //menu=no
1699 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1700 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1701 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1702 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1703 swf_SetU8(i->tag,0);
1704 swf_ActionSet(i->tag,actions1);
1705 swf_SetU8(i->tag,0);
1709 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1710 swf_SetU16(i->tag,buttonid); //id
1711 swf_ButtonSetFlags(i->tag, 0); //menu=no
1712 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1713 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1714 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1715 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1716 swf_SetU8(i->tag,0); // end of button records
1717 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1718 swf_ActionSet(i->tag,actions1);
1720 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1721 swf_ActionSet(i->tag,actions2);
1722 swf_SetU8(i->tag,0);
1723 swf_ButtonPostProcess(i->tag, 2);
1725 swf_SetU8(i->tag,0);
1726 swf_ButtonPostProcess(i->tag, 1);
1730 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1732 if(posx!=0 || posy!=0) {
1734 p.x = (int)(posx*20);
1735 p.y = (int)(posy*20);
1736 p = swf_TurnPoint(p, &i->page_matrix);
1741 swf_ObjectPlace(i->tag, buttonid, ++i->depth,&m,0,0);
1743 swf_ObjectPlace(i->tag, buttonid, ++i->depth,&i->page_matrix,0,0);
1750 for(t=0;t<picpos;t++)
1752 if(pic_xids[t] == xid &&
1753 pic_yids[t] == yid) {
1754 width = pic_width[t];
1755 height = pic_height[t];
1759 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1760 pic_xids[picpos] = xid;
1761 pic_yids[picpos] = yid;
1762 pic_width[picpos] = width;
1763 pic_height[picpos] = height;
1766 pic[width*y+x] = buf[0];
1770 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1771 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1775 xid += x*r+x*b*3+x*g*7+x*a*11;
1776 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1778 for(t=0;t<picpos;t++)
1780 if(pic_xids[t] == xid &&
1781 pic_yids[t] == yid) {
1789 static void drawgfxline(struct swfoutput*obj, gfxline_t*line)
1791 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1792 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1797 /* check whether the next segment is zero */
1798 if(line->type == gfx_moveTo) {
1799 msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
1800 moveto(obj, i->tag, line->x, line->y);
1801 px = lastx = line->x;
1802 py = lasty = line->y;
1804 } if(line->type == gfx_lineTo) {
1805 msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
1806 lineto(obj, i->tag, line->x, line->y);
1810 } else if(line->type == gfx_splineTo) {
1811 msg("<trace> ======== splineTo %.2f %.2f", line->x, line->y);
1813 s.x = line->sx;p.x = line->x;
1814 s.y = line->sy;p.y = line->y;
1815 splineto(obj, i->tag, s, p);
1824 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)
1826 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1827 gfxdevice_t*dev = &i->device;
1828 dev->stroke(dev, line, width, col, cap_style, joint_style, miterLimit);
1830 void swfoutput_fillgfxline(struct swfoutput*obj, gfxline_t*line, gfxcolor_t*col)
1832 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1833 gfxdevice_t*dev = &i->device;
1834 dev->fill(dev, line, col);
1836 void swfoutput_startclip(struct swfoutput*obj, gfxline_t*line)
1838 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1839 gfxdevice_t*dev = &i->device;
1840 dev->startclip(dev, line);
1842 void swfoutput_endclip(struct swfoutput*obj)
1844 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1845 gfxdevice_t*dev = &i->device;
1849 #define IMAGE_TYPE_JPEG 0
1850 #define IMAGE_TYPE_LOSSLESS 1
1852 static void swfoutput_drawimage(struct swfoutput*obj, RGBA* data, int sizex,int sizey,
1853 double x1,double y1,
1854 double x2,double y2,
1855 double x3,double y3,
1856 double x4,double y4, int type)
1858 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1862 double l1 = sqrt((x4-x1)*(x4-x1) + (y4-y1)*(y4-y1));
1863 double l2 = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
1865 gfxline_t p1,p2,p3,p4,p5;
1866 p1.type=gfx_moveTo;p1.x=x1; p1.y=y1;p1.next=&p2;
1867 p2.type=gfx_lineTo;p2.x=x2; p2.y=y2;p2.next=&p3;
1868 p3.type=gfx_lineTo;p3.x=x3; p3.y=y3;p3.next=&p4;
1869 p4.type=gfx_lineTo;p4.x=x4; p4.y=y4;p4.next=&p5;
1870 p5.type=gfx_lineTo;p5.x=x1; p5.y=y1;p5.next=0;
1872 {p1.x = (int)(p1.x*20)/20.0;
1873 p1.y = (int)(p1.y*20)/20.0;
1874 p2.x = (int)(p2.x*20)/20.0;
1875 p2.y = (int)(p2.y*20)/20.0;
1876 p3.x = (int)(p3.x*20)/20.0;
1877 p3.y = (int)(p3.y*20)/20.0;
1878 p4.x = (int)(p4.x*20)/20.0;
1879 p4.y = (int)(p4.y*20)/20.0;
1880 p5.x = (int)(p5.x*20)/20.0;
1881 p5.y = (int)(p5.y*20)/20.0;
1888 m.m00 = (p4.x-p1.x)/sizex; m.m10 = (p2.x-p1.x)/sizey;
1889 m.m01 = (p4.y-p1.y)/sizex; m.m11 = (p2.y-p1.y)/sizey;
1894 img.data = (gfxcolor_t*)data;
1898 if(type == IMAGE_TYPE_JPEG)
1899 /* TODO: pass image_dpi to device instead */
1900 i->device.setparameter(&i->device, "next_bitmap_is_jpeg", "1");
1902 i->device.fillbitmap(&i->device, &p1, &img, &m, 0);
1905 void swfoutput_drawimagejpeg(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1906 double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
1908 swfoutput_drawimage(obj,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_JPEG);
1911 void swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1912 double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
1914 swfoutput_drawimage(obj,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_LOSSLESS);
1917 void swfoutput_setparameter(char*name, char*value)
1919 if(!strcmp(name, "jpegsubpixels")) {
1920 config_jpegsubpixels = atof(value);
1921 } else if(!strcmp(name, "ppmsubpixels")) {
1922 config_ppmsubpixels = atof(value);
1923 } else if(!strcmp(name, "drawonlyshapes")) {
1924 config_drawonlyshapes = atoi(value);
1925 } else if(!strcmp(name, "ignoredraworder")) {
1926 config_ignoredraworder = atoi(value);
1927 } else if(!strcmp(name, "filloverlap")) {
1928 config_filloverlap = atoi(value);
1929 } else if(!strcmp(name, "linksopennewwindow")) {
1930 config_opennewwindow = atoi(value);
1931 } else if(!strcmp(name, "opennewwindow")) {
1932 config_opennewwindow = atoi(value);
1933 } else if(!strcmp(name, "storeallcharacters")) {
1934 config_storeallcharacters = atoi(value);
1935 } else if(!strcmp(name, "enablezlib")) {
1936 config_enablezlib = atoi(value);
1937 } else if(!strcmp(name, "insertstop")) {
1938 config_insertstoptag = atoi(value);
1939 } else if(!strcmp(name, "protected")) {
1940 config_protect = atoi(value);
1941 } else if(!strcmp(name, "flashversion")) {
1942 config_flashversion = atoi(value);
1943 } else if(!strcmp(name, "minlinewidth")) {
1944 config_minlinewidth = atof(value);
1945 } else if(!strcmp(name, "caplinewidth")) {
1946 config_caplinewidth = atof(value);
1947 } else if(!strcmp(name, "jpegquality")) {
1948 int val = atoi(value);
1950 if(val>100) val=100;
1951 config_jpegquality = val;
1952 } else if(!strcmp(name, "splinequality")) {
1953 int v = atoi(value);
1954 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1956 config_splinemaxerror = v;
1957 } else if(!strcmp(name, "fontquality")) {
1958 int v = atoi(value);
1959 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1961 config_fontsplinemaxerror = v;
1963 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1967 // --------------------------------------------------------------------
1969 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
1972 swf_GetCXForm(0, &cx, 1);
1975 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
1976 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
1977 c->br!=0 || c->bg!=0 || c->ba!=0 ||
1978 c->ar!=0 || c->ag!=0 || c->ab!=0)
1979 msg("<warning> CXForm not SWF-compatible");
1981 cx.a0 = (S16)(c->aa*256);
1982 cx.r0 = (S16)(c->rr*256);
1983 cx.g0 = (S16)(c->gg*256);
1984 cx.b0 = (S16)(c->bb*256);
1992 ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
1994 ArtVpath *vec = NULL;
2002 if(l2->type == gfx_moveTo) {
2004 } if(l2->type == gfx_lineTo) {
2006 } if(l2->type == gfx_splineTo) {
2007 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
2008 if(!parts) parts = 1;
2018 vec = art_new (ArtVpath, len);
2023 if(l2->type == gfx_moveTo) {
2024 vec[pos].code = ART_MOVETO;
2029 } else if(l2->type == gfx_lineTo) {
2030 vec[pos].code = ART_LINETO;
2035 } else if(l2->type == gfx_splineTo) {
2037 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
2038 if(!parts) parts = 1;
2039 for(i=0;i<=parts;i++) {
2040 double t = (double)i/(double)parts;
2041 vec[pos].code = ART_LINETO;
2042 vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
2043 vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
2052 vec[pos].code = ART_END;
2054 svp = art_svp_vpath_stroke (vec,
2055 (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
2056 ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
2057 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
2058 (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
2059 ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
2060 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
2062 miterLimit, //miter_limit
2069 gfxline_t* SVPtogfxline(ArtSVP*svp)
2074 for(t=0;t<svp->n_segs;t++) {
2075 size += svp->segs[t].n_points + 1;
2077 gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
2079 for(t=0;t<svp->n_segs;t++) {
2080 ArtSVPSeg* seg = &svp->segs[t];
2082 for(p=0;p<seg->n_points;p++) {
2083 lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
2084 ArtPoint* point = &seg->points[p];
2085 lines[pos].x = point->x;
2086 lines[pos].y = point->y;
2087 lines[pos].next = &lines[pos+1];
2092 lines[pos-1].next = 0;
2099 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
2101 swfoutput*obj = i->obj;
2103 RGBA*mem = (RGBA*)img->data;
2104 int bitid = getNewID(obj);
2106 int sizex = img->width;
2107 int sizey = img->height;
2108 int is_jpeg = i->jpeg;
2111 int newsizex=sizex, newsizey=sizey;
2114 if(is_jpeg && config_jpegsubpixels) {
2115 newsizex = (int)(targetwidth*config_jpegsubpixels+0.5);
2116 newsizey = (int)(targetheight*config_jpegsubpixels+0.5);
2117 } else if(!is_jpeg && config_ppmsubpixels) {
2118 newsizex = (int)(targetwidth*config_ppmsubpixels+0.5);
2119 newsizey = (int)(targetheight*config_ppmsubpixels+0.5);
2123 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
2126 /* TODO: cache images */
2130 if(newsizex<sizex || newsizey<sizey) {
2131 msg("<notice> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
2132 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
2133 *newwidth = sizex = newsizex;
2134 *newheight = sizey = newsizey;
2139 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
2140 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
2142 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
2144 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
2147 targetwidth, targetheight,
2148 /*newsizex, newsizey,*/
2149 num_colors>256?">":"", num_colors>256?256:num_colors);
2151 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
2152 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
2154 for(t=0;t<num_colors;t++) {
2155 printf("%02x%02x%02x%02x ",
2156 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
2162 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, config_jpegquality);
2170 static SRECT gfxline_getSWFbbox(gfxline_t*line)
2172 gfxbbox_t bbox = gfxline_getbbox(line);
2174 r.xmin = (int)(bbox.xmin*20);
2175 r.ymin = (int)(bbox.ymin*20);
2176 r.xmax = (int)(bbox.xmax*20);
2177 r.ymax = (int)(bbox.ymax*20);
2181 void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
2183 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2184 swfoutput*obj = i->obj;
2189 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
2190 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
2192 int newwidth=0,newheight=0;
2193 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
2196 double fx = (double)img->width / (double)newwidth;
2197 double fy = (double)img->height / (double)newheight;
2202 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
2203 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
2204 m.tx = (int)(matrix->tx*20);
2205 m.ty = (int)(matrix->ty*20);
2208 int myshapeid = getNewID(obj);
2209 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2211 swf_ShapeNew(&shape);
2212 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
2213 swf_SetU16(i->tag, myshapeid);
2214 SRECT r = gfxline_getSWFbbox(line);
2215 swf_SetRect(i->tag,&r);
2216 swf_SetShapeStyles(i->tag,shape);
2217 swf_ShapeCountBits(shape,NULL,NULL);
2218 swf_SetShapeBits(i->tag,shape);
2219 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2220 i->swflastx = i->swflasty = UNDEFINED_COORD;
2221 drawgfxline(obj, line);
2222 swf_ShapeSetEnd(i->tag);
2223 swf_ShapeFree(shape);
2225 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2226 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
2227 swf_ObjectPlace(i->tag,myshapeid,/*depth*/++i->depth,&i->page_matrix,&cxform2,NULL);
2230 void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
2232 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2233 swfoutput*obj = i->obj;
2238 if(i->clippos >= 127)
2240 msg("<warning> Too many clip levels.");
2244 int myshapeid = getNewID(obj);
2245 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2247 memset(&col, 0, sizeof(RGBA));
2249 swf_ShapeNew(&shape);
2250 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2251 swf_SetU16(i->tag,myshapeid);
2252 SRECT r = gfxline_getSWFbbox(line);
2253 swf_SetRect(i->tag,&r);
2254 swf_SetShapeStyles(i->tag,shape);
2255 swf_ShapeCountBits(shape,NULL,NULL);
2256 swf_SetShapeBits(i->tag,shape);
2257 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2258 i->swflastx = i->swflasty = UNDEFINED_COORD;
2259 drawgfxline(obj, line);
2260 swf_ShapeSetEnd(i->tag);
2261 swf_ShapeFree(shape);
2263 /* TODO: remember the bbox, and check all shapes against it */
2265 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2266 i->cliptags[i->clippos] = i->tag;
2267 i->clipshapes[i->clippos] = myshapeid;
2268 i->clipdepths[i->clippos] = ++i->depth;
2272 void swf_endclip(gfxdevice_t*dev)
2274 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2275 swfoutput*obj = i->obj;
2282 msg("<error> Invalid end of clipping region");
2286 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2287 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2289 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2291 int swf_setparameter(gfxdevice_t*dev, const char*key, const char*value)
2293 if(!strcmp(key, "next_bitmap_is_jpeg")) {
2294 ((swfoutput_internal*)dev->internal)->jpeg = 1;
2300 int gfxline_type(gfxline_t*line)
2306 int haszerosegments=0;
2308 if(line->type == gfx_moveTo) {
2311 } else if(line->type == gfx_lineTo) {
2315 } else if(line->type == gfx_splineTo) {
2317 if(tmpsplines>lines)
2322 if(lines==0 && splines==0) return 0;
2323 else if(lines==1 && splines==0) return 1;
2324 else if(lines==0 && splines==1) return 2;
2325 else if(splines==0) return 3;
2329 int gfxline_has_dots(gfxline_t*line)
2336 if(line->type == gfx_moveTo) {
2337 if(isline && dist < 1) {
2342 } else if(line->type == gfx_lineTo) {
2343 dist += fabs(line->x - x) + fabs(line->y - y);
2345 } else if(line->type == gfx_splineTo) {
2346 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2347 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2354 if(isline && dist < 1) {
2360 int gfxline_fix_short_edges(gfxline_t*line)
2364 if(line->type == gfx_lineTo) {
2365 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2368 } else if(line->type == gfx_splineTo) {
2369 if(fabs(line->sx - x) + fabs(line->sy - y) +
2370 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2383 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)
2385 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2386 swfoutput*obj = i->obj;
2387 int type = gfxline_type(line);
2388 int has_dots = gfxline_has_dots(line);
2390 /* TODO: * split line into segments, and perform this check for all segments */
2392 (width <= config_caplinewidth
2393 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2394 || (cap_style == gfx_capRound && type<=2))) {
2395 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2397 swfoutput_setstrokecolor(obj, color->r, color->g, color->b, color->a);
2398 swfoutput_setlinewidth(obj, width);
2401 drawgfxline(obj, line);
2403 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2405 gfxline_fix_short_edges(line);
2406 /* we need to convert the line into a polygon */
2407 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2408 gfxline_t*gfxline = SVPtogfxline(svp);
2409 dev->fill(dev, gfxline, color);
2412 void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2414 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2415 swfoutput*obj = i->obj;
2417 if(!config_ignoredraworder)
2419 swfoutput_setfillcolor(obj, color->r, color->g, color->b, color->a);
2423 drawgfxline(obj, line);
2424 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2426 void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2428 msg("<error> Gradient filling not implemented yet");