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_dumpfonts=0;
63 double config_ppmsubpixels=0;
64 double config_jpegsubpixels=0;
65 int config_opennewwindow=1;
66 int config_ignoredraworder=0;
67 int config_drawonlyshapes=0;
68 int config_jpegquality=85;
69 int config_storeallcharacters=0;
70 int config_enablezlib=0;
71 int config_insertstoptag=0;
72 int config_flashversion=5;
73 int config_splinemaxerror=1;
74 int config_fontsplinemaxerror=1;
75 int config_filloverlap=0;
77 float config_minlinewidth=0.05;
78 double config_caplinewidth=1;
80 typedef struct _swfoutput_internal
82 swfoutput*obj; // the swfoutput object where this internal struct resides
121 int pic_height[1024];
127 char fillstylechanged;
129 int jpeg; //next image type
136 chardata_t chardata[CHARDATAMAX];
143 /* during the transition to the gfxdevice interface:
144 a device which uses this swfoutput as target */
147 } swfoutput_internal;
149 void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
150 int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
151 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);
152 void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
153 void swf_endclip(gfxdevice_t*dev);
154 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);
155 void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
156 void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
157 void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
159 static swfoutput_internal* init_internal_struct()
161 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
162 memset(i, 0, sizeof(swfoutput_internal));
184 i->fillstylechanged = 0;
191 i->device.internal = (void*)i;
192 i->device.fillbitmap = swf_fillbitmap;
193 i->device.setparameter = swf_setparameter;
194 i->device.stroke = swf_stroke;
195 i->device.startclip = swf_startclip;
196 i->device.endclip = swf_endclip;
197 i->device.fill = swf_fill;
198 i->device.fillbitmap = swf_fillbitmap;
199 i->device.fillgradient = swf_fillgradient;
204 static int id_error = 0;
206 static U16 getNewID(struct swfoutput* obj)
208 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
209 if(i->currentswfid == 65535) {
211 msg("<error> ID Table overflow");
215 return ++i->currentswfid;
217 static U16 getNewDepth(struct swfoutput* obj)
219 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
220 if(i->depth == 65535) {
222 msg("<error> Depth Table overflow");
229 static void startshape(struct swfoutput* obj);
230 static void starttext(struct swfoutput* obj);
231 static void endshape(struct swfoutput* obj);
232 static void endtext(struct swfoutput* obj);
234 // matrix multiplication. changes p0
235 static void transform (plotxy*p0,struct swfmatrix*m)
238 x = m->m11*p0->x+m->m12*p0->y;
239 y = m->m21*p0->x+m->m22*p0->y;
244 // write a move-to command into the swf
245 static int moveto(struct swfoutput*obj, TAG*tag, plotxy p0)
247 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
248 int rx = (int)(p0.x*20);
249 int ry = (int)(p0.y*20);
250 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
251 swf_ShapeSetMove (tag, i->shape, rx,ry);
252 i->fillstylechanged = 0;
259 static int moveto(struct swfoutput*obj, TAG*tag, double x, double y)
261 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
265 return moveto(obj, tag, p);
267 static void addPointToBBox(struct swfoutput*obj, int px, int py)
269 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
275 swf_ExpandRect(&i->bboxrect, p);
277 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
281 /*static void plot(struct swfoutput*obj, int x, int y, TAG*tag)
283 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
284 int width = i->linewidth/4;
288 //swf_ShapeSetLine(tag, i->shape,-width,-width);
289 //swf_ShapeSetLine(tag, i->shape,width*2,0);
290 //swf_ShapeSetLine(tag, i->shape,0,width*2);
291 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
292 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
293 //swf_ShapeSetLine(tag, i->shape,width,width);
296 swf_ShapeSetLine(tag, i->shape,-width,0);
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,-width);
301 swf_ShapeSetLine(tag, i->shape,width,0);
303 addPointToBBox(obj, x-width ,y-width);
304 addPointToBBox(obj, x+width ,y+width);
307 // write a line-to command into the swf
308 static void lineto(struct swfoutput*obj, TAG*tag, plotxy p0)
310 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
311 int px = (int)(p0.x*20);
312 int py = (int)(p0.y*20);
313 int rx = (px-i->swflastx);
314 int ry = (py-i->swflasty);
316 swf_ShapeSetLine (tag, i->shape, rx,ry);
317 addPointToBBox(obj, i->swflastx,i->swflasty);
318 addPointToBBox(obj, px,py);
319 }/* else if(!i->fill) {
320 // treat lines of length 0 as plots, making them
321 // at least 1 twip wide so Flash will display them
322 plot(obj, i->swflastx, i->swflasty, tag);
329 static void lineto(struct swfoutput*obj, TAG*tag, double x, double y)
337 // write a spline-to command into the swf
338 static void splineto(struct swfoutput*obj, TAG*tag, plotxy control,plotxy end)
340 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
341 int lastlastx = i->swflastx;
342 int lastlasty = i->swflasty;
344 int cx = ((int)(control.x*20)-i->swflastx);
345 int cy = ((int)(control.y*20)-i->swflasty);
348 int ex = ((int)(end.x*20)-i->swflastx);
349 int ey = ((int)(end.y*20)-i->swflasty);
353 if(cx || cy || ex || ey) {
354 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
355 addPointToBBox(obj, lastlastx ,lastlasty );
356 addPointToBBox(obj, lastlastx+cx,lastlasty+cy);
357 addPointToBBox(obj, lastlastx+cx+ex,lastlasty+cy+ey);
358 }/* else if(!i->fill) {
359 // treat splines of length 0 as plots
360 plot(obj, lastlastx, lastlasty, tag);
365 /* write a line, given two points and the transformation
367 /*static void line(struct swfoutput*obj, TAG*tag, plotxy p0, plotxy p1)
369 moveto(obj, tag, p0);
370 lineto(obj, tag, p1);
373 void resetdrawer(struct swfoutput*obj)
375 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
380 static void stopFill(struct swfoutput*obj)
382 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
385 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
386 i->fillstylechanged = 1;
390 static void startFill(struct swfoutput*obj)
392 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
395 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
396 i->fillstylechanged = 1;
401 /* draw an outline. These are generated by pdf2swf and by t1lib
402 (representing characters). */
403 /*void drawpath(struct swfoutput*obj, SWF_OUTLINE*outline, struct swfmatrix*m, int log)
405 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
406 if( i->tag->id != ST_DEFINESHAPE &&
407 i->tag->id != ST_DEFINESHAPE2 &&
408 i->tag->id != ST_DEFINESHAPE3)
410 msg("<error> internal error: drawpath needs a shape tag, not %d\n",i->tag->id);
414 double lastx=0,lasty=0;
415 double firstx=0,firsty=0;
420 x += (outline->dest.x/(float)0xffff);
421 y += (outline->dest.y/(float)0xffff);
422 if(outline->type == SWF_PATHTYPE_MOVE)
424 //if(!init && fill && obj->drawmode != DRAWMODE_EOFILL && !ignoredraworder)
425 if(config_filloverlap && !init && i->fill && obj->drawmode != DRAWMODE_EOFILL) {
426 // drawmode=FILL (not EOFILL) means that
427 // seperate shapes do not cancel each other out.
428 // On SWF side, we need to start a new shape for each
429 // closed polygon, because SWF only knows EOFILL.
436 if(((int)(lastx*20) != (int)(firstx*20) ||
437 (int)(lasty*20) != (int)(firsty*20)) &&
446 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
447 line(obj,i->tag, p0, p1);
453 else if(outline->type == SWF_PATHTYPE_LINE)
461 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
462 line(obj,i->tag, p0,p1);
465 msg("<error> drawpath: unknown outline type:%d\n", outline->type);
469 outline = outline->link;
471 if(((int)(lastx*20) != (int)(firstx*20) ||
472 (int)(lasty*20) != (int)(firsty*20)) &&
481 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
482 line(obj, i->tag, p0, p1);
486 static inline int colorcompare(struct swfoutput*obj, RGBA*a,RGBA*b)
498 static SRECT getcharacterbbox(struct swfoutput*obj, SWFFONT*font)
500 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
503 memset(&r, 0, sizeof(r));
506 if(debug) printf("\n");
507 for(t=0;t<i->chardatapos;t++)
509 if(i->chardata[t].fontid != font->id) {
510 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
513 SRECT b = font->layout->bounds[i->chardata[t].charid];
514 b.xmin *= i->chardata[t].size;
515 b.ymin *= i->chardata[t].size;
516 b.xmax *= i->chardata[t].size;
517 b.ymax *= i->chardata[t].size;
522 b.xmin += i->chardata[t].x;
523 b.ymin += i->chardata[t].y;
524 b.xmax += i->chardata[t].x;
525 b.ymax += i->chardata[t].y;
527 /* until we solve the INTERNAL_SCALING problem (see below)
528 make sure the bounding box is big enough */
534 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
535 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
536 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
537 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
538 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
543 i->chardata[t].fontid,
545 i->chardata[t].charid
547 swf_ExpandRect2(&r, &b);
549 if(debug) printf("-----> (%f,%f,%f,%f)\n",
557 static void putcharacters(struct swfoutput*obj, TAG*tag)
559 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
563 color.r = i->chardata[0].color.r^255;
572 int charadvance[128];
575 int glyphbits=1; //TODO: can this be zero?
578 if(tag->id != ST_DEFINETEXT &&
579 tag->id != ST_DEFINETEXT2) {
580 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
583 if(!i->chardatapos) {
584 msg("<warning> putcharacters called with zero characters");
587 for(pass = 0; pass < 2; pass++)
597 advancebits++; // add sign bit
598 swf_SetU8(tag, glyphbits);
599 swf_SetU8(tag, advancebits);
602 for(t=0;t<=i->chardatapos;t++)
604 if(lastfontid != i->chardata[t].fontid ||
605 lastx!=i->chardata[t].x ||
606 lasty!=i->chardata[t].y ||
607 !colorcompare(obj,&color, &i->chardata[t].color) ||
609 lastsize != i->chardata[t].size ||
612 if(charstorepos && pass==0)
615 for(s=0;s<charstorepos;s++)
617 while(charids[s]>=(1<<glyphbits))
619 while(charadvance[s]>=(1<<advancebits))
623 if(charstorepos && pass==1)
625 tag->writeBit = 0; // Q&D
626 swf_SetBits(tag, 0, 1); // GLYPH Record
627 swf_SetBits(tag, charstorepos, 7); // number of glyphs
629 for(s=0;s<charstorepos;s++)
631 swf_SetBits(tag, charids[s], glyphbits);
632 swf_SetBits(tag, charadvance[s], advancebits);
637 if(pass == 1 && t<i->chardatapos)
643 if(lastx != i->chardata[t].x ||
644 lasty != i->chardata[t].y)
646 newx = i->chardata[t].x;
647 newy = i->chardata[t].y;
653 if(!colorcompare(obj,&color, &i->chardata[t].color))
655 color = i->chardata[t].color;
658 font.id = i->chardata[t].fontid;
659 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
662 tag->writeBit = 0; // Q&D
663 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
666 lastfontid = i->chardata[t].fontid;
667 lastx = i->chardata[t].x;
668 lasty = i->chardata[t].y;
669 lastsize = i->chardata[t].size;
672 if(t==i->chardatapos)
676 int nextt = t==i->chardatapos-1?t:t+1;
677 int rel = i->chardata[nextt].x-i->chardata[t].x;
678 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
680 lastx=i->chardata[nextt].x;
684 lastx=i->chardata[t].x;
686 charids[charstorepos] = i->chardata[t].charid;
687 charadvance[charstorepos] = advance;
694 static void putcharacter(struct swfoutput*obj, int fontid, int charid, int x,int y, int size, RGBA color)
696 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
697 if(i->chardatapos == CHARDATAMAX)
699 msg("<warning> Character buffer too small. SWF will be slightly bigger");
703 i->chardata[i->chardatapos].fontid = fontid;
704 i->chardata[i->chardatapos].charid = charid;
705 i->chardata[i->chardatapos].x = x;
706 i->chardata[i->chardatapos].y = y;
707 i->chardata[i->chardatapos].color = color;
708 i->chardata[i->chardatapos].size = size;
712 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
713 So if we set this value to high, the char coordinates will overflow.
714 If we set it to low, however, the char positions will be inaccurate */
715 #define FONT_INTERNAL_SIZE 4
717 static int font_active = 0;
718 static char* font_active_filename = 0;
720 /* process a character. */
721 static int drawchar(struct swfoutput*obj, SWFFONT *swffont, char*character, int charnr, int u, swfmatrix*m, gfxcolor_t*col)
723 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
725 msg("<warning> Font is NULL");
729 int charid = getCharID(swffont, charnr, character, u);
732 sprintf(buf, "%s.usage", font_active_filename);
733 FILE*fi = fopen(buf, "ab+");
735 fprintf(fi, "%d %d %d %s\n", charnr, u, charid, character);
738 msg("<error> Couldn't write to %s", buf);
742 msg("<warning> Didn't find character '%s' (c=%d,u=%d) in current charset (%s, %d characters)",
743 FIXNULL(character),charnr, u, FIXNULL((char*)swffont->name), swffont->numchars);
746 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
747 msg("<warning> Character '%s' (c=%d,u=%d), glyph %d in current charset (%s, %d characters) is empty",
748 FIXNULL(character),charnr, u, charid, FIXNULL((char*)swffont->name), swffont->numchars);
760 float det = ((m->m11*m->m22)-(m->m21*m->m12));
761 if(fabs(det) < 0.0005) {
762 /* x direction equals y direction- the text is invisible */
765 det = 20*FONT_INTERNAL_SIZE / det;
768 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
769 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
771 RGBA rgba = *(RGBA*)col;
772 putcharacter(obj, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
773 swf_FontUseGlyph(swffont, charid);
778 SWF_OUTLINE*outline = font->getOutline(character, charnr);
779 char* charname = character;
782 msg("<warning> Didn't find character '%s' (%d) in current charset (%s)",
783 FIXNULL(character),charnr,FIXNULL(font->getName()));
802 drawpath(tag, outline, &m2, 0);
807 static void endtext(swfoutput*obj)
809 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
813 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
814 swf_SetU16(i->tag, i->textid);
817 r = getcharacterbbox(obj, obj->swffont);
819 swf_SetRect(i->tag,&r);
822 swf_GetMatrix(0, &m); /* set unit matrix- the real matrix is in the placeobject */
823 swf_SetMatrix(i->tag,&m);
825 msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
827 putcharacters(obj, i->tag);
829 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
831 swf_MatrixJoin(&m2,&obj->fontmatrix, &i->page_matrix);
833 swf_ObjectPlace(i->tag,i->textid,getNewDepth(obj),&m2,NULL,NULL);
837 int getCharID(SWFFONT *font, int charnr, char *charname, int u)
840 if(charname && font->glyphnames) {
841 for(t=0;t<font->numchars;t++) {
842 if(font->glyphnames[t] && !strcmp(font->glyphnames[t],charname)) {
843 msg("<debug> Char [%d,>%s<,%d] maps to %d\n", charnr, charname, u, t);
847 /* if we didn't find the character, maybe
848 we can find the capitalized version */
849 for(t=0;t<font->numchars;t++) {
850 if(font->glyphnames[t] && !strcasecmp(font->glyphnames[t],charname)) {
851 msg("<debug> Char [%d,>>%s<<,%d] maps to %d\n", charnr, charname, u, t);
857 if(u>0 && font->encoding != 255) {
858 /* try to use the unicode id */
859 if(u>=0 && u<font->maxascii && font->ascii2glyph[u]>=0) {
860 msg("<debug> Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->ascii2glyph[u]);
861 return font->ascii2glyph[u];
865 if(font->encoding != FONT_ENCODING_UNICODE) {
866 /* the following only works if the font encoding
867 is US-ASCII based. It's needed for fonts which return broken unicode
869 if(charnr>=0 && charnr<font->maxascii && font->ascii2glyph[charnr]>=0) {
870 msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, font->ascii2glyph[charnr]);
871 return font->ascii2glyph[charnr];
875 if(charnr>=0 && charnr<font->numchars) {
876 msg("<debug> Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr);
883 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
884 void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename)
886 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
888 fontlist_t*last=0,*iterator;
890 msg("<error> No fontid");
894 if(obj->swffont && obj->swffont->name && !strcmp((char*)obj->swffont->name,fontid))
897 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
898 with multiple fonts */
901 iterator = i->fontlist;
903 if(!strcmp((char*)iterator->swffont->name,fontid)) {
904 obj->swffont = iterator->swffont;
908 iterator = iterator->next;
912 msg("<error> No filename given for font- internal error?");
916 swf_SetLoadFontParameters(64,/*skip unused*/0,/*full unicode*/1);
917 SWFFONT*swffont = swf_LoadFont(filename);
919 if(config_dumpfonts) {
921 font_active_filename = strdup(filename);
925 msg("<warning> Couldn't load font %s (%s)", fontid, filename);
926 swffont = swf_LoadFont(0);
929 if(swffont->glyph2ascii) {
932 /* check whether the Unicode indices look o.k.
933 If they don't, disable the unicode lookup by setting
934 the encoding to 255 */
935 for(t=0;t<swffont->numchars;t++) {
936 int c = swffont->glyph2ascii[t];
937 if(c && c < 32 && swffont->glyph[t].shape->bitlen > 16) {
938 // the character maps into the unicode control character range
939 // between 0001-001f. Yet it is not empty. Treat the one
940 // mapping as broken, and look how many of those we find.
945 msg("<warning> Font %s has bad unicode mapping", fontid);
946 swffont->encoding = 255;
950 if(swffont->encoding != FONT_ENCODING_UNICODE && swffont->encoding != 255) {
951 msg("<warning> Non-unicode mapping for font %s (%s)", fontid, filename);
954 swf_FontSetID(swffont, getNewID(obj));
956 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
957 // print font information
958 msg("<debug> Font %s (%s)",fontid, filename);
959 msg("<debug> | ID: %d", swffont->id);
960 msg("<debug> | Version: %d", swffont->version);
961 msg("<debug> | Name: %s", swffont->name);
962 msg("<debug> | Numchars: %d", swffont->numchars);
963 msg("<debug> | Maxascii: %d", swffont->maxascii);
964 msg("<debug> | Style: %d", swffont->style);
965 msg("<debug> | Encoding: %d", swffont->encoding);
966 for(int iii=0; iii<swffont->numchars;iii++) {
967 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,
968 swffont->layout->bounds[iii].xmin/20.0,
969 swffont->layout->bounds[iii].ymin/20.0,
970 swffont->layout->bounds[iii].xmax/20.0,
971 swffont->layout->bounds[iii].ymax/20.0
974 for(t=0;t<swffont->maxascii;t++) {
975 if(swffont->ascii2glyph[t] == iii)
976 msg("<debug> | - maps to %d",t);
981 /* set the font name to the ID we use here */
982 if(swffont->name) free(swffont->name);
983 swffont->name = (U8*)strdup(fontid);
985 iterator = new fontlist_t;
986 iterator->swffont = swffont;
990 last->next = iterator;
992 i->fontlist = iterator;
994 obj->swffont = swffont;
997 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
999 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1000 fontlist_t *iterator = i->fontlist;
1002 if(!strcmp((char*)iterator->swffont->name,fontid))
1004 iterator = iterator->next;
1009 /* set's the matrix which is to be applied to characters drawn by
1010 swfoutput_drawchar() */
1011 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
1012 double m21,double m22)
1014 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1015 if(obj->fontm11 == m11 &&
1016 obj->fontm12 == m12 &&
1017 obj->fontm21 == m21 &&
1018 obj->fontm22 == m22)
1028 m.sx = (U32)(((obj->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((obj->fontm12)*65536)/FONT_INTERNAL_SIZE);
1029 m.r0 = (U32)(((obj->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((obj->fontm22)*65536)/FONT_INTERNAL_SIZE);
1032 obj->fontmatrix = m;
1035 /* draws a character at x,y. */
1036 int swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr, int u, gfxcolor_t* color)
1038 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1040 m.m11 = obj->fontm11;
1041 m.m12 = obj->fontm12;
1042 m.m21 = obj->fontm21;
1043 m.m22 = obj->fontm22;
1046 return drawchar(obj, obj->swffont, character, charnr, u, &m, color);
1049 static void endpage(struct swfoutput*obj)
1051 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1057 swfoutput_endclip(obj);
1058 i->pagefinished = 1;
1061 void swfoutput_pagefeed(struct swfoutput*obj)
1063 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1065 if(!i->pagefinished)
1068 if(config_insertstoptag) {
1070 atag = action_Stop(atag);
1071 atag = action_End(atag);
1072 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
1073 swf_ActionSet(i->tag,atag);
1075 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
1078 for(i->depth;i->depth>i->startdepth;i->depth--) {
1079 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
1080 swf_SetU16(i->tag,i->depth);
1082 i->depth = i->startdepth;
1085 static void setBackground(struct swfoutput*obj, int x1, int y1, int x2, int y2)
1087 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1089 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
1093 int shapeid = getNewID(obj);
1098 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
1100 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
1101 swf_SetU16(i->tag,shapeid);
1102 swf_SetRect(i->tag,&r);
1103 swf_SetShapeHeader(i->tag,s);
1104 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
1105 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
1106 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
1107 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
1108 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
1109 swf_ShapeSetEnd(i->tag);
1111 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
1112 swf_ObjectPlace(i->tag,shapeid,getNewDepth(obj),0,0,0);
1113 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
1114 swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(obj),0,0,0,65535);
1115 i->cliptag = i->tag;
1118 void swfoutput_newpage(struct swfoutput*obj, int pageNum, int movex, int movey, int x1, int y1, int x2, int y2)
1120 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1121 if(!i->firstpage && !i->pagefinished)
1124 swf_GetMatrix(0, &i->page_matrix);
1125 i->page_matrix.tx = movex*20;
1126 i->page_matrix.ty = movey*20;
1128 if(i->cliptag && i->frameno == i->lastframeno) {
1130 swf_GetPlaceObject(i->cliptag, &obj);
1131 obj.clipdepth = i->depth;
1132 swf_ResetTag(i->cliptag, i->cliptag->id);
1133 swf_SetPlaceObject(i->cliptag, &obj);
1134 swf_PlaceObjectFree(&obj);
1142 msg("<notice> processing page %d (%dx%d:%d:%d)", pageNum,x2-x1,y2-y1, x1, y1);
1144 x1*=20;y1*=20;x2*=20;y2*=20;
1146 /* set clipping/background rectangle */
1147 /* TODO: this should all be done in SWFOutputDev */
1148 setBackground(obj, x1, y1, x2, y2);
1150 /* increase SWF's bounding box */
1156 swf_ExpandRect2(&i->swf.movieSize, &r);
1158 i->lastframeno = i->frameno;
1160 i->pagefinished = 0;
1163 /* initialize the swf writer */
1164 void swfoutput_init(struct swfoutput* obj)
1166 memset(obj, 0, sizeof(struct swfoutput));
1167 obj->internal = init_internal_struct();
1168 ((swfoutput_internal*)obj->internal)->obj = obj;
1170 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1175 msg("<verbose> initializing swf output for size %d*%d\n", i->max_x,i->max_y);
1179 memset(&i->swf,0x00,sizeof(SWF));
1181 i->swf.fileVersion = config_flashversion;
1182 i->swf.frameRate = 0x0040; // 1 frame per 4 seconds
1183 i->swf.movieSize.xmin = 0;
1184 i->swf.movieSize.ymin = 0;
1185 i->swf.movieSize.xmax = 0;
1186 i->swf.movieSize.ymax = 0;
1188 i->swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
1189 i->tag = i->swf.firstTag;
1190 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
1191 swf_SetRGB(i->tag,&rgb);
1193 i->startdepth = i->depth = 0;
1196 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1199 static void startshape(struct swfoutput*obj)
1201 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1210 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
1212 swf_ShapeNew(&i->shape);
1213 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&obj->strokergb);
1214 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&obj->fillrgb);
1216 i->shapeid = getNewID(obj);
1218 msg("<debug> Using shape id %d", i->shapeid);
1220 swf_SetU16(i->tag,i->shapeid); // ID
1222 i->bboxrectpos = i->tag->len;
1226 r.xmax = 20*i->max_x;
1227 r.ymax = 20*i->max_y;
1228 swf_SetRect(i->tag,&r);
1230 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
1232 swf_SetShapeStyles(i->tag,i->shape);
1233 swf_ShapeCountBits(i->shape,NULL,NULL);
1234 swf_SetShapeBits(i->tag,i->shape);
1236 /* TODO: do we really need this? */
1237 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
1238 i->swflastx=i->swflasty=0;
1240 i->shapeisempty = 1;
1243 static void starttext(struct swfoutput*obj)
1245 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1249 i->textid = getNewID(obj);
1251 i->swflastx=i->swflasty=0;
1255 /* TODO: move to ../lib/rfxswf */
1256 void changeRect(struct swfoutput*obj, TAG*tag, int pos, SRECT*newrect)
1258 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1259 /* determine length of old rect */
1263 swf_GetRect(tag, &old);
1264 swf_ResetReadBits(tag);
1265 int pos_end = tag->pos;
1267 int len = tag->len - pos_end;
1268 U8*data = (U8*)malloc(len);
1269 memcpy(data, &tag->data[pos_end], len);
1272 swf_SetRect(tag, newrect);
1273 swf_SetBlock(tag, data, len);
1275 tag->pos = tag->readBit = 0;
1278 void cancelshape(swfoutput*obj)
1280 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1281 /* delete old shape tag */
1283 i->tag = i->tag->prev;
1284 swf_DeleteTag(todel);
1285 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
1287 i->bboxrectpos = -1;
1290 void fixAreas(swfoutput*obj)
1292 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1293 if(!i->shapeisempty && i->fill &&
1294 (i->bboxrect.xmin == i->bboxrect.xmax ||
1295 i->bboxrect.ymin == i->bboxrect.ymax) &&
1296 config_minlinewidth >= 0.001
1298 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1299 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1300 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1303 SRECT r = i->bboxrect;
1305 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1306 /* this thing comes down to a single dot- nothing to fix here */
1312 RGBA save_col = obj->strokergb;
1313 int save_width = i->linewidth;
1315 obj->strokergb = obj->fillrgb;
1316 i->linewidth = (int)(config_minlinewidth*20);
1317 if(i->linewidth==0) i->linewidth = 1;
1321 moveto(obj, i->tag, r.xmin/20.0,r.ymin/20.0);
1322 lineto(obj, i->tag, r.xmax/20.0,r.ymax/20.0);
1324 obj->strokergb = save_col;
1325 i->linewidth = save_width;
1330 static void endshape_noput(swfoutput*obj)
1332 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1335 //changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect);
1338 swf_ShapeFree(i->shape);
1344 static void endshape(swfoutput*obj)
1346 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1352 if(i->shapeisempty ||
1354 (i->bboxrect.xmin == i->bboxrect.xmax &&
1355 i->bboxrect.ymin == i->bboxrect.ymax))
1357 // delete the shape again, we didn't do anything
1358 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1359 i->bboxrect.xmin /20.0,
1360 i->bboxrect.ymin /20.0,
1361 i->bboxrect.xmax /20.0,
1362 i->bboxrect.ymax /20.0
1368 swf_ShapeSetEnd(i->tag);
1370 changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect);
1372 msg("<trace> Placing shape id %d", i->shapeid);
1374 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1375 swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(obj),&i->page_matrix,NULL,NULL);
1377 swf_ShapeFree(i->shape);
1380 i->bboxrectpos = -1;
1386 sprintf(text, "id%d", i->shapeid);
1388 points[0].x = i->bboxrect.xmin;
1389 points[0].y = i->bboxrect.ymin;
1390 points[1].x = i->bboxrect.xmax;
1391 points[1].y = i->bboxrect.ymin;
1392 points[2].x = i->bboxrect.xmax;
1393 points[2].y = i->bboxrect.ymax;
1394 points[3].x = i->bboxrect.xmin;
1395 points[3].y = i->bboxrect.ymax;
1396 swfoutput_namedlink(obj,text,points);
1400 void wipeSWF(SWF*swf)
1402 TAG*tag = swf->firstTag;
1404 TAG*next = tag->next;
1405 if(tag->id != ST_SETBACKGROUNDCOLOR &&
1406 tag->id != ST_END &&
1407 tag->id != ST_SHOWFRAME) {
1415 void swfoutput_finalize(struct swfoutput*obj)
1417 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1419 if(i->tag && i->tag->id == ST_END)
1420 return; //already done
1422 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1423 swfoutput_pagefeed(obj);
1426 fontlist_t *tmp,*iterator = i->fontlist;
1428 TAG*mtag = i->swf.firstTag;
1429 if(iterator->swffont) {
1430 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1431 /*if(!storeallcharacters)
1432 swf_FontReduce(iterator->swffont);*/
1433 swf_FontSetDefine2(mtag, iterator->swffont);
1436 iterator = iterator->next;
1438 i->tag = swf_InsertTag(i->tag,ST_END);
1439 TAG* tag = i->tag->prev;
1441 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1442 and the ST_END- they confuse the flash player */
1443 while(tag->id == ST_REMOVEOBJECT2) {
1444 TAG* prev = tag->prev;
1454 SWF* swfoutput_get(struct swfoutput*obj)
1456 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1458 swfoutput_finalize(obj);
1460 return swf_CopySWF(&i->swf);
1463 void swfoutput_getdimensions(struct swfoutput*obj, int*x1, int*y1, int*x2, int*y2)
1465 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1466 if(x1) *x1 = i->swf.movieSize.xmin/20;
1467 if(y1) *y1 = i->swf.movieSize.ymin/20;
1468 if(x2) *x2 = i->swf.movieSize.xmax/20;
1469 if(y2) *y2 = i->swf.movieSize.ymax/20;
1472 int swfoutput_save(struct swfoutput* obj, char*filename)
1474 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1475 swfoutput_finalize(obj);
1479 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1484 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1488 if(config_enablezlib || config_flashversion>=6) {
1489 if FAILED(swf_WriteSWC(fi,&i->swf))
1490 msg("<error> WriteSWC() failed.\n");
1492 if FAILED(swf_WriteSWF(fi,&i->swf))
1493 msg("<error> WriteSWF() failed.\n");
1501 /* Perform cleaning up, complete the swf, and write it out. */
1502 void swfoutput_destroy(struct swfoutput* obj)
1504 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1506 /* not initialized yet- nothing to destroy */
1510 fontlist_t *tmp,*iterator = i->fontlist;
1512 if(iterator->swffont) {
1513 swf_FontFree(iterator->swffont);iterator->swffont=0;
1516 iterator = iterator->next;
1519 swf_FreeTags(&i->swf);
1522 memset(obj, 0, sizeof(swfoutput));
1525 static void swfoutput_setfillcolor(swfoutput* obj, U8 r, U8 g, U8 b, U8 a)
1527 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1528 if(obj->fillrgb.r == r &&
1529 obj->fillrgb.g == g &&
1530 obj->fillrgb.b == b &&
1531 obj->fillrgb.a == a) return;
1541 static void swfoutput_setstrokecolor(swfoutput* obj, U8 r, U8 g, U8 b, U8 a)
1543 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1544 if(obj->strokergb.r == r &&
1545 obj->strokergb.g == g &&
1546 obj->strokergb.b == b &&
1547 obj->strokergb.a == a) return;
1551 obj->strokergb.r = r;
1552 obj->strokergb.g = g;
1553 obj->strokergb.b = b;
1554 obj->strokergb.a = a;
1557 static void swfoutput_setlinewidth(struct swfoutput*obj, double _linewidth)
1559 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1560 if(i->linewidth == (U16)(_linewidth*20))
1565 i->linewidth = (U16)(_linewidth*20);
1569 static void drawlink(struct swfoutput*obj, ActionTAG*,ActionTAG*, swfcoord*points, char mouseover);
1571 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1573 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1575 if(!strncmp("http://pdf2swf:", url, 15)) {
1576 char*tmp = strdup(url);
1577 int l = strlen(tmp);
1580 swfoutput_namedlink(obj, tmp+15, points);
1590 if(!config_opennewwindow)
1591 actions = action_GetUrl(0, url, "_parent");
1593 actions = action_GetUrl(0, url, "_this");
1594 actions = action_End(actions);
1596 drawlink(obj, actions, 0, points,0);
1598 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1600 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1608 actions = action_GotoFrame(0, page);
1609 actions = action_End(actions);
1611 drawlink(obj, actions, 0, points,0);
1614 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1615 of the viewer objects, like subtitles, index elements etc.
1617 void swfoutput_namedlink(struct swfoutput*obj, char*name, swfcoord*points)
1619 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1620 ActionTAG *actions1,*actions2;
1621 char*tmp = strdup(name);
1629 if(!strncmp(tmp, "call:", 5))
1631 char*x = strchr(&tmp[5], ':');
1633 actions1 = action_PushInt(0, 0); //number of parameters (0)
1634 actions1 = action_PushString(actions1, &tmp[5]); //function name
1635 actions1 = action_CallFunction(actions1);
1638 actions1 = action_PushString(0, x+1); //parameter
1639 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1640 actions1 = action_PushString(actions1, &tmp[5]); //function name
1641 actions1 = action_CallFunction(actions1);
1643 actions2 = action_End(0);
1648 actions1 = action_PushString(0, "/:subtitle");
1649 actions1 = action_PushString(actions1, name);
1650 actions1 = action_SetVariable(actions1);
1651 actions1 = action_End(actions1);
1653 actions2 = action_PushString(0, "/:subtitle");
1654 actions2 = action_PushString(actions2, "");
1655 actions2 = action_SetVariable(actions2);
1656 actions2 = action_End(actions2);
1659 drawlink(obj, actions1, actions2, points,mouseover);
1661 swf_ActionFree(actions1);
1662 swf_ActionFree(actions2);
1666 static void drawlink(struct swfoutput*obj, ActionTAG*actions1, ActionTAG*actions2, swfcoord*points, char mouseover)
1668 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1673 struct plotxy p1,p2,p3,p4;
1677 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1681 int buttonid = getNewID(obj);
1684 if(points[t].x>xmax) xmax=points[t].x;
1685 if(points[t].y>ymax) ymax=points[t].y;
1686 if(points[t].x<xmin) xmin=points[t].x;
1687 if(points[t].y<ymin) ymin=points[t].y;
1690 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1691 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1693 /* the following code subtracts the upper left edge from all coordinates,
1694 and set's posx,posy so that ST_PLACEOBJECT is used with a matrix.
1695 Necessary for preprocessing with swfcombine. */
1696 posx = xmin; posy = ymin;
1697 p1.x-=posx;p2.x-=posx;p3.x-=posx;p4.x-=posx;
1698 p1.y-=posy;p2.y-=posy;p3.y-=posy;p4.y-=posy;
1699 xmin -= posx; ymin -= posy;
1700 xmax -= posx; ymax -= posy;
1703 myshapeid = 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 = 0;
1707 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1708 swf_SetU16(i->tag, myshapeid);
1709 r.xmin = (int)(xmin*20);
1710 r.ymin = (int)(ymin*20);
1711 r.xmax = (int)(xmax*20);
1712 r.ymax = (int)(ymax*20);
1713 swf_SetRect(i->tag,&r);
1714 swf_SetShapeStyles(i->tag,i->shape);
1715 swf_ShapeCountBits(i->shape,NULL,NULL);
1716 swf_SetShapeBits(i->tag,i->shape);
1717 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1718 i->swflastx = i->swflasty = 0;
1719 moveto(obj, i->tag, p1);
1720 lineto(obj, i->tag, p2);
1721 lineto(obj, i->tag, p3);
1722 lineto(obj, i->tag, p4);
1723 lineto(obj, i->tag, p1);
1724 swf_ShapeSetEnd(i->tag);
1727 myshapeid2 = getNewID(obj);
1728 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1729 swf_ShapeNew(&i->shape);
1730 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1732 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1733 swf_SetU16(i->tag, myshapeid2);
1734 r.xmin = (int)(xmin*20);
1735 r.ymin = (int)(ymin*20);
1736 r.xmax = (int)(xmax*20);
1737 r.ymax = (int)(ymax*20);
1738 swf_SetRect(i->tag,&r);
1739 swf_SetShapeStyles(i->tag,i->shape);
1740 swf_ShapeCountBits(i->shape,NULL,NULL);
1741 swf_SetShapeBits(i->tag,i->shape);
1742 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1743 i->swflastx = i->swflasty = 0;
1744 moveto(obj, i->tag, p1);
1745 lineto(obj, i->tag, p2);
1746 lineto(obj, i->tag, p3);
1747 lineto(obj, i->tag, p4);
1748 lineto(obj, i->tag, p1);
1749 swf_ShapeSetEnd(i->tag);
1753 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1754 swf_SetU16(i->tag,buttonid); //id
1755 swf_ButtonSetFlags(i->tag, 0); //menu=no
1756 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1757 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1758 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1759 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1760 swf_SetU8(i->tag,0);
1761 swf_ActionSet(i->tag,actions1);
1762 swf_SetU8(i->tag,0);
1766 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1767 swf_SetU16(i->tag,buttonid); //id
1768 swf_ButtonSetFlags(i->tag, 0); //menu=no
1769 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1770 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1771 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1772 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1773 swf_SetU8(i->tag,0); // end of button records
1774 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1775 swf_ActionSet(i->tag,actions1);
1777 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1778 swf_ActionSet(i->tag,actions2);
1779 swf_SetU8(i->tag,0);
1780 swf_ButtonPostProcess(i->tag, 2);
1782 swf_SetU8(i->tag,0);
1783 swf_ButtonPostProcess(i->tag, 1);
1787 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1789 if(posx!=0 || posy!=0) {
1791 p.x = (int)(posx*20);
1792 p.y = (int)(posy*20);
1793 p = swf_TurnPoint(p, &i->page_matrix);
1798 swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&m,0,0);
1800 swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&i->page_matrix,0,0);
1807 for(t=0;t<picpos;t++)
1809 if(pic_xids[t] == xid &&
1810 pic_yids[t] == yid) {
1811 width = pic_width[t];
1812 height = pic_height[t];
1816 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1817 pic_xids[picpos] = xid;
1818 pic_yids[picpos] = yid;
1819 pic_width[picpos] = width;
1820 pic_height[picpos] = height;
1823 pic[width*y+x] = buf[0];
1827 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1828 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1832 xid += x*r+x*b*3+x*g*7+x*a*11;
1833 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1835 for(t=0;t<picpos;t++)
1837 if(pic_xids[t] == xid &&
1838 pic_yids[t] == yid) {
1846 static void drawgfxline(struct swfoutput*obj, gfxline_t*line)
1848 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1849 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1854 /* check whether the next segment is zero */
1855 if(line->type == gfx_moveTo) {
1856 msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
1857 moveto(obj, i->tag, line->x, line->y);
1858 px = lastx = line->x;
1859 py = lasty = line->y;
1861 } if(line->type == gfx_lineTo) {
1862 msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
1863 lineto(obj, i->tag, line->x, line->y);
1867 } else if(line->type == gfx_splineTo) {
1868 msg("<trace> ======== splineTo %.2f %.2f", line->x, line->y);
1870 s.x = line->sx;p.x = line->x;
1871 s.y = line->sy;p.y = line->y;
1872 splineto(obj, i->tag, s, p);
1881 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)
1883 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1884 gfxdevice_t*dev = &i->device;
1885 dev->stroke(dev, line, width, col, cap_style, joint_style, miterLimit);
1887 void swfoutput_fillgfxline(struct swfoutput*obj, gfxline_t*line, gfxcolor_t*col)
1889 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1890 gfxdevice_t*dev = &i->device;
1891 dev->fill(dev, line, col);
1893 void swfoutput_startclip(struct swfoutput*obj, gfxline_t*line)
1895 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1896 gfxdevice_t*dev = &i->device;
1897 dev->startclip(dev, line);
1899 void swfoutput_endclip(struct swfoutput*obj)
1901 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1902 gfxdevice_t*dev = &i->device;
1906 #define IMAGE_TYPE_JPEG 0
1907 #define IMAGE_TYPE_LOSSLESS 1
1909 static void swfoutput_drawimage(struct swfoutput*obj, RGBA* data, int sizex,int sizey,
1910 double x1,double y1,
1911 double x2,double y2,
1912 double x3,double y3,
1913 double x4,double y4, int type)
1915 swfoutput_internal*i = (swfoutput_internal*)obj->internal;
1919 double l1 = sqrt((x4-x1)*(x4-x1) + (y4-y1)*(y4-y1));
1920 double l2 = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
1922 gfxline_t p1,p2,p3,p4,p5;
1923 p1.type=gfx_moveTo;p1.x=x1; p1.y=y1;p1.next=&p2;
1924 p2.type=gfx_lineTo;p2.x=x2; p2.y=y2;p2.next=&p3;
1925 p3.type=gfx_lineTo;p3.x=x3; p3.y=y3;p3.next=&p4;
1926 p4.type=gfx_lineTo;p4.x=x4; p4.y=y4;p4.next=&p5;
1927 p5.type=gfx_lineTo;p5.x=x1; p5.y=y1;p5.next=0;
1929 {p1.x = (int)(p1.x*20)/20.0;
1930 p1.y = (int)(p1.y*20)/20.0;
1931 p2.x = (int)(p2.x*20)/20.0;
1932 p2.y = (int)(p2.y*20)/20.0;
1933 p3.x = (int)(p3.x*20)/20.0;
1934 p3.y = (int)(p3.y*20)/20.0;
1935 p4.x = (int)(p4.x*20)/20.0;
1936 p4.y = (int)(p4.y*20)/20.0;
1937 p5.x = (int)(p5.x*20)/20.0;
1938 p5.y = (int)(p5.y*20)/20.0;
1945 m.m00 = (p4.x-p1.x)/sizex; m.m10 = (p2.x-p1.x)/sizey;
1946 m.m01 = (p4.y-p1.y)/sizex; m.m11 = (p2.y-p1.y)/sizey;
1951 img.data = (gfxcolor_t*)data;
1955 if(type == IMAGE_TYPE_JPEG)
1956 /* TODO: pass image_dpi to device instead */
1957 i->device.setparameter(&i->device, "next_bitmap_is_jpeg", "1");
1959 i->device.fillbitmap(&i->device, &p1, &img, &m, 0);
1962 void swfoutput_drawimagejpeg(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1963 double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
1965 swfoutput_drawimage(obj,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_JPEG);
1968 void swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1969 double x1,double y1, double x2,double y2, double x3,double y3, double x4,double y4)
1971 swfoutput_drawimage(obj,mem,sizex,sizey,x1,y1,x2,y2,x3,y3,x4,y4, IMAGE_TYPE_LOSSLESS);
1974 void swfoutput_setparameter(char*name, char*value)
1976 if(!strcmp(name, "jpegsubpixels")) {
1977 config_jpegsubpixels = atof(value);
1978 } else if(!strcmp(name, "ppmsubpixels")) {
1979 config_ppmsubpixels = atof(value);
1980 } else if(!strcmp(name, "drawonlyshapes")) {
1981 config_drawonlyshapes = atoi(value);
1982 } else if(!strcmp(name, "ignoredraworder")) {
1983 config_ignoredraworder = atoi(value);
1984 } else if(!strcmp(name, "filloverlap")) {
1985 config_filloverlap = atoi(value);
1986 } else if(!strcmp(name, "linksopennewwindow")) {
1987 config_opennewwindow = atoi(value);
1988 } else if(!strcmp(name, "opennewwindow")) {
1989 config_opennewwindow = atoi(value);
1990 } else if(!strcmp(name, "storeallcharacters")) {
1991 config_storeallcharacters = atoi(value);
1992 } else if(!strcmp(name, "enablezlib")) {
1993 config_enablezlib = atoi(value);
1994 } else if(!strcmp(name, "insertstop")) {
1995 config_insertstoptag = atoi(value);
1996 } else if(!strcmp(name, "protected")) {
1997 config_protect = atoi(value);
1998 } else if(!strcmp(name, "flashversion")) {
1999 config_flashversion = atoi(value);
2000 } else if(!strcmp(name, "minlinewidth")) {
2001 config_minlinewidth = atof(value);
2002 } else if(!strcmp(name, "caplinewidth")) {
2003 config_caplinewidth = atof(value);
2004 } else if(!strcmp(name, "dumpfonts")) {
2005 config_dumpfonts = atoi(value);
2006 } else if(!strcmp(name, "jpegquality")) {
2007 int val = atoi(value);
2009 if(val>100) val=100;
2010 config_jpegquality = val;
2011 } else if(!strcmp(name, "splinequality")) {
2012 int v = atoi(value);
2013 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
2015 config_splinemaxerror = v;
2016 } else if(!strcmp(name, "fontquality")) {
2017 int v = atoi(value);
2018 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
2020 config_fontsplinemaxerror = v;
2022 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
2026 // --------------------------------------------------------------------
2028 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
2031 swf_GetCXForm(0, &cx, 1);
2034 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
2035 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
2036 c->br!=0 || c->bg!=0 || c->ba!=0 ||
2037 c->ar!=0 || c->ag!=0 || c->ab!=0)
2038 msg("<warning> CXForm not SWF-compatible");
2040 cx.a0 = (S16)(c->aa*256);
2041 cx.r0 = (S16)(c->rr*256);
2042 cx.g0 = (S16)(c->gg*256);
2043 cx.b0 = (S16)(c->bb*256);
2051 ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
2053 ArtVpath *vec = NULL;
2061 if(l2->type == gfx_moveTo) {
2063 } if(l2->type == gfx_lineTo) {
2065 } if(l2->type == gfx_splineTo) {
2066 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
2067 if(!parts) parts = 1;
2077 vec = art_new (ArtVpath, len);
2082 if(l2->type == gfx_moveTo) {
2083 vec[pos].code = ART_MOVETO;
2088 } else if(l2->type == gfx_lineTo) {
2089 vec[pos].code = ART_LINETO;
2094 } else if(l2->type == gfx_splineTo) {
2096 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))/3);
2097 if(!parts) parts = 1;
2098 for(i=0;i<=parts;i++) {
2099 double t = (double)i/(double)parts;
2100 vec[pos].code = ART_LINETO;
2101 vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
2102 vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
2111 vec[pos].code = ART_END;
2113 svp = art_svp_vpath_stroke (vec,
2114 (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
2115 ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
2116 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
2117 (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
2118 ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
2119 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
2121 miterLimit, //miter_limit
2128 gfxline_t* SVPtogfxline(ArtSVP*svp)
2133 for(t=0;t<svp->n_segs;t++) {
2134 size += svp->segs[t].n_points + 1;
2136 gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
2138 for(t=0;t<svp->n_segs;t++) {
2139 ArtSVPSeg* seg = &svp->segs[t];
2141 for(p=0;p<seg->n_points;p++) {
2142 lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
2143 ArtPoint* point = &seg->points[p];
2144 lines[pos].x = point->x;
2145 lines[pos].y = point->y;
2146 lines[pos].next = &lines[pos+1];
2151 lines[pos-1].next = 0;
2159 static int imageInCache(swfoutput*obj, void*data, int width, int height)
2163 static void addImageToCache(swfoutput*obj, void*data, int width, int height)
2167 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
2169 swfoutput*obj = i->obj;
2171 RGBA*mem = (RGBA*)img->data;
2173 int sizex = img->width;
2174 int sizey = img->height;
2175 int is_jpeg = i->jpeg;
2178 int newsizex=sizex, newsizey=sizey;
2181 if(is_jpeg && config_jpegsubpixels) {
2182 newsizex = (int)(targetwidth*config_jpegsubpixels+0.5);
2183 newsizey = (int)(targetheight*config_jpegsubpixels+0.5);
2184 } else if(!is_jpeg && config_ppmsubpixels) {
2185 newsizex = (int)(targetwidth*config_ppmsubpixels+0.5);
2186 newsizey = (int)(targetheight*config_ppmsubpixels+0.5);
2190 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
2193 /* TODO: cache images */
2197 if(newsizex<sizex || newsizey<sizey) {
2198 msg("<notice> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
2199 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
2200 *newwidth = sizex = newsizex;
2201 *newheight = sizey = newsizey;
2206 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
2207 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
2209 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
2211 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
2214 targetwidth, targetheight,
2215 /*newsizex, newsizey,*/
2216 num_colors>256?">":"", num_colors>256?256:num_colors);
2218 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
2219 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
2221 for(t=0;t<num_colors;t++) {
2222 printf("%02x%02x%02x%02x ",
2223 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
2230 int cacheid = imageInCache(obj, mem, sizex, sizey);
2233 bitid = getNewID(obj);
2234 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, config_jpegquality);
2235 addImageToCache(obj, mem, sizex, sizey);
2245 static SRECT gfxline_getSWFbbox(gfxline_t*line)
2247 gfxbbox_t bbox = gfxline_getbbox(line);
2249 r.xmin = (int)(bbox.xmin*20);
2250 r.ymin = (int)(bbox.ymin*20);
2251 r.xmax = (int)(bbox.xmax*20);
2252 r.ymax = (int)(bbox.ymax*20);
2256 void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
2258 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2259 swfoutput*obj = i->obj;
2264 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
2265 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
2267 int newwidth=0,newheight=0;
2268 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
2271 double fx = (double)img->width / (double)newwidth;
2272 double fy = (double)img->height / (double)newheight;
2277 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
2278 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
2279 m.tx = (int)(matrix->tx*20);
2280 m.ty = (int)(matrix->ty*20);
2283 int myshapeid = getNewID(obj);
2284 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2286 swf_ShapeNew(&shape);
2287 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
2288 swf_SetU16(i->tag, myshapeid);
2289 SRECT r = gfxline_getSWFbbox(line);
2290 swf_SetRect(i->tag,&r);
2291 swf_SetShapeStyles(i->tag,shape);
2292 swf_ShapeCountBits(shape,NULL,NULL);
2293 swf_SetShapeBits(i->tag,shape);
2294 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2295 i->swflastx = i->swflasty = UNDEFINED_COORD;
2296 drawgfxline(obj, line);
2297 swf_ShapeSetEnd(i->tag);
2298 swf_ShapeFree(shape);
2300 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2301 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
2302 swf_ObjectPlace(i->tag,myshapeid,getNewDepth(obj),&i->page_matrix,&cxform2,NULL);
2305 void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
2307 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2308 swfoutput*obj = i->obj;
2313 if(i->clippos >= 127)
2315 msg("<warning> Too many clip levels.");
2319 int myshapeid = getNewID(obj);
2320 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2322 memset(&col, 0, sizeof(RGBA));
2324 swf_ShapeNew(&shape);
2325 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2326 swf_SetU16(i->tag,myshapeid);
2327 SRECT r = gfxline_getSWFbbox(line);
2328 swf_SetRect(i->tag,&r);
2329 swf_SetShapeStyles(i->tag,shape);
2330 swf_ShapeCountBits(shape,NULL,NULL);
2331 swf_SetShapeBits(i->tag,shape);
2332 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2333 i->swflastx = i->swflasty = UNDEFINED_COORD;
2334 drawgfxline(obj, line);
2335 swf_ShapeSetEnd(i->tag);
2336 swf_ShapeFree(shape);
2338 /* TODO: remember the bbox, and check all shapes against it */
2340 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2341 i->cliptags[i->clippos] = i->tag;
2342 i->clipshapes[i->clippos] = myshapeid;
2343 i->clipdepths[i->clippos] = getNewDepth(obj);
2347 void swf_endclip(gfxdevice_t*dev)
2349 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2350 swfoutput*obj = i->obj;
2357 msg("<error> Invalid end of clipping region");
2361 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2362 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2364 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2366 int swf_setparameter(gfxdevice_t*dev, const char*key, const char*value)
2368 if(!strcmp(key, "next_bitmap_is_jpeg")) {
2369 ((swfoutput_internal*)dev->internal)->jpeg = 1;
2375 int gfxline_type(gfxline_t*line)
2381 int haszerosegments=0;
2383 if(line->type == gfx_moveTo) {
2386 } else if(line->type == gfx_lineTo) {
2390 } else if(line->type == gfx_splineTo) {
2392 if(tmpsplines>lines)
2397 if(lines==0 && splines==0) return 0;
2398 else if(lines==1 && splines==0) return 1;
2399 else if(lines==0 && splines==1) return 2;
2400 else if(splines==0) return 3;
2404 int gfxline_has_dots(gfxline_t*line)
2411 if(line->type == gfx_moveTo) {
2412 if(isline && dist < 1) {
2417 } else if(line->type == gfx_lineTo) {
2418 dist += fabs(line->x - x) + fabs(line->y - y);
2420 } else if(line->type == gfx_splineTo) {
2421 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2422 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2429 if(isline && dist < 1) {
2435 int gfxline_fix_short_edges(gfxline_t*line)
2439 if(line->type == gfx_lineTo) {
2440 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2443 } else if(line->type == gfx_splineTo) {
2444 if(fabs(line->sx - x) + fabs(line->sy - y) +
2445 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2458 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)
2460 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2461 swfoutput*obj = i->obj;
2462 int type = gfxline_type(line);
2463 int has_dots = gfxline_has_dots(line);
2465 /* TODO: * split line into segments, and perform this check for all segments */
2467 (width <= config_caplinewidth
2468 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2469 || (cap_style == gfx_capRound && type<=2))) {
2470 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2472 swfoutput_setstrokecolor(obj, color->r, color->g, color->b, color->a);
2473 swfoutput_setlinewidth(obj, width);
2476 drawgfxline(obj, line);
2478 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2480 gfxline_fix_short_edges(line);
2481 /* we need to convert the line into a polygon */
2482 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2483 gfxline_t*gfxline = SVPtogfxline(svp);
2484 dev->fill(dev, gfxline, color);
2489 void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2491 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2492 swfoutput*obj = i->obj;
2494 if(!config_ignoredraworder)
2496 swfoutput_setfillcolor(obj, color->r, color->g, color->b, color->a);
2500 drawgfxline(obj, line);
2501 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2503 void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2505 msg("<error> Gradient filling not implemented yet");