3 Part of the swftools package.
5 Copyright (c) 2001,2002,2003,2004,2005 Matthias Kramm <kramm@quiss.org>
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"
34 #include "../rfxswf.h"
35 #include "../gfxdevice.h"
36 #include "../gfxtools.h"
37 #include "../art/libart.h"
38 #include "artsutils.c"
40 #define CHARDATAMAX 8192
44 typedef struct _chardata {
46 int fontid; /* TODO: use a SWFFONT instead */
53 typedef struct _fontlist
56 struct _fontlist*next;
59 typedef long int twip;
61 typedef struct _swfmatrix {
62 double m11,m12,m21,m22,m31,m32;
65 typedef struct _swfoutput_internal
67 gfxdevice_t*dev; // the gfxdevice object where this internal struct resides
69 double config_dumpfonts;
70 double config_ppmsubpixels;
71 double config_jpegsubpixels;
72 int config_opennewwindow;
73 int config_ignoredraworder;
74 int config_drawonlyshapes;
75 int config_jpegquality;
76 int config_storeallcharacters;
77 int config_generate_fake_tags;
78 int config_enablezlib;
79 int config_insertstoptag;
80 int config_flashversion;
81 int config_splinemaxerror;
82 int config_fontsplinemaxerror;
83 int config_filloverlap;
86 int config_disable_polygon_conversion;
87 RGBA config_linkcolor;
88 float config_minlinewidth;
89 double config_caplinewidth;
90 char* config_linktarget;
91 char*config_internallinkfunction;
92 char*config_externallinkfunction;
131 int pic_height[1024];
137 char fillstylechanged;
139 int jpeg; //next image type
144 chardata_t chardata[CHARDATAMAX];
152 double fontm11,fontm12,fontm21,fontm22;
163 } swfoutput_internal;
165 static void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
166 static int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
167 static 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);
168 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
169 static void swf_endclip(gfxdevice_t*dev);
170 static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit);
171 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
172 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
173 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
174 static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
175 static void swf_addfont(gfxdevice_t*dev, gfxfont_t*font);
176 static void swf_drawlink(gfxdevice_t*dev, gfxline_t*line, char*action);
177 static void swf_startframe(gfxdevice_t*dev, int width, int height);
178 static void swf_endframe(gfxdevice_t*dev);
179 static gfxresult_t* swf_finish(gfxdevice_t*driver);
181 static swfoutput_internal* init_internal_struct()
183 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
184 memset(i, 0, sizeof(swfoutput_internal));
208 i->fillstylechanged = 0;
215 i->config_dumpfonts=0;
216 i->config_ppmsubpixels=0;
217 i->config_jpegsubpixels=0;
218 i->config_opennewwindow=1;
219 i->config_ignoredraworder=0;
220 i->config_drawonlyshapes=0;
221 i->config_jpegquality=85;
222 i->config_storeallcharacters=0;
223 i->config_enablezlib=0;
224 i->config_generate_fake_tags=0;
225 i->config_insertstoptag=0;
226 i->config_flashversion=6;
227 i->config_splinemaxerror=1;
228 i->config_fontsplinemaxerror=1;
229 i->config_filloverlap=0;
231 i->config_bboxvars=0;
232 i->config_minlinewidth=0.05;
233 i->config_caplinewidth=1;
234 i->config_linktarget=0;
235 i->config_internallinkfunction=0;
236 i->config_externallinkfunction=0;
238 i->config_linkcolor.r = i->config_linkcolor.g = i->config_linkcolor.b = 255;
239 i->config_linkcolor.a = 0x40;
244 static int id_error = 0;
246 static U16 getNewID(gfxdevice_t* dev)
248 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
249 if(i->currentswfid == 65535) {
251 msg("<error> ID Table overflow");
256 return ++i->currentswfid;
258 static U16 getNewDepth(gfxdevice_t* dev)
260 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
261 if(i->depth == 65535) {
263 msg("<error> Depth Table overflow");
271 static void startshape(gfxdevice_t* dev);
272 static void starttext(gfxdevice_t* dev);
273 static void endshape(gfxdevice_t* dev);
274 static void endtext(gfxdevice_t* dev);
276 typedef struct _plotxy
281 // write a move-to command into the swf
282 static int movetoxy(gfxdevice_t*dev, TAG*tag, plotxy_t p0)
284 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
285 int rx = (int)(p0.x*20);
286 int ry = (int)(p0.y*20);
287 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
288 swf_ShapeSetMove (tag, i->shape, rx,ry);
289 i->fillstylechanged = 0;
296 static int moveto(gfxdevice_t*dev, TAG*tag, double x, double y)
298 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
302 return movetoxy(dev, tag, p);
304 static void addPointToBBox(gfxdevice_t*dev, int px, int py)
306 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
312 swf_ExpandRect(&i->bboxrect, p);
314 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
318 /*static void plot(gfxdevice_t*dev, int x, int y, TAG*tag)
320 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
321 int width = i->linewidth/4;
325 //swf_ShapeSetLine(tag, i->shape,-width,-width);
326 //swf_ShapeSetLine(tag, i->shape,width*2,0);
327 //swf_ShapeSetLine(tag, i->shape,0,width*2);
328 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
329 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
330 //swf_ShapeSetLine(tag, i->shape,width,width);
333 swf_ShapeSetLine(tag, i->shape,-width,0);
334 swf_ShapeSetLine(tag, i->shape,width,-width);
335 swf_ShapeSetLine(tag, i->shape,width,width);
336 swf_ShapeSetLine(tag, i->shape,-width,width);
337 swf_ShapeSetLine(tag, i->shape,-width,-width);
338 swf_ShapeSetLine(tag, i->shape,width,0);
340 addPointToBBox(dev, x-width ,y-width);
341 addPointToBBox(dev, x+width ,y+width);
344 // write a line-to command into the swf
345 static void linetoxy(gfxdevice_t*dev, TAG*tag, plotxy_t p0)
347 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
348 int px = (int)(p0.x*20);
349 int py = (int)(p0.y*20);
350 int rx = (px-i->swflastx);
351 int ry = (py-i->swflasty);
353 swf_ShapeSetLine (tag, i->shape, rx,ry);
354 addPointToBBox(dev, i->swflastx,i->swflasty);
355 addPointToBBox(dev, px,py);
356 }/* else if(!i->fill) {
357 // treat lines of length 0 as plots, making them
358 // at least 1 twip wide so Flash will display them
359 plot(dev, i->swflastx, i->swflasty, tag);
366 static void lineto(gfxdevice_t*dev, TAG*tag, double x, double y)
371 linetoxy(dev,tag, p);
374 // write a spline-to command into the swf
375 static void splineto(gfxdevice_t*dev, TAG*tag, plotxy_t control,plotxy_t end)
377 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
378 int lastlastx = i->swflastx;
379 int lastlasty = i->swflasty;
381 int cx = ((int)(control.x*20)-i->swflastx);
382 int cy = ((int)(control.y*20)-i->swflasty);
385 int ex = ((int)(end.x*20)-i->swflastx);
386 int ey = ((int)(end.y*20)-i->swflasty);
390 if((cx || cy) && (ex || ey)) {
391 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
392 addPointToBBox(dev, lastlastx ,lastlasty );
393 addPointToBBox(dev, lastlastx+cx,lastlasty+cy);
394 addPointToBBox(dev, lastlastx+cx+ex,lastlasty+cy+ey);
395 } else if(cx || cy || ex || ey) {
396 swf_ShapeSetLine(tag, i->shape, cx+ex,cy+ey);
397 addPointToBBox(dev, lastlastx ,lastlasty );
398 addPointToBBox(dev, lastlastx+cx,lastlasty+cy);
399 addPointToBBox(dev, lastlastx+cx+ex,lastlasty+cy+ey);
405 /* write a line, given two points and the transformation
407 /*static void line(gfxdevice_t*dev, TAG*tag, plotxy_t p0, plotxy_t p1)
409 moveto(dev, tag, p0);
410 lineto(dev, tag, p1);
413 void resetdrawer(gfxdevice_t*dev)
415 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
420 static void stopFill(gfxdevice_t*dev)
422 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
423 if(i->lastwasfill!=0)
425 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
426 i->fillstylechanged = 1;
430 static void startFill(gfxdevice_t*dev)
432 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
433 if(i->lastwasfill!=1)
435 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
436 i->fillstylechanged = 1;
441 static inline int colorcompare(gfxdevice_t*dev, RGBA*a,RGBA*b)
453 static SRECT getcharacterbbox(gfxdevice_t*dev, SWFFONT*font, MATRIX* m)
455 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
458 memset(&r, 0, sizeof(r));
461 if(debug) printf("\n");
462 for(t=0;t<i->chardatapos;t++)
464 if(i->chardata[t].fontid != font->id) {
465 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
468 SRECT b = font->layout->bounds[i->chardata[t].charid];
469 b.xmin *= i->chardata[t].size;
470 b.ymin *= i->chardata[t].size;
471 b.xmax *= i->chardata[t].size;
472 b.ymax *= i->chardata[t].size;
474 /* divide by 1024, rounding xmax/ymax up */
475 b.xmax += 1023; b.ymax += 1023; b.xmin /= 1024; b.ymin /= 1024; b.xmax /= 1024; b.ymax /= 1024;
477 b.xmin += i->chardata[t].x;
478 b.ymin += i->chardata[t].y;
479 b.xmax += i->chardata[t].x;
480 b.ymax += i->chardata[t].y;
482 /* until we solve the INTERNAL_SCALING problem (see below)
483 make sure the bounding box is big enough */
489 b = swf_TurnRect(b, m);
491 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
492 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
493 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
494 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
495 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
500 i->chardata[t].fontid,
502 i->chardata[t].charid
504 swf_ExpandRect2(&r, &b);
506 if(debug) printf("-----> (%f,%f,%f,%f)\n",
514 static void putcharacters(gfxdevice_t*dev, TAG*tag)
516 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
520 color.r = i->chardata[0].color.r^255;
529 int charadvance[128];
532 int glyphbits=1; //TODO: can this be zero?
535 if(tag->id != ST_DEFINETEXT &&
536 tag->id != ST_DEFINETEXT2) {
537 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
540 if(!i->chardatapos) {
541 msg("<warning> putcharacters called with zero characters");
544 for(pass = 0; pass < 2; pass++)
554 advancebits++; // add sign bit
555 swf_SetU8(tag, glyphbits);
556 swf_SetU8(tag, advancebits);
559 for(t=0;t<=i->chardatapos;t++)
561 if(lastfontid != i->chardata[t].fontid ||
562 lastx!=i->chardata[t].x ||
563 lasty!=i->chardata[t].y ||
564 !colorcompare(dev,&color, &i->chardata[t].color) ||
566 lastsize != i->chardata[t].size ||
569 if(charstorepos && pass==0)
572 for(s=0;s<charstorepos;s++)
574 while(charids[s]>=(1<<glyphbits))
576 while(charadvance[s]>=(1<<advancebits))
580 if(charstorepos && pass==1)
582 tag->writeBit = 0; // Q&D
583 swf_SetBits(tag, 0, 1); // GLYPH Record
584 swf_SetBits(tag, charstorepos, 7); // number of glyphs
586 for(s=0;s<charstorepos;s++)
588 swf_SetBits(tag, charids[s], glyphbits);
589 swf_SetBits(tag, charadvance[s], advancebits);
594 if(pass == 1 && t<i->chardatapos)
600 if(lastx != i->chardata[t].x ||
601 lasty != i->chardata[t].y)
603 newx = i->chardata[t].x;
604 newy = i->chardata[t].y;
610 if(!colorcompare(dev,&color, &i->chardata[t].color))
612 color = i->chardata[t].color;
615 font.id = i->chardata[t].fontid;
616 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
619 tag->writeBit = 0; // Q&D
620 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
623 lastfontid = i->chardata[t].fontid;
624 lastx = i->chardata[t].x;
625 lasty = i->chardata[t].y;
626 lastsize = i->chardata[t].size;
629 if(t==i->chardatapos)
633 int nextt = t==i->chardatapos-1?t:t+1;
634 int rel = i->chardata[nextt].x-i->chardata[t].x;
635 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
637 lastx=i->chardata[nextt].x;
641 lastx=i->chardata[t].x;
643 charids[charstorepos] = i->chardata[t].charid;
644 charadvance[charstorepos] = advance;
651 static void putcharacter(gfxdevice_t*dev, int fontid, int charid, int x,int y, int size, RGBA color)
653 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
654 if(i->chardatapos == CHARDATAMAX)
656 msg("<warning> Character buffer too small. SWF will be slightly bigger");
660 i->chardata[i->chardatapos].fontid = fontid;
661 i->chardata[i->chardatapos].charid = charid;
662 i->chardata[i->chardatapos].x = x;
663 i->chardata[i->chardatapos].y = y;
664 i->chardata[i->chardatapos].color = color;
665 i->chardata[i->chardatapos].size = size;
669 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
670 So if we set this value to high, the char coordinates will overflow.
671 If we set it to low, however, the char positions will be inaccurate */
672 #define FONT_INTERNAL_SIZE 4
674 /* process a character. */
675 static int drawchar(gfxdevice_t*dev, SWFFONT *swffont, int charid, swfmatrix_t*m, gfxcolor_t*col)
677 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
679 msg("<warning> Font is NULL");
683 if(charid<0 || charid>=swffont->numchars) {
684 msg("<warning> No character %d in font %s ", charid, FIXNULL((char*)swffont->name));
687 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
688 msg("<warning> Glyph %d in current charset (%s, %d characters) is empty",
689 charid, FIXNULL((char*)swffont->name), swffont->numchars);
700 float det = ((m->m11*m->m22)-(m->m21*m->m12));
701 if(fabs(det) < 0.0005) {
702 /* x direction equals y direction- the text is invisible */
705 det = 20*FONT_INTERNAL_SIZE / det;
708 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
709 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
711 RGBA rgba = *(RGBA*)col;
712 putcharacter(dev, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
713 swf_FontUseGlyph(swffont, charid);
717 static void endtext(gfxdevice_t*dev)
719 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
723 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
724 swf_SetU16(i->tag, i->textid);
727 r = getcharacterbbox(dev, i->swffont, &i->fontmatrix);
729 swf_SetRect(i->tag,&r);
731 swf_SetMatrix(i->tag,&i->fontmatrix);
733 msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
735 putcharacters(dev, i->tag);
737 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
739 swf_ObjectPlace(i->tag,i->textid,getNewDepth(dev),&i->page_matrix,NULL,NULL);
743 /* set's the matrix which is to be applied to characters drawn by swfoutput_drawchar() */
744 static void swfoutput_setfontmatrix(gfxdevice_t*dev,double m11,double m21,
745 double m12,double m22)
751 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
752 if(i->fontm11 == m11 &&
765 m.sx = (U32)(((i->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((i->fontm12)*65536)/FONT_INTERNAL_SIZE);
766 m.r0 = (U32)(((i->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((i->fontm22)*65536)/FONT_INTERNAL_SIZE);
772 static void endpage(gfxdevice_t*dev)
774 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
784 void swf_startframe(gfxdevice_t*dev, int width, int height)
786 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
787 if(!i->firstpage && !i->pagefinished)
789 msg("<verbose> Starting new SWF page of size %dx%d", width, height);
791 swf_GetMatrix(0, &i->page_matrix);
792 i->page_matrix.tx = 0;
793 i->page_matrix.ty = 0;
799 /* set clipping/background rectangle */
800 /* TODO: this should all be done in SWFOutputDev */
801 //setBackground(dev, x1, y1, x2, y2);
803 /* increase SWF's bounding box */
809 swf_ExpandRect2(&i->swf->movieSize, &r);
811 i->lastframeno = i->frameno;
816 void swf_endframe(gfxdevice_t*dev)
818 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
823 if(i->config_insertstoptag) {
825 atag = action_Stop(atag);
826 atag = action_End(atag);
827 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
828 swf_ActionSet(i->tag,atag);
830 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
833 for(i->depth;i->depth>i->startdepth;i->depth--) {
834 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
835 swf_SetU16(i->tag,i->depth);
837 i->depth = i->startdepth;
840 static void setBackground(gfxdevice_t*dev, int x1, int y1, int x2, int y2)
842 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
844 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
848 int shapeid = getNewID(dev);
853 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
855 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
856 swf_SetU16(i->tag,shapeid);
857 swf_SetRect(i->tag,&r);
858 swf_SetShapeHeader(i->tag,s);
859 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
860 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
861 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
862 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
863 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
864 swf_ShapeSetEnd(i->tag);
866 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
867 swf_ObjectPlace(i->tag,shapeid,getNewDepth(dev),0,0,0);
868 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
869 swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(dev),0,0,0,65535);
872 /* initialize the swf writer */
873 void gfxdevice_swf_init(gfxdevice_t* dev)
875 memset(dev, 0, sizeof(gfxdevice_t));
876 dev->internal = init_internal_struct();
878 dev->startpage = swf_startframe;
879 dev->endpage = swf_endframe;
880 dev->finish = swf_finish;
881 dev->fillbitmap = swf_fillbitmap;
882 dev->setparameter = swf_setparameter;
883 dev->stroke = swf_stroke;
884 dev->startclip = swf_startclip;
885 dev->endclip = swf_endclip;
886 dev->fill = swf_fill;
887 dev->fillbitmap = swf_fillbitmap;
888 dev->fillgradient = swf_fillgradient;
889 dev->addfont = swf_addfont;
890 dev->drawchar = swf_drawchar;
891 dev->drawlink = swf_drawlink;
893 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
899 msg("<verbose> initializing swf output\n", i->max_x,i->max_y);
903 i->swf = (SWF*)rfx_calloc(sizeof(SWF));
904 i->swf->fileVersion = i->config_flashversion;
905 i->swf->frameRate = 0x0040; // 1 frame per 4 seconds
906 i->swf->movieSize.xmin = 0;
907 i->swf->movieSize.ymin = 0;
908 i->swf->movieSize.xmax = 0;
909 i->swf->movieSize.ymax = 0;
911 i->swf->firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
912 i->tag = i->swf->firstTag;
913 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
914 swf_SetRGB(i->tag,&rgb);
916 i->startdepth = i->depth = 0;
918 if(i->config_protect)
919 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
922 static void startshape(gfxdevice_t*dev)
924 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
933 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
935 swf_ShapeNew(&i->shape);
936 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&i->strokergb);
937 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&i->fillrgb);
939 RGBA markcol = {0,i->mark[0],i->mark[1],i->mark[2]};
940 swf_ShapeAddSolidFillStyle(i->shape,&markcol);
943 i->shapeid = getNewID(dev);
945 msg("<debug> Using shape id %d", i->shapeid);
947 swf_SetU16(i->tag,i->shapeid); // ID
949 i->bboxrectpos = i->tag->len;
953 r.xmax = 20*i->max_x;
954 r.ymax = 20*i->max_y;
955 swf_SetRect(i->tag,&r);
957 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
959 swf_SetShapeStyles(i->tag,i->shape);
960 swf_ShapeCountBits(i->shape,NULL,NULL);
961 swf_SetShapeBits(i->tag,i->shape);
963 /* TODO: do we really need this? */
964 //swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
965 //swf_ShapeSetAll(i->tag,i->shape,/*x*/UNDEFINED_COORD,/*y*/UNDEFINED_COORD,i->linestyleid,0,0);
966 i->swflastx=i->swflasty=UNDEFINED_COORD;
971 static void starttext(gfxdevice_t*dev)
973 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
977 i->textid = getNewID(dev);
979 i->swflastx=i->swflasty=0;
983 /* TODO: move to ../lib/rfxswf */
984 void changeRect(gfxdevice_t*dev, TAG*tag, int pos, SRECT*newrect)
986 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
987 /* determine length of old rect */
991 swf_GetRect(tag, &old);
992 swf_ResetReadBits(tag);
993 int pos_end = tag->pos;
995 int len = tag->len - pos_end;
996 U8*data = (U8*)malloc(len);
997 memcpy(data, &tag->data[pos_end], len);
1000 swf_SetRect(tag, newrect);
1001 swf_SetBlock(tag, data, len);
1003 tag->pos = tag->readBit = 0;
1006 void cancelshape(gfxdevice_t*dev)
1008 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1009 /* delete old shape tag */
1011 i->tag = i->tag->prev;
1012 swf_DeleteTag(todel);
1013 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
1015 i->bboxrectpos = -1;
1017 // i->currentswfid--; // this was an *exceptionally* bad idea
1020 void fixAreas(gfxdevice_t*dev)
1022 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1023 if(!i->shapeisempty && i->fill &&
1024 (i->bboxrect.xmin == i->bboxrect.xmax ||
1025 i->bboxrect.ymin == i->bboxrect.ymax) &&
1026 i->config_minlinewidth >= 0.001
1028 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1029 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1030 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1033 SRECT r = i->bboxrect;
1035 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1036 /* this thing comes down to a single dot- nothing to fix here */
1042 RGBA save_col = i->strokergb;
1043 int save_width = i->linewidth;
1045 i->strokergb = i->fillrgb;
1046 i->linewidth = (int)(i->config_minlinewidth*20);
1047 if(i->linewidth==0) i->linewidth = 1;
1052 moveto(dev, i->tag, r.xmin/20.0,r.ymin/20.0);
1053 lineto(dev, i->tag, r.xmax/20.0,r.ymax/20.0);
1055 i->strokergb = save_col;
1056 i->linewidth = save_width;
1061 static void endshape_noput(gfxdevice_t*dev)
1063 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1066 //changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1069 swf_ShapeFree(i->shape);
1077 static void endshape(gfxdevice_t*dev)
1079 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1085 if(i->shapeisempty ||
1087 (i->bboxrect.xmin == i->bboxrect.xmax &&
1088 i->bboxrect.ymin == i->bboxrect.ymax))
1090 // delete the shape again, we didn't do anything
1091 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1092 i->bboxrect.xmin /20.0,
1093 i->bboxrect.ymin /20.0,
1094 i->bboxrect.xmax /20.0,
1095 i->bboxrect.ymax /20.0
1101 swf_ShapeSetEnd(i->tag);
1103 changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1105 msg("<trace> Placing shape id %d", i->shapeid);
1107 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1108 MATRIX m = i->page_matrix;
1109 m.tx += i->shapeposx;
1110 m.ty += i->shapeposy;
1111 swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(dev),&m,NULL,NULL);
1113 swf_ShapeFree(i->shape);
1116 i->bboxrectpos = -1;
1123 void wipeSWF(SWF*swf)
1125 TAG*tag = swf->firstTag;
1127 TAG*next = tag->next;
1128 if(tag->id != ST_SETBACKGROUNDCOLOR &&
1129 tag->id != ST_END &&
1130 tag->id != ST_DOACTION &&
1131 tag->id != ST_SHOWFRAME) {
1139 void swfoutput_finalize(gfxdevice_t*dev)
1141 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1143 if(i->tag && i->tag->id == ST_END)
1144 return; //already done
1146 if(i->config_bboxvars) {
1147 TAG* tag = swf_InsertTag(i->swf->firstTag, ST_DOACTION);
1149 a = action_PushString(a, "xmin");
1150 a = action_PushFloat(a, i->swf->movieSize.xmin / 20.0);
1151 a = action_SetVariable(a);
1152 a = action_PushString(a, "ymin");
1153 a = action_PushFloat(a, i->swf->movieSize.ymin / 20.0);
1154 a = action_SetVariable(a);
1155 a = action_PushString(a, "xmax");
1156 a = action_PushFloat(a, i->swf->movieSize.xmax / 20.0);
1157 a = action_SetVariable(a);
1158 a = action_PushString(a, "ymax");
1159 a = action_PushFloat(a, i->swf->movieSize.ymax / 20.0);
1160 a = action_SetVariable(a);
1161 a = action_PushString(a, "width");
1162 a = action_PushFloat(a, (i->swf->movieSize.xmax - i->swf->movieSize.xmin) / 20.0);
1163 a = action_SetVariable(a);
1164 a = action_PushString(a, "height");
1165 a = action_PushFloat(a, (i->swf->movieSize.ymax - i->swf->movieSize.ymin) / 20.0);
1166 a = action_SetVariable(a);
1168 swf_ActionSet(tag, a);
1172 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1176 free(i->mark);i->mark = 0;
1180 fontlist_t *tmp,*iterator = i->fontlist;
1182 TAG*mtag = i->swf->firstTag;
1183 if(iterator->swffont) {
1184 if(!i->config_storeallcharacters) {
1185 msg("<debug> Reducing font %s", iterator->swffont->name);
1186 swf_FontReduce(iterator->swffont);
1188 int used = iterator->swffont->use && iterator->swffont->use->used_glyphs;
1189 if(i->config_storeallcharacters || used) {
1190 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1191 swf_FontSetDefine2(mtag, iterator->swffont);
1195 iterator = iterator->next;
1197 i->tag = swf_InsertTag(i->tag,ST_END);
1198 TAG* tag = i->tag->prev;
1200 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1201 and the ST_END- they confuse the flash player */
1202 while(tag->id == ST_REMOVEOBJECT2) {
1203 TAG* prev = tag->prev;
1211 if(i->config_enablezlib || i->config_flashversion>=6) {
1212 i->swf->compressed = 1;
1216 int swfresult_save(gfxresult_t*gfx, char*filename)
1218 SWF*swf = (SWF*)gfx->internal;
1221 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1226 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1230 if(swf->compressed) {
1231 if FAILED(swf_WriteSWC(fi,swf))
1232 msg("<error> WriteSWC() failed.\n");
1234 if FAILED(swf_WriteSWF(fi,swf))
1235 msg("<error> WriteSWF() failed.\n");
1242 void* swfresult_get(gfxresult_t*gfx, char*name)
1244 SWF*swf = (SWF*)gfx->internal;
1245 if(!strcmp(name, "swf")) {
1246 return (void*)swf_CopySWF(swf);
1247 } else if(!strcmp(name, "xmin")) {
1248 return (void*)(swf->movieSize.xmin/20);
1249 } else if(!strcmp(name, "ymin")) {
1250 return (void*)(swf->movieSize.ymin/20);
1251 } else if(!strcmp(name, "xmax")) {
1252 return (void*)(swf->movieSize.xmax/20);
1253 } else if(!strcmp(name, "ymax")) {
1254 return (void*)(swf->movieSize.ymax/20);
1255 } else if(!strcmp(name, "width")) {
1256 return (void*)((swf->movieSize.xmax - swf->movieSize.xmin)/20);
1257 } else if(!strcmp(name, "height")) {
1258 return (void*)((swf->movieSize.ymax - swf->movieSize.ymin)/20);
1262 void swfresult_destroy(gfxresult_t*gfx)
1265 swf_FreeTags((SWF*)gfx->internal);
1266 free(gfx->internal);
1269 memset(gfx, 0, sizeof(gfxresult_t));
1273 static void swfoutput_destroy(gfxdevice_t* dev);
1275 gfxresult_t* swf_finish(gfxdevice_t* dev)
1277 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1280 if(i->config_linktarget) {
1281 free(i->config_linktarget);
1282 i->config_linktarget = 0;
1285 swfoutput_finalize(dev);
1286 SWF* swf = i->swf;i->swf = 0;
1287 swfoutput_destroy(dev);
1289 result = (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t));
1290 result->internal = swf;
1291 result->save = swfresult_save;
1293 result->get = swfresult_get;
1294 result->destroy = swfresult_destroy;
1298 /* Perform cleaning up */
1299 static void swfoutput_destroy(gfxdevice_t* dev)
1301 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1303 /* not initialized yet- nothing to destroy */
1307 fontlist_t *tmp,*iterator = i->fontlist;
1309 if(iterator->swffont) {
1310 swf_FontFree(iterator->swffont);iterator->swffont=0;
1313 iterator = iterator->next;
1316 if(i->swf) {swf_FreeTags(i->swf);free(i->swf);i->swf = 0;}
1319 memset(dev, 0, sizeof(gfxdevice_t));
1322 static void swfoutput_setfillcolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1324 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1325 if(i->fillrgb.r == r &&
1326 i->fillrgb.g == g &&
1327 i->fillrgb.b == b &&
1328 i->fillrgb.a == a) return;
1338 static void swfoutput_setstrokecolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1340 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1341 if(i->strokergb.r == r &&
1342 i->strokergb.g == g &&
1343 i->strokergb.b == b &&
1344 i->strokergb.a == a) return;
1354 //#define ROUND_UP 19
1355 //#define ROUND_UP 10
1357 static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth)
1359 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1360 if(i->linewidth == (U16)(_linewidth*20+19.0/20.0))
1364 i->linewidth = (U16)(_linewidth*20+19.0/20.0);
1368 static void drawlink(gfxdevice_t*dev, ActionTAG*,ActionTAG*, gfxline_t*points, char mouseover);
1369 static void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points);
1370 static void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points);
1371 static void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points);
1373 void swfoutput_drawlink(gfxdevice_t*dev, char*url, gfxline_t*points)
1375 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1376 dev->drawlink(dev, points, url);
1379 void swf_drawlink(gfxdevice_t*dev, gfxline_t*points, char*url)
1381 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1383 if(!strncmp("http://pdf2swf:", url, 15)) {
1384 char*tmp = strdup(url);
1385 int l = strlen(tmp);
1388 swfoutput_namedlink(dev, tmp+15, points);
1391 } else if(!strncmp("page", url, 4)) {
1394 if(url[t]<'0' || url[t]>'9')
1397 int page = atoi(&url[4]);
1398 if(page<0) page = 0;
1399 swfoutput_linktopage(dev, page, points);
1402 swfoutput_linktourl(dev, url, points);
1405 void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points)
1407 ActionTAG* actions = 0;
1408 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1414 if(i->config_externallinkfunction) {
1415 actions = action_PushString(actions, url); //parameter
1416 actions = action_PushInt(actions, 1); //number of parameters (1)
1417 actions = action_PushString(actions, i->config_externallinkfunction); //function name
1418 actions = action_CallFunction(actions);
1419 } else if(!i->config_linktarget) {
1420 if(!i->config_opennewwindow)
1421 actions = action_GetUrl(actions, url, "_parent");
1423 actions = action_GetUrl(actions, url, "_this");
1425 actions = action_GetUrl(actions, url, i->config_linktarget);
1427 actions = action_End(actions);
1429 drawlink(dev, actions, 0, points,0);
1431 void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points)
1433 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1434 ActionTAG* actions = 0;
1441 if(!i->config_internallinkfunction) {
1442 actions = action_GotoFrame(actions, page-1);
1443 actions = action_End(actions);
1445 actions = action_PushInt(actions, page); //parameter
1446 actions = action_PushInt(actions, 1); //number of parameters (1)
1447 actions = action_PushString(actions, i->config_internallinkfunction); //function name
1448 actions = action_CallFunction(actions);
1449 actions = action_End(actions);
1452 drawlink(dev, actions, 0, points,0);
1455 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1456 of the viewer objects, like subtitles, index elements etc.
1458 void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points)
1460 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1461 ActionTAG *actions1,*actions2;
1462 char*tmp = strdup(name);
1470 if(!strncmp(tmp, "call:", 5))
1472 char*x = strchr(&tmp[5], ':');
1474 actions1 = action_PushInt(0, 0); //number of parameters (0)
1475 actions1 = action_PushString(actions1, &tmp[5]); //function name
1476 actions1 = action_CallFunction(actions1);
1477 actions1 = action_End(actions1);
1480 actions1 = action_PushString(0, x+1); //parameter
1481 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1482 actions1 = action_PushString(actions1, &tmp[5]); //function name
1483 actions1 = action_CallFunction(actions1);
1484 actions1 = action_End(actions1);
1486 actions2 = action_End(0);
1491 actions1 = action_PushString(0, "/:subtitle");
1492 actions1 = action_PushString(actions1, name);
1493 actions1 = action_SetVariable(actions1);
1494 actions1 = action_End(actions1);
1496 actions2 = action_PushString(0, "/:subtitle");
1497 actions2 = action_PushString(actions2, "");
1498 actions2 = action_SetVariable(actions2);
1499 actions2 = action_End(actions2);
1502 drawlink(dev, actions1, actions2, points,mouseover);
1504 swf_ActionFree(actions1);
1505 swf_ActionFree(actions2);
1509 static void drawgfxline(gfxdevice_t*dev, gfxline_t*line)
1511 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1512 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1514 int lines= 0, splines=0;
1518 /* check whether the next segment is zero */
1519 if(line->type == gfx_moveTo) {
1520 moveto(dev, i->tag, line->x, line->y);
1521 px = lastx = line->x;
1522 py = lasty = line->y;
1524 } if(line->type == gfx_lineTo) {
1525 lineto(dev, i->tag, line->x, line->y);
1530 } else if(line->type == gfx_splineTo) {
1532 s.x = line->sx;p.x = line->x;
1533 s.y = line->sy;p.y = line->y;
1534 splineto(dev, i->tag, s, p);
1542 msg("<trace> drawgfxline, %d lines, %d splines", lines, splines);
1546 static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gfxline_t*points, char mouseover)
1548 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1553 plotxy_t p1,p2,p3,p4;
1559 int buttonid = getNewID(dev);
1560 gfxbbox_t bbox = gfxline_getbbox(points);
1563 myshapeid = getNewID(dev);
1564 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1565 swf_ShapeNew(&i->shape);
1566 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1567 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1568 swf_SetU16(i->tag, myshapeid);
1569 r.xmin = (int)(bbox.xmin*20);
1570 r.ymin = (int)(bbox.ymin*20);
1571 r.xmax = (int)(bbox.xmax*20);
1572 r.ymax = (int)(bbox.ymax*20);
1573 swf_SetRect(i->tag,&r);
1574 swf_SetShapeStyles(i->tag,i->shape);
1575 swf_ShapeCountBits(i->shape,NULL,NULL);
1576 swf_SetShapeBits(i->tag,i->shape);
1577 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1578 i->swflastx = i->swflasty = 0;
1579 drawgfxline(dev, points);
1580 swf_ShapeSetEnd(i->tag);
1583 myshapeid2 = getNewID(dev);
1584 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1585 swf_ShapeNew(&i->shape);
1587 rgb = i->config_linkcolor;
1589 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1590 swf_SetU16(i->tag, myshapeid2);
1591 r.xmin = (int)(bbox.xmin*20);
1592 r.ymin = (int)(bbox.ymin*20);
1593 r.xmax = (int)(bbox.xmax*20);
1594 r.ymax = (int)(bbox.ymax*20);
1595 swf_SetRect(i->tag,&r);
1596 swf_SetShapeStyles(i->tag,i->shape);
1597 swf_ShapeCountBits(i->shape,NULL,NULL);
1598 swf_SetShapeBits(i->tag,i->shape);
1599 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1600 i->swflastx = i->swflasty = 0;
1601 drawgfxline(dev, points);
1602 swf_ShapeSetEnd(i->tag);
1606 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1607 swf_SetU16(i->tag,buttonid); //id
1608 swf_ButtonSetFlags(i->tag, 0); //menu=no
1609 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1610 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1611 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1612 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1613 swf_SetU8(i->tag,0);
1614 swf_ActionSet(i->tag,actions1);
1615 swf_SetU8(i->tag,0);
1619 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1620 swf_SetU16(i->tag,buttonid); //id
1621 swf_ButtonSetFlags(i->tag, 0); //menu=no
1622 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1623 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1624 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1625 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1626 swf_SetU8(i->tag,0); // end of button records
1627 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1628 swf_ActionSet(i->tag,actions1);
1630 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1631 swf_ActionSet(i->tag,actions2);
1632 swf_SetU8(i->tag,0);
1633 swf_ButtonPostProcess(i->tag, 2);
1635 swf_SetU8(i->tag,0);
1636 swf_ButtonPostProcess(i->tag, 1);
1640 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1642 if(posx!=0 || posy!=0) {
1644 p.x = (int)(posx*20);
1645 p.y = (int)(posy*20);
1646 p = swf_TurnPoint(p, &i->page_matrix);
1651 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&m,0,0);
1653 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&i->page_matrix,0,0);
1660 for(t=0;t<picpos;t++)
1662 if(pic_xids[t] == xid &&
1663 pic_yids[t] == yid) {
1664 width = pic_width[t];
1665 height = pic_height[t];
1669 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1670 pic_xids[picpos] = xid;
1671 pic_yids[picpos] = yid;
1672 pic_width[picpos] = width;
1673 pic_height[picpos] = height;
1676 pic[width*y+x] = buf[0];
1680 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1681 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1685 xid += x*r+x*b*3+x*g*7+x*a*11;
1686 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1688 for(t=0;t<picpos;t++)
1690 if(pic_xids[t] == xid &&
1691 pic_yids[t] == yid) {
1700 int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
1702 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1704 msg("<trace> swfdevice: %s=%s", name, value);
1705 if(!strcmp(name, "jpegsubpixels")) {
1706 i->config_jpegsubpixels = atof(value);
1707 } else if(!strcmp(name, "ppmsubpixels")) {
1708 i->config_ppmsubpixels = atof(value);
1709 } else if(!strcmp(name, "subpixels")) {
1710 i->config_ppmsubpixels = i->config_jpegsubpixels = atof(value);
1711 } else if(!strcmp(name, "drawonlyshapes")) {
1712 i->config_drawonlyshapes = atoi(value);
1713 } else if(!strcmp(name, "ignoredraworder")) {
1714 i->config_ignoredraworder = atoi(value);
1715 } else if(!strcmp(name, "mark")) {
1716 if(!value || !value[0]) {
1717 if(i->mark) free(i->mark);
1721 i->mark = strdup("...");
1722 for(t=0;t<3;t++) if(value[t]) i->mark[t] = value[t];
1724 } else if(!strcmp(name, "filloverlap")) {
1725 i->config_filloverlap = atoi(value);
1726 } else if(!strcmp(name, "linksopennewwindow")) {
1727 i->config_opennewwindow = atoi(value);
1728 } else if(!strcmp(name, "opennewwindow")) {
1729 i->config_opennewwindow = atoi(value);
1730 } else if(!strcmp(name, "storeallcharacters")) {
1731 i->config_storeallcharacters = atoi(value);
1732 } else if(!strcmp(name, "enablezlib")) {
1733 i->config_enablezlib = atoi(value);
1734 } else if(!strcmp(name, "bboxvars")) {
1735 i->config_bboxvars = atoi(value);
1736 } else if(!strcmp(name, "internallinkfunction")) {
1737 i->config_internallinkfunction = strdup(value);
1738 } else if(!strcmp(name, "externallinkfunction")) {
1739 i->config_externallinkfunction = strdup(value);
1740 } else if(!strcmp(name, "disable_polygon_conversion")) {
1741 i->config_disable_polygon_conversion = atoi(value);
1742 } else if(!strcmp(name, "insertstop")) {
1743 i->config_insertstoptag = atoi(value);
1744 } else if(!strcmp(name, "protect")) {
1745 i->config_protect = atoi(value);
1746 if(i->config_protect && i->tag) {
1747 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1749 } else if(!strcmp(name, "faketags")) {
1750 i->config_generate_fake_tags = atoi(value);
1751 } else if(!strcmp(name, "flashversion")) {
1752 i->config_flashversion = atoi(value);
1754 i->swf->fileVersion = i->config_flashversion;
1756 } else if(!strcmp(name, "minlinewidth")) {
1757 i->config_minlinewidth = atof(value);
1758 } else if(!strcmp(name, "caplinewidth")) {
1759 i->config_caplinewidth = atof(value);
1760 } else if(!strcmp(name, "linktarget")) {
1761 i->config_linktarget = strdup(value);
1762 } else if(!strcmp(name, "dumpfonts")) {
1763 i->config_dumpfonts = atoi(value);
1764 } else if(!strcmp(name, "next_bitmap_is_jpeg")) {
1766 } else if(!strcmp(name, "jpegquality")) {
1767 int val = atoi(value);
1769 if(val>100) val=100;
1770 i->config_jpegquality = val;
1771 } else if(!strcmp(name, "splinequality")) {
1772 int v = atoi(value);
1773 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1775 i->config_splinemaxerror = v;
1776 } else if(!strcmp(name, "fontquality")) {
1777 int v = atoi(value);
1778 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1780 i->config_fontsplinemaxerror = v;
1781 } else if(!strcmp(name, "linkcolor")) {
1782 if(strlen(value)!=8) {
1783 fprintf(stderr, "Unknown format for option 'linkcolor'. (%s <-> RRGGBBAA)\n", value);
1786 # define NIBBLE(s) (((s)>='0' && (s)<='9')?((s)-'0'):((s)&0x0f)+9)
1787 i->config_linkcolor.r = NIBBLE(value[0])<<4 | NIBBLE(value[1]);
1788 i->config_linkcolor.g = NIBBLE(value[2])<<4 | NIBBLE(value[3]);
1789 i->config_linkcolor.b = NIBBLE(value[4])<<4 | NIBBLE(value[5]);
1790 i->config_linkcolor.a = NIBBLE(value[6])<<4 | NIBBLE(value[7]);
1791 printf("%02x%02x%02x%02x\n",
1792 i->config_linkcolor.r,
1793 i->config_linkcolor.g,
1794 i->config_linkcolor.b,
1795 i->config_linkcolor.a);
1798 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1804 // --------------------------------------------------------------------
1806 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
1809 swf_GetCXForm(0, &cx, 1);
1812 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
1813 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
1814 c->br!=0 || c->bg!=0 || c->ba!=0 ||
1815 c->ar!=0 || c->ag!=0 || c->ab!=0)
1816 msg("<warning> CXForm not SWF-compatible");
1818 cx.a0 = (S16)(c->aa*256);
1819 cx.r0 = (S16)(c->rr*256);
1820 cx.g0 = (S16)(c->gg*256);
1821 cx.b0 = (S16)(c->bb*256);
1830 static int imageInCache(gfxdevice_t*dev, void*data, int width, int height)
1834 static void addImageToCache(gfxdevice_t*dev, void*data, int width, int height)
1838 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
1840 gfxdevice_t*dev = i->dev;
1842 RGBA*mem = (RGBA*)img->data;
1844 int sizex = img->width;
1845 int sizey = img->height;
1846 int is_jpeg = i->jpeg;
1849 int newsizex=sizex, newsizey=sizey;
1852 if(is_jpeg && i->config_jpegsubpixels) {
1853 newsizex = (int)(targetwidth*i->config_jpegsubpixels+0.5);
1854 newsizey = (int)(targetheight*i->config_jpegsubpixels+0.5);
1855 } else if(!is_jpeg && i->config_ppmsubpixels) {
1856 newsizex = (int)(targetwidth*i->config_ppmsubpixels+0.5);
1857 newsizey = (int)(targetheight*i->config_ppmsubpixels+0.5);
1861 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
1864 /* TODO: cache images */
1866 if(newsizex<sizex || newsizey<sizey) {
1867 msg("<verbose> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
1868 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
1869 *newwidth = sizex = newsizex;
1870 *newheight = sizey = newsizey;
1873 *newwidth = newsizex = sizex;
1874 *newheight = newsizey = sizey;
1877 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
1878 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
1880 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
1882 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
1885 targetwidth, targetheight,
1886 /*newsizex, newsizey,*/
1887 num_colors>256?">":"", num_colors>256?256:num_colors);
1889 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
1890 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
1892 for(t=0;t<num_colors;t++) {
1893 printf("%02x%02x%02x%02x ",
1894 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
1901 int cacheid = imageInCache(dev, mem, sizex, sizey);
1904 bitid = getNewID(dev);
1905 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, i->config_jpegquality);
1906 addImageToCache(dev, mem, sizex, sizey);
1916 static SRECT gfxline_getSWFbbox(gfxline_t*line)
1918 gfxbbox_t bbox = gfxline_getbbox(line);
1920 r.xmin = (int)(bbox.xmin*20);
1921 r.ymin = (int)(bbox.ymin*20);
1922 r.xmax = (int)(bbox.xmax*20);
1923 r.ymax = (int)(bbox.ymax*20);
1927 int line_is_empty(gfxline_t*line)
1930 if(line->type != gfx_moveTo)
1937 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
1939 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1941 if(line_is_empty(line))
1947 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
1948 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
1950 int newwidth=0,newheight=0;
1951 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
1954 double fx = (double)img->width / (double)newwidth;
1955 double fy = (double)img->height / (double)newheight;
1960 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
1961 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
1962 m.tx = (int)(matrix->tx*20);
1963 m.ty = (int)(matrix->ty*20);
1966 int myshapeid = getNewID(dev);
1967 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
1969 swf_ShapeNew(&shape);
1970 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
1971 swf_SetU16(i->tag, myshapeid);
1972 SRECT r = gfxline_getSWFbbox(line);
1973 swf_SetRect(i->tag,&r);
1974 swf_SetShapeStyles(i->tag,shape);
1975 swf_ShapeCountBits(shape,NULL,NULL);
1976 swf_SetShapeBits(i->tag,shape);
1977 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
1978 i->swflastx = i->swflasty = UNDEFINED_COORD;
1979 drawgfxline(dev, line);
1980 swf_ShapeSetEnd(i->tag);
1981 swf_ShapeFree(shape);
1983 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1984 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
1985 swf_ObjectPlace(i->tag,myshapeid,getNewDepth(dev),&i->page_matrix,&cxform2,NULL);
1988 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
1990 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1995 if(i->clippos >= 127)
1997 msg("<warning> Too many clip levels.");
2001 int myshapeid = getNewID(dev);
2002 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
2004 memset(&col, 0, sizeof(RGBA));
2006 swf_ShapeNew(&shape);
2007 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2009 RGBA markcol = {0,i->mark[0],i->mark[1],i->mark[2]};
2010 swf_ShapeAddSolidFillStyle(shape,&markcol);
2012 swf_SetU16(i->tag,myshapeid);
2013 SRECT r = gfxline_getSWFbbox(line);
2014 swf_SetRect(i->tag,&r);
2015 swf_SetShapeStyles(i->tag,shape);
2016 swf_ShapeCountBits(shape,NULL,NULL);
2017 swf_SetShapeBits(i->tag,shape);
2018 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2019 i->swflastx = i->swflasty = UNDEFINED_COORD;
2020 drawgfxline(dev, line);
2021 swf_ShapeSetEnd(i->tag);
2022 swf_ShapeFree(shape);
2024 /* TODO: remember the bbox, and check all shapes against it */
2026 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2027 i->cliptags[i->clippos] = i->tag;
2028 i->clipshapes[i->clippos] = myshapeid;
2029 i->clipdepths[i->clippos] = getNewDepth(dev);
2033 static void swf_endclip(gfxdevice_t*dev)
2035 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2042 msg("<error> Invalid end of clipping region");
2046 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2047 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2049 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2051 static int gfxline_type(gfxline_t*line)
2057 int haszerosegments=0;
2060 if(line->type == gfx_moveTo) {
2063 } else if(line->type == gfx_lineTo) {
2067 } else if(line->type == gfx_splineTo) {
2069 if(tmpsplines>lines)
2077 if(lines==0 && splines==0) return 0;
2078 else if(lines==1 && splines==0) return 1;
2079 else if(lines==0 && splines==1) return 2;
2080 else if(splines==0) return 3;
2084 static int gfxline_has_dots(gfxline_t*line)
2092 if(line->type == gfx_moveTo) {
2093 /* test the length of the preceding line, and assume it is a dot if
2094 it's length is less than 1.0. But *only* if there's a noticable
2095 gap between the previous line and the next moveTo. (I've come
2096 across a PDF where thousands of "dots" were stringed together,
2098 int last_short_gap = short_gap;
2099 if((fabs(line->x - x) + fabs(line->y - y)) < 1.0) {
2104 if(isline && dist < 1 && !short_gap && !last_short_gap) {
2109 } else if(line->type == gfx_lineTo) {
2110 dist += fabs(line->x - x) + fabs(line->y - y);
2112 } else if(line->type == gfx_splineTo) {
2113 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2114 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2121 if(isline && dist < 1 && !short_gap) {
2127 static int gfxline_fix_short_edges(gfxline_t*line)
2131 if(line->type == gfx_lineTo) {
2132 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2135 } else if(line->type == gfx_splineTo) {
2136 if(fabs(line->sx - x) + fabs(line->sy - y) +
2137 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2148 static char is_inside_page(gfxdevice_t*dev, gfxcoord_t x, gfxcoord_t y)
2150 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2151 if(x<i->min_x || x>i->max_x) return 0;
2152 if(y<i->min_y || y>i->max_y) return 0;
2156 gfxline_t* gfxline_move(gfxline_t*line, double x, double y)
2158 gfxline_t*l = line = gfxline_clone(line);
2170 //#define NORMALIZE_POLYGON_POSITIONS
2172 static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
2174 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2175 if(line_is_empty(line))
2177 int type = gfxline_type(line);
2178 int has_dots = gfxline_has_dots(line);
2179 gfxbbox_t r = gfxline_getbbox(line);
2180 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2182 /* TODO: * split line into segments, and perform this check for all segments */
2184 if(i->config_disable_polygon_conversion || type>=5 ||
2186 (width <= i->config_caplinewidth
2187 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2188 || (cap_style == gfx_capRound && type<=2)))) {} else
2190 /* convert line to polygon */
2191 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2193 gfxline_fix_short_edges(line);
2194 /* we need to convert the line into a polygon */
2195 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2196 gfxline_t*gfxline = SVPtogfxline(svp);
2197 dev->fill(dev, gfxline, color);
2203 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2206 #ifdef NORMALIZE_POLYGON_POSITIONS
2208 double startx = 0, starty = 0;
2209 if(line && line->type == gfx_moveTo) {
2213 line = gfxline_move(line, -startx, -starty);
2214 i->shapeposx = (int)(startx*20);
2215 i->shapeposy = (int)(starty*20);
2218 swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a);
2219 swfoutput_setlinewidth(dev, width);
2222 drawgfxline(dev, line);
2224 #ifdef NORMALIZE_POLYGON_POSITIONS
2225 free(line); //account for _move
2229 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2231 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2232 if(line_is_empty(line))
2234 gfxbbox_t r = gfxline_getbbox(line);
2235 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2238 if(!i->config_ignoredraworder)
2241 #ifdef NORMALIZE_POLYGON_POSITIONS
2243 double startx = 0, starty = 0;
2244 if(line && line->type == gfx_moveTo) {
2248 line = gfxline_move(line, -startx, -starty);
2249 i->shapeposx = (int)(startx*20);
2250 i->shapeposy = (int)(starty*20);
2253 swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a);
2257 drawgfxline(dev, line);
2258 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2260 #ifdef NORMALIZE_POLYGON_POSITIONS
2261 free(line); //account for _move
2264 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2266 if(line_is_empty(line))
2268 msg("<error> Gradient filling not implemented yet");
2271 static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
2273 SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
2275 SRECT bounds = {0,0,0,0};
2277 swffont->version = 2;
2278 swffont->name = (U8*)strdup(id);
2279 swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
2280 swffont->layout->ascent = 0; /* ? */
2281 swffont->layout->descent = 0;
2282 swffont->layout->leading = 0;
2283 swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
2284 swffont->encoding = FONT_ENCODING_UNICODE;
2285 swffont->numchars = font->num_glyphs;
2286 swffont->maxascii = font->max_unicode;
2287 swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
2288 swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
2289 swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
2290 swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
2291 for(t=0;t<font->max_unicode;t++) {
2292 swffont->ascii2glyph[t] = font->unicode2glyph[t];
2294 for(t=0;t<font->num_glyphs;t++) {
2298 swffont->glyph2ascii[t] = font->glyphs[t].unicode;
2299 if(font->glyphs[t].name) {
2300 swffont->glyphnames[t] = strdup(font->glyphs[t].name);
2302 swffont->glyphnames[t] = 0;
2304 advance = (int)(font->glyphs[t].advance);
2306 swf_Shape01DrawerInit(&draw, 0);
2307 line = font->glyphs[t].line;
2310 c.x = line->sx; c.y = line->sy;
2311 to.x = line->x; to.y = line->y;
2312 if(line->type == gfx_moveTo) {
2313 draw.moveTo(&draw, &to);
2314 } else if(line->type == gfx_lineTo) {
2315 draw.lineTo(&draw, &to);
2316 } else if(line->type == gfx_splineTo) {
2317 draw.splineTo(&draw, &c, &to);
2322 swffont->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
2323 swffont->layout->bounds[t] = swf_ShapeDrawerGetBBox(&draw);
2325 if(swffont->layout->bounds[t].xmax && swffont->layout->bounds[t].xmax*2 < advance) {
2326 printf("fix bad advance value: bbox=%d, advance=%d (%f)\n", swffont->layout->bounds[t].xmax, advance, font->glyphs[t].advance);
2327 advance = swffont->layout->bounds[t].xmax;
2331 swffont->glyph[t].advance = advance;
2333 swffont->glyph[t].advance = 32767;
2336 draw.dealloc(&draw);
2338 swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
2340 if(bounds.ymin < 0 && bounds.ymax > 0) {
2341 swffont->layout->ascent = -bounds.ymin;
2342 swffont->layout->descent = bounds.ymax;
2343 swffont->layout->leading = bounds.ymax - bounds.ymin;
2345 swffont->layout->ascent = (bounds.ymax - bounds.ymin)/2;
2346 swffont->layout->descent = (bounds.ymax - bounds.ymin)/2;
2347 swffont->layout->leading = bounds.ymax - bounds.ymin;
2353 static void swf_addfont(gfxdevice_t*dev, gfxfont_t*font)
2355 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2357 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,font->id))
2358 return; // the requested font is the current font
2360 fontlist_t*last=0,*l = i->fontlist;
2363 if(!strcmp((char*)l->swffont->name, font->id)) {
2364 return; // we already know this font
2368 l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
2369 l->swffont = gfxfont_to_swffont(font, font->id);
2376 swf_FontSetID(l->swffont, getNewID(i->dev));
2378 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
2380 // print font information
2381 msg("<debug> Font %s",font->id);
2382 msg("<debug> | ID: %d", l->swffont->id);
2383 msg("<debug> | Version: %d", l->swffont->version);
2384 msg("<debug> | Name: %s", l->swffont->name);
2385 msg("<debug> | Numchars: %d", l->swffont->numchars);
2386 msg("<debug> | Maxascii: %d", l->swffont->maxascii);
2387 msg("<debug> | Style: %d", l->swffont->style);
2388 msg("<debug> | Encoding: %d", l->swffont->encoding);
2389 for(iii=0; iii<l->swffont->numchars;iii++) {
2390 msg("<debug> | Glyph %d) name=%s, unicode=%d size=%d bbox=(%.2f,%.2f,%.2f,%.2f)\n", iii, l->swffont->glyphnames?l->swffont->glyphnames[iii]:"<nonames>", l->swffont->glyph2ascii[iii], l->swffont->glyph[iii].shape->bitlen,
2391 l->swffont->layout->bounds[iii].xmin/20.0,
2392 l->swffont->layout->bounds[iii].ymin/20.0,
2393 l->swffont->layout->bounds[iii].xmax/20.0,
2394 l->swffont->layout->bounds[iii].ymax/20.0
2397 for(t=0;t<l->swffont->maxascii;t++) {
2398 if(l->swffont->ascii2glyph[t] == iii)
2399 msg("<debug> | - maps to %d",t);
2405 static void swf_switchfont(gfxdevice_t*dev, char*fontid)
2407 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2409 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2410 return; // the requested font is the current font
2412 fontlist_t*l = i->fontlist;
2414 if(!strcmp((char*)l->swffont->name, fontid)) {
2415 i->swffont = l->swffont;
2420 msg("<error> Unknown font id: %s", fontid);
2424 static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
2426 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2428 if(!i->swffont || !i->swffont->name || strcmp((char*)i->swffont->name,font->id)) // not equal to current font
2430 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
2431 with multiple fonts */
2434 swf_switchfont(dev, font->id); // set the current font
2436 swfoutput_setfontmatrix(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
2446 /* printf("%f %f\n", m.m31, m.m32);
2448 static int xpos = 40;
2449 static int ypos = 200;
2456 drawchar(dev, i->swffont, glyph, &m, color);