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"
39 #define CHARDATAMAX 8192
43 typedef struct _chardata {
45 int fontid; /* TODO: use a SWFFONT instead */
52 typedef struct _fontlist
55 struct _fontlist*next;
58 typedef long int twip;
60 typedef struct _swfmatrix {
61 double m11,m12,m21,m22,m31,m32;
64 typedef struct _swfoutput_internal
66 gfxdevice_t*dev; // the gfxdevice object where this internal struct resides
68 double config_dumpfonts;
69 double config_ppmsubpixels;
70 double config_jpegsubpixels;
71 int config_opennewwindow;
72 int config_ignoredraworder;
73 int config_drawonlyshapes;
74 int config_jpegquality;
75 int config_storeallcharacters;
76 int config_generate_fake_tags;
77 int config_enablezlib;
78 int config_insertstoptag;
79 int config_flashversion;
80 int config_splinemaxerror;
81 int config_fontsplinemaxerror;
82 int config_filloverlap;
85 float config_minlinewidth;
86 double config_caplinewidth;
87 char* config_linktarget;
126 int pic_height[1024];
132 char fillstylechanged;
134 int jpeg; //next image type
139 chardata_t chardata[CHARDATAMAX];
147 double fontm11,fontm12,fontm21,fontm22;
156 } swfoutput_internal;
158 static void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
159 static int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
160 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);
161 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
162 static void swf_endclip(gfxdevice_t*dev);
163 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);
164 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
165 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
166 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
167 static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
168 static void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font);
169 static void swf_drawlink(gfxdevice_t*dev, gfxline_t*line, char*action);
170 static void swf_startframe(gfxdevice_t*dev, int width, int height);
171 static void swf_endframe(gfxdevice_t*dev);
172 static gfxresult_t* swf_finish(gfxdevice_t*driver);
174 static swfoutput_internal* init_internal_struct()
176 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
177 memset(i, 0, sizeof(swfoutput_internal));
199 i->fillstylechanged = 0;
206 i->config_dumpfonts=0;
207 i->config_ppmsubpixels=0;
208 i->config_jpegsubpixels=0;
209 i->config_opennewwindow=1;
210 i->config_ignoredraworder=0;
211 i->config_drawonlyshapes=0;
212 i->config_jpegquality=85;
213 i->config_storeallcharacters=0;
214 i->config_enablezlib=0;
215 i->config_generate_fake_tags=0;
216 i->config_insertstoptag=0;
217 i->config_flashversion=6;
218 i->config_splinemaxerror=1;
219 i->config_fontsplinemaxerror=1;
220 i->config_filloverlap=0;
222 i->config_bboxvars=0;
223 i->config_minlinewidth=0.05;
224 i->config_caplinewidth=1;
225 i->config_linktarget=0;
230 static int id_error = 0;
232 static U16 getNewID(gfxdevice_t* dev)
234 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
235 if(i->currentswfid == 65535) {
237 msg("<error> ID Table overflow");
241 return ++i->currentswfid;
243 static U16 getNewDepth(gfxdevice_t* dev)
245 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
246 if(i->depth == 65535) {
248 msg("<error> Depth Table overflow");
255 static void startshape(gfxdevice_t* dev);
256 static void starttext(gfxdevice_t* dev);
257 static void endshape(gfxdevice_t* dev);
258 static void endtext(gfxdevice_t* dev);
260 typedef struct _plotxy
265 // write a move-to command into the swf
266 static int movetoxy(gfxdevice_t*dev, TAG*tag, plotxy_t p0)
268 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
269 int rx = (int)(p0.x*20);
270 int ry = (int)(p0.y*20);
271 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
272 swf_ShapeSetMove (tag, i->shape, rx,ry);
273 i->fillstylechanged = 0;
280 static int moveto(gfxdevice_t*dev, TAG*tag, double x, double y)
282 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
286 return movetoxy(dev, tag, p);
288 static void addPointToBBox(gfxdevice_t*dev, int px, int py)
290 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
296 swf_ExpandRect(&i->bboxrect, p);
298 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
302 /*static void plot(gfxdevice_t*dev, int x, int y, TAG*tag)
304 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
305 int width = i->linewidth/4;
309 //swf_ShapeSetLine(tag, i->shape,-width,-width);
310 //swf_ShapeSetLine(tag, i->shape,width*2,0);
311 //swf_ShapeSetLine(tag, i->shape,0,width*2);
312 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
313 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
314 //swf_ShapeSetLine(tag, i->shape,width,width);
317 swf_ShapeSetLine(tag, i->shape,-width,0);
318 swf_ShapeSetLine(tag, i->shape,width,-width);
319 swf_ShapeSetLine(tag, i->shape,width,width);
320 swf_ShapeSetLine(tag, i->shape,-width,width);
321 swf_ShapeSetLine(tag, i->shape,-width,-width);
322 swf_ShapeSetLine(tag, i->shape,width,0);
324 addPointToBBox(dev, x-width ,y-width);
325 addPointToBBox(dev, x+width ,y+width);
328 // write a line-to command into the swf
329 static void linetoxy(gfxdevice_t*dev, TAG*tag, plotxy_t p0)
331 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
332 int px = (int)(p0.x*20);
333 int py = (int)(p0.y*20);
334 int rx = (px-i->swflastx);
335 int ry = (py-i->swflasty);
337 swf_ShapeSetLine (tag, i->shape, rx,ry);
338 addPointToBBox(dev, i->swflastx,i->swflasty);
339 addPointToBBox(dev, px,py);
340 }/* else if(!i->fill) {
341 // treat lines of length 0 as plots, making them
342 // at least 1 twip wide so Flash will display them
343 plot(dev, i->swflastx, i->swflasty, tag);
350 static void lineto(gfxdevice_t*dev, TAG*tag, double x, double y)
355 linetoxy(dev,tag, p);
358 // write a spline-to command into the swf
359 static void splineto(gfxdevice_t*dev, TAG*tag, plotxy_t control,plotxy_t end)
361 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
362 int lastlastx = i->swflastx;
363 int lastlasty = i->swflasty;
365 int cx = ((int)(control.x*20)-i->swflastx);
366 int cy = ((int)(control.y*20)-i->swflasty);
369 int ex = ((int)(end.x*20)-i->swflastx);
370 int ey = ((int)(end.y*20)-i->swflasty);
374 if(cx || cy || ex || ey) {
375 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
376 addPointToBBox(dev, lastlastx ,lastlasty );
377 addPointToBBox(dev, lastlastx+cx,lastlasty+cy);
378 addPointToBBox(dev, lastlastx+cx+ex,lastlasty+cy+ey);
379 }/* else if(!i->fill) {
380 // treat splines of length 0 as plots
381 plot(dev, lastlastx, lastlasty, tag);
386 /* write a line, given two points and the transformation
388 /*static void line(gfxdevice_t*dev, TAG*tag, plotxy_t p0, plotxy_t p1)
390 moveto(dev, tag, p0);
391 lineto(dev, tag, p1);
394 void resetdrawer(gfxdevice_t*dev)
396 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
401 static void stopFill(gfxdevice_t*dev)
403 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
406 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
407 i->fillstylechanged = 1;
411 static void startFill(gfxdevice_t*dev)
413 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
416 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
417 i->fillstylechanged = 1;
422 static inline int colorcompare(gfxdevice_t*dev, RGBA*a,RGBA*b)
434 static SRECT getcharacterbbox(gfxdevice_t*dev, SWFFONT*font, MATRIX* m)
436 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
439 memset(&r, 0, sizeof(r));
442 if(debug) printf("\n");
443 for(t=0;t<i->chardatapos;t++)
445 if(i->chardata[t].fontid != font->id) {
446 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
449 SRECT b = font->layout->bounds[i->chardata[t].charid];
450 b.xmin *= i->chardata[t].size;
451 b.ymin *= i->chardata[t].size;
452 b.xmax *= i->chardata[t].size;
453 b.ymax *= i->chardata[t].size;
455 /* divide by 1024, rounding xmax/ymax up */
456 b.xmax += 1023; b.ymax += 1023; b.xmin /= 1024; b.ymin /= 1024; b.xmax /= 1024; b.ymax /= 1024;
458 b.xmin += i->chardata[t].x;
459 b.ymin += i->chardata[t].y;
460 b.xmax += i->chardata[t].x;
461 b.ymax += i->chardata[t].y;
463 /* until we solve the INTERNAL_SCALING problem (see below)
464 make sure the bounding box is big enough */
470 b = swf_TurnRect(b, m);
472 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
473 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
474 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
475 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
476 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
481 i->chardata[t].fontid,
483 i->chardata[t].charid
485 swf_ExpandRect2(&r, &b);
487 if(debug) printf("-----> (%f,%f,%f,%f)\n",
495 static void putcharacters(gfxdevice_t*dev, TAG*tag)
497 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
501 color.r = i->chardata[0].color.r^255;
510 int charadvance[128];
513 int glyphbits=1; //TODO: can this be zero?
516 if(tag->id != ST_DEFINETEXT &&
517 tag->id != ST_DEFINETEXT2) {
518 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
521 if(!i->chardatapos) {
522 msg("<warning> putcharacters called with zero characters");
525 for(pass = 0; pass < 2; pass++)
535 advancebits++; // add sign bit
536 swf_SetU8(tag, glyphbits);
537 swf_SetU8(tag, advancebits);
540 for(t=0;t<=i->chardatapos;t++)
542 if(lastfontid != i->chardata[t].fontid ||
543 lastx!=i->chardata[t].x ||
544 lasty!=i->chardata[t].y ||
545 !colorcompare(dev,&color, &i->chardata[t].color) ||
547 lastsize != i->chardata[t].size ||
550 if(charstorepos && pass==0)
553 for(s=0;s<charstorepos;s++)
555 while(charids[s]>=(1<<glyphbits))
557 while(charadvance[s]>=(1<<advancebits))
561 if(charstorepos && pass==1)
563 tag->writeBit = 0; // Q&D
564 swf_SetBits(tag, 0, 1); // GLYPH Record
565 swf_SetBits(tag, charstorepos, 7); // number of glyphs
567 for(s=0;s<charstorepos;s++)
569 swf_SetBits(tag, charids[s], glyphbits);
570 swf_SetBits(tag, charadvance[s], advancebits);
575 if(pass == 1 && t<i->chardatapos)
581 if(lastx != i->chardata[t].x ||
582 lasty != i->chardata[t].y)
584 newx = i->chardata[t].x;
585 newy = i->chardata[t].y;
591 if(!colorcompare(dev,&color, &i->chardata[t].color))
593 color = i->chardata[t].color;
596 font.id = i->chardata[t].fontid;
597 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
600 tag->writeBit = 0; // Q&D
601 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
604 lastfontid = i->chardata[t].fontid;
605 lastx = i->chardata[t].x;
606 lasty = i->chardata[t].y;
607 lastsize = i->chardata[t].size;
610 if(t==i->chardatapos)
614 int nextt = t==i->chardatapos-1?t:t+1;
615 int rel = i->chardata[nextt].x-i->chardata[t].x;
616 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
618 lastx=i->chardata[nextt].x;
622 lastx=i->chardata[t].x;
624 charids[charstorepos] = i->chardata[t].charid;
625 charadvance[charstorepos] = advance;
632 static void putcharacter(gfxdevice_t*dev, int fontid, int charid, int x,int y, int size, RGBA color)
634 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
635 if(i->chardatapos == CHARDATAMAX)
637 msg("<warning> Character buffer too small. SWF will be slightly bigger");
641 i->chardata[i->chardatapos].fontid = fontid;
642 i->chardata[i->chardatapos].charid = charid;
643 i->chardata[i->chardatapos].x = x;
644 i->chardata[i->chardatapos].y = y;
645 i->chardata[i->chardatapos].color = color;
646 i->chardata[i->chardatapos].size = size;
650 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
651 So if we set this value to high, the char coordinates will overflow.
652 If we set it to low, however, the char positions will be inaccurate */
653 #define FONT_INTERNAL_SIZE 4
655 /* process a character. */
656 static int drawchar(gfxdevice_t*dev, SWFFONT *swffont, int charid, swfmatrix_t*m, gfxcolor_t*col)
658 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
660 msg("<warning> Font is NULL");
664 if(charid<0 || charid>=swffont->numchars) {
665 msg("<warning> No character %d in font %s ", charid, FIXNULL((char*)swffont->name));
668 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
669 msg("<warning> Glyph %d in current charset (%s, %d characters) is empty",
670 charid, FIXNULL((char*)swffont->name), swffont->numchars);
681 float det = ((m->m11*m->m22)-(m->m21*m->m12));
682 if(fabs(det) < 0.0005) {
683 /* x direction equals y direction- the text is invisible */
686 det = 20*FONT_INTERNAL_SIZE / det;
689 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
690 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
692 RGBA rgba = *(RGBA*)col;
693 putcharacter(dev, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
694 swf_FontUseGlyph(swffont, charid);
698 static void endtext(gfxdevice_t*dev)
700 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
704 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
705 swf_SetU16(i->tag, i->textid);
708 r = getcharacterbbox(dev, i->swffont, &i->fontmatrix);
710 swf_SetRect(i->tag,&r);
712 swf_SetMatrix(i->tag,&i->fontmatrix);
714 msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
716 putcharacters(dev, i->tag);
718 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
720 swf_ObjectPlace(i->tag,i->textid,getNewDepth(dev),&i->page_matrix,NULL,NULL);
724 /* set's the matrix which is to be applied to characters drawn by swfoutput_drawchar() */
725 static void swfoutput_setfontmatrix(gfxdevice_t*dev,double m11,double m21,
726 double m12,double m22)
732 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
733 if(i->fontm11 == m11 &&
746 m.sx = (U32)(((i->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((i->fontm12)*65536)/FONT_INTERNAL_SIZE);
747 m.r0 = (U32)(((i->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((i->fontm22)*65536)/FONT_INTERNAL_SIZE);
753 static void endpage(gfxdevice_t*dev)
755 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
765 void swf_startframe(gfxdevice_t*dev, int width, int height)
767 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
768 if(!i->firstpage && !i->pagefinished)
770 msg("<verbose> Starting new SWF page of size %dx%d", width, height);
772 swf_GetMatrix(0, &i->page_matrix);
773 i->page_matrix.tx = 0;
774 i->page_matrix.ty = 0;
780 /* set clipping/background rectangle */
781 /* TODO: this should all be done in SWFOutputDev */
782 //setBackground(dev, x1, y1, x2, y2);
784 /* increase SWF's bounding box */
790 swf_ExpandRect2(&i->swf->movieSize, &r);
792 i->lastframeno = i->frameno;
797 void swf_endframe(gfxdevice_t*dev)
799 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
804 if(i->config_insertstoptag) {
806 atag = action_Stop(atag);
807 atag = action_End(atag);
808 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
809 swf_ActionSet(i->tag,atag);
811 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
814 for(i->depth;i->depth>i->startdepth;i->depth--) {
815 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
816 swf_SetU16(i->tag,i->depth);
818 i->depth = i->startdepth;
821 static void setBackground(gfxdevice_t*dev, int x1, int y1, int x2, int y2)
823 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
825 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
829 int shapeid = getNewID(dev);
834 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
836 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
837 swf_SetU16(i->tag,shapeid);
838 swf_SetRect(i->tag,&r);
839 swf_SetShapeHeader(i->tag,s);
840 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
841 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
842 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
843 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
844 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
845 swf_ShapeSetEnd(i->tag);
847 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
848 swf_ObjectPlace(i->tag,shapeid,getNewDepth(dev),0,0,0);
849 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
850 swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(dev),0,0,0,65535);
853 /* initialize the swf writer */
854 void gfxdevice_swf_init(gfxdevice_t* dev)
856 memset(dev, 0, sizeof(gfxdevice_t));
857 dev->internal = init_internal_struct();
859 dev->startpage = swf_startframe;
860 dev->endpage = swf_endframe;
861 dev->finish = swf_finish;
862 dev->fillbitmap = swf_fillbitmap;
863 dev->setparameter = swf_setparameter;
864 dev->stroke = swf_stroke;
865 dev->startclip = swf_startclip;
866 dev->endclip = swf_endclip;
867 dev->fill = swf_fill;
868 dev->fillbitmap = swf_fillbitmap;
869 dev->fillgradient = swf_fillgradient;
870 dev->addfont = swf_addfont;
871 dev->drawchar = swf_drawchar;
872 dev->drawlink = swf_drawlink;
874 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
880 msg("<verbose> initializing swf output\n", i->max_x,i->max_y);
884 i->swf = (SWF*)rfx_calloc(sizeof(SWF));
885 i->swf->fileVersion = i->config_flashversion;
886 i->swf->frameRate = 0x0040; // 1 frame per 4 seconds
887 i->swf->movieSize.xmin = 0;
888 i->swf->movieSize.ymin = 0;
889 i->swf->movieSize.xmax = 0;
890 i->swf->movieSize.ymax = 0;
892 i->swf->firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
893 i->tag = i->swf->firstTag;
894 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
895 swf_SetRGB(i->tag,&rgb);
897 i->startdepth = i->depth = 0;
899 if(i->config_protect)
900 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
903 static void startshape(gfxdevice_t*dev)
905 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
914 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
916 swf_ShapeNew(&i->shape);
917 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&i->strokergb);
918 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&i->fillrgb);
920 i->shapeid = getNewID(dev);
922 msg("<debug> Using shape id %d", i->shapeid);
924 swf_SetU16(i->tag,i->shapeid); // ID
926 i->bboxrectpos = i->tag->len;
930 r.xmax = 20*i->max_x;
931 r.ymax = 20*i->max_y;
932 swf_SetRect(i->tag,&r);
934 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
936 swf_SetShapeStyles(i->tag,i->shape);
937 swf_ShapeCountBits(i->shape,NULL,NULL);
938 swf_SetShapeBits(i->tag,i->shape);
940 /* TODO: do we really need this? */
941 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
942 i->swflastx=i->swflasty=0;
947 static void starttext(gfxdevice_t*dev)
949 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
953 i->textid = getNewID(dev);
955 i->swflastx=i->swflasty=0;
959 /* TODO: move to ../lib/rfxswf */
960 void changeRect(gfxdevice_t*dev, TAG*tag, int pos, SRECT*newrect)
962 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
963 /* determine length of old rect */
967 swf_GetRect(tag, &old);
968 swf_ResetReadBits(tag);
969 int pos_end = tag->pos;
971 int len = tag->len - pos_end;
972 U8*data = (U8*)malloc(len);
973 memcpy(data, &tag->data[pos_end], len);
976 swf_SetRect(tag, newrect);
977 swf_SetBlock(tag, data, len);
979 tag->pos = tag->readBit = 0;
982 void cancelshape(gfxdevice_t*dev)
984 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
985 /* delete old shape tag */
987 i->tag = i->tag->prev;
988 swf_DeleteTag(todel);
989 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
994 void fixAreas(gfxdevice_t*dev)
996 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
997 if(!i->shapeisempty && i->fill &&
998 (i->bboxrect.xmin == i->bboxrect.xmax ||
999 i->bboxrect.ymin == i->bboxrect.ymax) &&
1000 i->config_minlinewidth >= 0.001
1002 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1003 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1004 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1007 SRECT r = i->bboxrect;
1009 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1010 /* this thing comes down to a single dot- nothing to fix here */
1016 RGBA save_col = i->strokergb;
1017 int save_width = i->linewidth;
1019 i->strokergb = i->fillrgb;
1020 i->linewidth = (int)(i->config_minlinewidth*20);
1021 if(i->linewidth==0) i->linewidth = 1;
1025 moveto(dev, i->tag, r.xmin/20.0,r.ymin/20.0);
1026 lineto(dev, i->tag, r.xmax/20.0,r.ymax/20.0);
1028 i->strokergb = save_col;
1029 i->linewidth = save_width;
1034 static void endshape_noput(gfxdevice_t*dev)
1036 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1039 //changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1042 swf_ShapeFree(i->shape);
1050 static void endshape(gfxdevice_t*dev)
1052 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1058 if(i->shapeisempty ||
1060 (i->bboxrect.xmin == i->bboxrect.xmax &&
1061 i->bboxrect.ymin == i->bboxrect.ymax))
1063 // delete the shape again, we didn't do anything
1064 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1065 i->bboxrect.xmin /20.0,
1066 i->bboxrect.ymin /20.0,
1067 i->bboxrect.xmax /20.0,
1068 i->bboxrect.ymax /20.0
1074 swf_ShapeSetEnd(i->tag);
1076 changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1078 msg("<trace> Placing shape id %d", i->shapeid);
1080 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1081 MATRIX m = i->page_matrix;
1082 m.tx += i->shapeposx;
1083 m.ty += i->shapeposy;
1084 swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(dev),&m,NULL,NULL);
1086 swf_ShapeFree(i->shape);
1089 i->bboxrectpos = -1;
1096 void wipeSWF(SWF*swf)
1098 TAG*tag = swf->firstTag;
1100 TAG*next = tag->next;
1101 if(tag->id != ST_SETBACKGROUNDCOLOR &&
1102 tag->id != ST_END &&
1103 tag->id != ST_DOACTION &&
1104 tag->id != ST_SHOWFRAME) {
1112 void swfoutput_finalize(gfxdevice_t*dev)
1114 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1116 if(i->tag && i->tag->id == ST_END)
1117 return; //already done
1119 if(i->config_bboxvars) {
1120 TAG* tag = swf_InsertTag(i->swf->firstTag, ST_DOACTION);
1122 a = action_PushString(a, "xmin");
1123 a = action_PushFloat(a, i->swf->movieSize.xmin / 20.0);
1124 a = action_SetVariable(a);
1125 a = action_PushString(a, "ymin");
1126 a = action_PushFloat(a, i->swf->movieSize.ymin / 20.0);
1127 a = action_SetVariable(a);
1128 a = action_PushString(a, "xmax");
1129 a = action_PushFloat(a, i->swf->movieSize.xmax / 20.0);
1130 a = action_SetVariable(a);
1131 a = action_PushString(a, "ymax");
1132 a = action_PushFloat(a, i->swf->movieSize.ymax / 20.0);
1133 a = action_SetVariable(a);
1134 a = action_PushString(a, "width");
1135 a = action_PushFloat(a, (i->swf->movieSize.xmax - i->swf->movieSize.xmin) / 20.0);
1136 a = action_SetVariable(a);
1137 a = action_PushString(a, "height");
1138 a = action_PushFloat(a, (i->swf->movieSize.ymax - i->swf->movieSize.ymin) / 20.0);
1139 a = action_SetVariable(a);
1141 swf_ActionSet(tag, a);
1145 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1149 fontlist_t *tmp,*iterator = i->fontlist;
1151 TAG*mtag = i->swf->firstTag;
1152 if(iterator->swffont) {
1153 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1154 if(!i->config_storeallcharacters) {
1155 msg("<debug> Reducing font %s", iterator->swffont->name);
1156 swf_FontReduce(iterator->swffont);
1158 swf_FontSetDefine2(mtag, iterator->swffont);
1161 iterator = iterator->next;
1163 i->tag = swf_InsertTag(i->tag,ST_END);
1164 TAG* tag = i->tag->prev;
1166 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1167 and the ST_END- they confuse the flash player */
1168 while(tag->id == ST_REMOVEOBJECT2) {
1169 TAG* prev = tag->prev;
1177 if(i->config_enablezlib || i->config_flashversion>=6) {
1178 i->swf->compressed = 1;
1182 int swfresult_save(gfxresult_t*gfx, char*filename)
1184 SWF*swf = (SWF*)gfx->internal;
1187 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1192 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1196 if(swf->compressed) {
1197 if FAILED(swf_WriteSWC(fi,swf))
1198 msg("<error> WriteSWC() failed.\n");
1200 if FAILED(swf_WriteSWF(fi,swf))
1201 msg("<error> WriteSWF() failed.\n");
1208 void* swfresult_get(gfxresult_t*gfx, char*name)
1210 SWF*swf = (SWF*)gfx->internal;
1211 if(!strcmp(name, "swf")) {
1212 return (void*)swf_CopySWF(swf);
1213 } else if(!strcmp(name, "xmin")) {
1214 return (void*)(swf->movieSize.xmin/20);
1215 } else if(!strcmp(name, "ymin")) {
1216 return (void*)(swf->movieSize.ymin/20);
1217 } else if(!strcmp(name, "xmax")) {
1218 return (void*)(swf->movieSize.xmax/20);
1219 } else if(!strcmp(name, "ymax")) {
1220 return (void*)(swf->movieSize.ymax/20);
1221 } else if(!strcmp(name, "width")) {
1222 return (void*)((swf->movieSize.xmax - swf->movieSize.xmin)/20);
1223 } else if(!strcmp(name, "height")) {
1224 return (void*)((swf->movieSize.ymax - swf->movieSize.ymin)/20);
1228 void swfresult_destroy(gfxresult_t*gfx)
1231 swf_FreeTags((SWF*)gfx->internal);
1232 free(gfx->internal);
1235 memset(gfx, 0, sizeof(gfxresult_t));
1239 static void swfoutput_destroy(gfxdevice_t* dev);
1241 gfxresult_t* swf_finish(gfxdevice_t* dev)
1243 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1246 if(i->config_linktarget) {
1247 free(i->config_linktarget);
1248 i->config_linktarget = 0;
1251 swfoutput_finalize(dev);
1252 SWF* swf = i->swf;i->swf = 0;
1253 swfoutput_destroy(dev);
1255 result = (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t));
1256 result->internal = swf;
1257 result->save = swfresult_save;
1259 result->get = swfresult_get;
1260 result->destroy = swfresult_destroy;
1264 /* Perform cleaning up */
1265 static void swfoutput_destroy(gfxdevice_t* dev)
1267 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1269 /* not initialized yet- nothing to destroy */
1273 fontlist_t *tmp,*iterator = i->fontlist;
1275 if(iterator->swffont) {
1276 swf_FontFree(iterator->swffont);iterator->swffont=0;
1279 iterator = iterator->next;
1282 if(i->swf) {swf_FreeTags(i->swf);free(i->swf);i->swf = 0;}
1285 memset(dev, 0, sizeof(gfxdevice_t));
1288 static void swfoutput_setfillcolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1290 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1291 if(i->fillrgb.r == r &&
1292 i->fillrgb.g == g &&
1293 i->fillrgb.b == b &&
1294 i->fillrgb.a == a) return;
1304 static void swfoutput_setstrokecolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1306 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1307 if(i->strokergb.r == r &&
1308 i->strokergb.g == g &&
1309 i->strokergb.b == b &&
1310 i->strokergb.a == a) return;
1320 //#define ROUND_UP 19
1321 //#define ROUND_UP 10
1323 static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth)
1325 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1326 if(i->linewidth == (U16)(_linewidth*20+19.0/20.0))
1330 i->linewidth = (U16)(_linewidth*20+19.0/20.0);
1334 static void drawlink(gfxdevice_t*dev, ActionTAG*,ActionTAG*, gfxline_t*points, char mouseover);
1335 static void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points);
1336 static void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points);
1337 static void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points);
1339 void swfoutput_drawlink(gfxdevice_t*dev, char*url, gfxline_t*points)
1341 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1342 dev->drawlink(dev, points, url);
1345 void swf_drawlink(gfxdevice_t*dev, gfxline_t*points, char*url)
1347 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1349 if(!strncmp("http://pdf2swf:", url, 15)) {
1350 char*tmp = strdup(url);
1351 int l = strlen(tmp);
1354 swfoutput_namedlink(dev, tmp+15, points);
1357 } else if(!strncmp("page", url, 4)) {
1360 if(url[t]<'0' || url[t]>'9')
1363 int page = atoi(&url[4]) - 1;
1364 if(page<0) page = 0;
1365 swfoutput_linktopage(dev, page, points);
1368 swfoutput_linktourl(dev, url, points);
1371 void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points)
1374 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1380 if(!i->config_linktarget) {
1381 if(!i->config_opennewwindow)
1382 actions = action_GetUrl(0, url, "_parent");
1384 actions = action_GetUrl(0, url, "_this");
1386 actions = action_GetUrl(0, url, i->config_linktarget);
1388 actions = action_End(actions);
1390 drawlink(dev, actions, 0, points,0);
1392 void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points)
1394 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1402 actions = action_GotoFrame(0, page);
1403 actions = action_End(actions);
1405 drawlink(dev, actions, 0, points,0);
1408 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1409 of the viewer objects, like subtitles, index elements etc.
1411 void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points)
1413 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1414 ActionTAG *actions1,*actions2;
1415 char*tmp = strdup(name);
1423 if(!strncmp(tmp, "call:", 5))
1425 char*x = strchr(&tmp[5], ':');
1427 actions1 = action_PushInt(0, 0); //number of parameters (0)
1428 actions1 = action_PushString(actions1, &tmp[5]); //function name
1429 actions1 = action_CallFunction(actions1);
1432 actions1 = action_PushString(0, x+1); //parameter
1433 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1434 actions1 = action_PushString(actions1, &tmp[5]); //function name
1435 actions1 = action_CallFunction(actions1);
1437 actions2 = action_End(0);
1442 actions1 = action_PushString(0, "/:subtitle");
1443 actions1 = action_PushString(actions1, name);
1444 actions1 = action_SetVariable(actions1);
1445 actions1 = action_End(actions1);
1447 actions2 = action_PushString(0, "/:subtitle");
1448 actions2 = action_PushString(actions2, "");
1449 actions2 = action_SetVariable(actions2);
1450 actions2 = action_End(actions2);
1453 drawlink(dev, actions1, actions2, points,mouseover);
1455 swf_ActionFree(actions1);
1456 swf_ActionFree(actions2);
1460 static void drawgfxline(gfxdevice_t*dev, gfxline_t*line)
1462 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1463 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1468 /* check whether the next segment is zero */
1469 if(line->type == gfx_moveTo) {
1470 msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
1471 moveto(dev, i->tag, line->x, line->y);
1472 px = lastx = line->x;
1473 py = lasty = line->y;
1475 } if(line->type == gfx_lineTo) {
1476 msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
1477 lineto(dev, i->tag, line->x, line->y);
1481 } else if(line->type == gfx_splineTo) {
1482 msg("<trace> ======== splineTo %.2f %.2f", line->x, line->y);
1484 s.x = line->sx;p.x = line->x;
1485 s.y = line->sy;p.y = line->y;
1486 splineto(dev, i->tag, s, p);
1496 static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gfxline_t*points, char mouseover)
1498 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1503 plotxy_t p1,p2,p3,p4;
1509 int buttonid = getNewID(dev);
1510 gfxbbox_t bbox = gfxline_getbbox(points);
1513 myshapeid = getNewID(dev);
1514 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1515 swf_ShapeNew(&i->shape);
1516 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1517 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1518 swf_SetU16(i->tag, myshapeid);
1519 r.xmin = (int)(bbox.xmin*20);
1520 r.ymin = (int)(bbox.ymin*20);
1521 r.xmax = (int)(bbox.xmax*20);
1522 r.ymax = (int)(bbox.ymax*20);
1523 swf_SetRect(i->tag,&r);
1524 swf_SetShapeStyles(i->tag,i->shape);
1525 swf_ShapeCountBits(i->shape,NULL,NULL);
1526 swf_SetShapeBits(i->tag,i->shape);
1527 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1528 i->swflastx = i->swflasty = 0;
1529 drawgfxline(dev, points);
1530 swf_ShapeSetEnd(i->tag);
1533 myshapeid2 = getNewID(dev);
1534 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1535 swf_ShapeNew(&i->shape);
1536 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1538 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1539 swf_SetU16(i->tag, myshapeid2);
1540 r.xmin = (int)(bbox.xmin*20);
1541 r.ymin = (int)(bbox.ymin*20);
1542 r.xmax = (int)(bbox.xmax*20);
1543 r.ymax = (int)(bbox.ymax*20);
1544 swf_SetRect(i->tag,&r);
1545 swf_SetShapeStyles(i->tag,i->shape);
1546 swf_ShapeCountBits(i->shape,NULL,NULL);
1547 swf_SetShapeBits(i->tag,i->shape);
1548 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1549 i->swflastx = i->swflasty = 0;
1550 drawgfxline(dev, points);
1551 swf_ShapeSetEnd(i->tag);
1555 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1556 swf_SetU16(i->tag,buttonid); //id
1557 swf_ButtonSetFlags(i->tag, 0); //menu=no
1558 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1559 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1560 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1561 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1562 swf_SetU8(i->tag,0);
1563 swf_ActionSet(i->tag,actions1);
1564 swf_SetU8(i->tag,0);
1568 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1569 swf_SetU16(i->tag,buttonid); //id
1570 swf_ButtonSetFlags(i->tag, 0); //menu=no
1571 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1572 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1573 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1574 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1575 swf_SetU8(i->tag,0); // end of button records
1576 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1577 swf_ActionSet(i->tag,actions1);
1579 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1580 swf_ActionSet(i->tag,actions2);
1581 swf_SetU8(i->tag,0);
1582 swf_ButtonPostProcess(i->tag, 2);
1584 swf_SetU8(i->tag,0);
1585 swf_ButtonPostProcess(i->tag, 1);
1589 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1591 if(posx!=0 || posy!=0) {
1593 p.x = (int)(posx*20);
1594 p.y = (int)(posy*20);
1595 p = swf_TurnPoint(p, &i->page_matrix);
1600 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&m,0,0);
1602 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&i->page_matrix,0,0);
1609 for(t=0;t<picpos;t++)
1611 if(pic_xids[t] == xid &&
1612 pic_yids[t] == yid) {
1613 width = pic_width[t];
1614 height = pic_height[t];
1618 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1619 pic_xids[picpos] = xid;
1620 pic_yids[picpos] = yid;
1621 pic_width[picpos] = width;
1622 pic_height[picpos] = height;
1625 pic[width*y+x] = buf[0];
1629 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1630 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1634 xid += x*r+x*b*3+x*g*7+x*a*11;
1635 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1637 for(t=0;t<picpos;t++)
1639 if(pic_xids[t] == xid &&
1640 pic_yids[t] == yid) {
1649 int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
1651 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1653 if(!strcmp(name, "jpegsubpixels")) {
1654 i->config_jpegsubpixels = atof(value);
1655 } else if(!strcmp(name, "ppmsubpixels")) {
1656 i->config_ppmsubpixels = atof(value);
1657 } else if(!strcmp(name, "drawonlyshapes")) {
1658 i->config_drawonlyshapes = atoi(value);
1659 } else if(!strcmp(name, "ignoredraworder")) {
1660 i->config_ignoredraworder = atoi(value);
1661 } else if(!strcmp(name, "filloverlap")) {
1662 i->config_filloverlap = atoi(value);
1663 } else if(!strcmp(name, "linksopennewwindow")) {
1664 i->config_opennewwindow = atoi(value);
1665 } else if(!strcmp(name, "opennewwindow")) {
1666 i->config_opennewwindow = atoi(value);
1667 } else if(!strcmp(name, "storeallcharacters")) {
1668 i->config_storeallcharacters = atoi(value);
1669 } else if(!strcmp(name, "enablezlib")) {
1670 i->config_enablezlib = atoi(value);
1671 } else if(!strcmp(name, "bboxvars")) {
1672 i->config_bboxvars = atoi(value);
1673 } else if(!strcmp(name, "insertstop")) {
1674 i->config_insertstoptag = atoi(value);
1675 } else if(!strcmp(name, "protect")) {
1676 i->config_protect = atoi(value);
1677 if(i->config_protect && i->tag) {
1678 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1680 } else if(!strcmp(name, "faketags")) {
1681 i->config_generate_fake_tags = atoi(value);
1682 } else if(!strcmp(name, "flashversion")) {
1683 i->config_flashversion = atoi(value);
1685 i->swf->fileVersion = i->config_flashversion;
1687 } else if(!strcmp(name, "minlinewidth")) {
1688 i->config_minlinewidth = atof(value);
1689 } else if(!strcmp(name, "caplinewidth")) {
1690 i->config_caplinewidth = atof(value);
1691 } else if(!strcmp(name, "linktarget")) {
1692 i->config_linktarget = strdup(value);
1693 } else if(!strcmp(name, "dumpfonts")) {
1694 i->config_dumpfonts = atoi(value);
1695 } else if(!strcmp(name, "next_bitmap_is_jpeg")) {
1697 } else if(!strcmp(name, "jpegquality")) {
1698 int val = atoi(value);
1700 if(val>100) val=100;
1701 i->config_jpegquality = val;
1702 } else if(!strcmp(name, "splinequality")) {
1703 int v = atoi(value);
1704 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1706 i->config_splinemaxerror = v;
1707 } else if(!strcmp(name, "fontquality")) {
1708 int v = atoi(value);
1709 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1711 i->config_fontsplinemaxerror = v;
1713 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1719 // --------------------------------------------------------------------
1721 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
1724 swf_GetCXForm(0, &cx, 1);
1727 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
1728 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
1729 c->br!=0 || c->bg!=0 || c->ba!=0 ||
1730 c->ar!=0 || c->ag!=0 || c->ab!=0)
1731 msg("<warning> CXForm not SWF-compatible");
1733 cx.a0 = (S16)(c->aa*256);
1734 cx.r0 = (S16)(c->rr*256);
1735 cx.g0 = (S16)(c->gg*256);
1736 cx.b0 = (S16)(c->bb*256);
1744 static ArtVpath* gfxline_to_ArtVpath(gfxline_t*line)
1746 ArtVpath *vec = NULL;
1751 /* factor which determines into how many line fragments a spline is converted */
1752 double subfraction = 2.4;//0.3
1756 if(l2->type == gfx_moveTo) {
1758 } if(l2->type == gfx_lineTo) {
1760 } if(l2->type == gfx_splineTo) {
1761 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))*subfraction);
1762 if(!parts) parts = 1;
1772 vec = art_new (ArtVpath, len);
1777 if(l2->type == gfx_moveTo) {
1778 vec[pos].code = ART_MOVETO;
1783 } else if(l2->type == gfx_lineTo) {
1784 vec[pos].code = ART_LINETO;
1789 } else if(l2->type == gfx_splineTo) {
1791 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))*subfraction);
1792 if(!parts) parts = 1;
1793 for(i=0;i<=parts;i++) {
1794 double t = (double)i/(double)parts;
1795 vec[pos].code = ART_LINETO;
1796 vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
1797 vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
1806 vec[pos].code = ART_END;
1811 static ArtSVP* gfxfillToSVP(gfxline_t*line)
1813 ArtVpath* vec = gfxline_to_ArtVpath(line);
1814 ArtSVP *svp = art_svp_from_vpath(vec);
1819 static ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
1821 ArtVpath* vec = gfxline_to_ArtVpath(line);
1822 ArtSVP *svp = art_svp_vpath_stroke (vec,
1823 (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
1824 ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
1825 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
1826 (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
1827 ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
1828 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
1830 miterLimit, //miter_limit
1837 static gfxline_t* SVPtogfxline(ArtSVP*svp)
1842 for(t=0;t<svp->n_segs;t++) {
1843 size += svp->segs[t].n_points + 1;
1845 gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
1847 for(t=0;t<svp->n_segs;t++) {
1848 ArtSVPSeg* seg = &svp->segs[t];
1850 for(p=0;p<seg->n_points;p++) {
1851 lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
1852 ArtPoint* point = &seg->points[p];
1853 lines[pos].x = point->x;
1854 lines[pos].y = point->y;
1855 lines[pos].next = &lines[pos+1];
1860 lines[pos-1].next = 0;
1868 static int imageInCache(gfxdevice_t*dev, void*data, int width, int height)
1872 static void addImageToCache(gfxdevice_t*dev, void*data, int width, int height)
1876 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
1878 gfxdevice_t*dev = i->dev;
1880 RGBA*mem = (RGBA*)img->data;
1882 int sizex = img->width;
1883 int sizey = img->height;
1884 int is_jpeg = i->jpeg;
1887 int newsizex=sizex, newsizey=sizey;
1890 if(is_jpeg && i->config_jpegsubpixels) {
1891 newsizex = (int)(targetwidth*i->config_jpegsubpixels+0.5);
1892 newsizey = (int)(targetheight*i->config_jpegsubpixels+0.5);
1893 } else if(!is_jpeg && i->config_ppmsubpixels) {
1894 newsizex = (int)(targetwidth*i->config_ppmsubpixels+0.5);
1895 newsizey = (int)(targetheight*i->config_ppmsubpixels+0.5);
1899 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
1902 /* TODO: cache images */
1904 if(newsizex<sizex || newsizey<sizey) {
1905 msg("<verbose> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
1906 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
1907 *newwidth = sizex = newsizex;
1908 *newheight = sizey = newsizey;
1911 *newwidth = newsizex = sizex;
1912 *newheight = newsizey = sizey;
1915 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
1916 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
1918 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
1920 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
1923 targetwidth, targetheight,
1924 /*newsizex, newsizey,*/
1925 num_colors>256?">":"", num_colors>256?256:num_colors);
1927 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
1928 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
1930 for(t=0;t<num_colors;t++) {
1931 printf("%02x%02x%02x%02x ",
1932 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
1939 int cacheid = imageInCache(dev, mem, sizex, sizey);
1942 bitid = getNewID(dev);
1943 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, i->config_jpegquality);
1944 addImageToCache(dev, mem, sizex, sizey);
1954 static SRECT gfxline_getSWFbbox(gfxline_t*line)
1956 gfxbbox_t bbox = gfxline_getbbox(line);
1958 r.xmin = (int)(bbox.xmin*20);
1959 r.ymin = (int)(bbox.ymin*20);
1960 r.xmax = (int)(bbox.xmax*20);
1961 r.ymax = (int)(bbox.ymax*20);
1965 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
1967 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1972 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
1973 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
1975 int newwidth=0,newheight=0;
1976 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
1979 double fx = (double)img->width / (double)newwidth;
1980 double fy = (double)img->height / (double)newheight;
1985 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
1986 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
1987 m.tx = (int)(matrix->tx*20);
1988 m.ty = (int)(matrix->ty*20);
1991 int myshapeid = getNewID(dev);
1992 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
1994 swf_ShapeNew(&shape);
1995 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
1996 swf_SetU16(i->tag, myshapeid);
1997 SRECT r = gfxline_getSWFbbox(line);
1998 swf_SetRect(i->tag,&r);
1999 swf_SetShapeStyles(i->tag,shape);
2000 swf_ShapeCountBits(shape,NULL,NULL);
2001 swf_SetShapeBits(i->tag,shape);
2002 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2003 i->swflastx = i->swflasty = UNDEFINED_COORD;
2004 drawgfxline(dev, line);
2005 swf_ShapeSetEnd(i->tag);
2006 swf_ShapeFree(shape);
2008 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2009 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
2010 swf_ObjectPlace(i->tag,myshapeid,getNewDepth(dev),&i->page_matrix,&cxform2,NULL);
2013 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
2015 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2020 if(i->clippos >= 127)
2022 msg("<warning> Too many clip levels.");
2026 int myshapeid = getNewID(dev);
2027 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2029 memset(&col, 0, sizeof(RGBA));
2031 swf_ShapeNew(&shape);
2032 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2033 swf_SetU16(i->tag,myshapeid);
2034 SRECT r = gfxline_getSWFbbox(line);
2035 swf_SetRect(i->tag,&r);
2036 swf_SetShapeStyles(i->tag,shape);
2037 swf_ShapeCountBits(shape,NULL,NULL);
2038 swf_SetShapeBits(i->tag,shape);
2039 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2040 i->swflastx = i->swflasty = UNDEFINED_COORD;
2041 drawgfxline(dev, line);
2042 swf_ShapeSetEnd(i->tag);
2043 swf_ShapeFree(shape);
2045 /* TODO: remember the bbox, and check all shapes against it */
2047 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2048 i->cliptags[i->clippos] = i->tag;
2049 i->clipshapes[i->clippos] = myshapeid;
2050 i->clipdepths[i->clippos] = getNewDepth(dev);
2054 static void swf_endclip(gfxdevice_t*dev)
2056 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2063 msg("<error> Invalid end of clipping region");
2067 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2068 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2070 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2072 static int gfxline_type(gfxline_t*line)
2078 int haszerosegments=0;
2080 if(line->type == gfx_moveTo) {
2083 } else if(line->type == gfx_lineTo) {
2087 } else if(line->type == gfx_splineTo) {
2089 if(tmpsplines>lines)
2094 if(lines==0 && splines==0) return 0;
2095 else if(lines==1 && splines==0) return 1;
2096 else if(lines==0 && splines==1) return 2;
2097 else if(splines==0) return 3;
2101 static int gfxline_has_dots(gfxline_t*line)
2108 if(line->type == gfx_moveTo) {
2109 if(isline && dist < 1) {
2114 } else if(line->type == gfx_lineTo) {
2115 dist += fabs(line->x - x) + fabs(line->y - y);
2117 } else if(line->type == gfx_splineTo) {
2118 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2119 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2126 if(isline && dist < 1) {
2132 static int gfxline_fix_short_edges(gfxline_t*line)
2136 if(line->type == gfx_lineTo) {
2137 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2140 } else if(line->type == gfx_splineTo) {
2141 if(fabs(line->sx - x) + fabs(line->sy - y) +
2142 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2153 static char is_inside_page(gfxdevice_t*dev, gfxcoord_t x, gfxcoord_t y)
2155 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2156 if(x<i->min_x || x>i->max_x) return 0;
2157 if(y<i->min_y || y>i->max_y) return 0;
2161 static void show_path(ArtSVP*path)
2164 printf("Segments: %d\n", path->n_segs);
2165 for(t=0;t<path->n_segs;t++) {
2166 ArtSVPSeg* seg = &path->segs[t];
2167 printf("Segment %d: %d points, %s, BBox: (%f,%f,%f,%f)\n",
2168 t, seg->n_points, seg->dir==0?"UP ":"DOWN",
2169 seg->bbox.x0, seg->bbox.y0, seg->bbox.x1, seg->bbox.y1);
2171 for(p=0;p<seg->n_points;p++) {
2172 ArtPoint* point = &seg->points[p];
2173 printf(" (%f,%f)\n", point->x, point->y);
2179 gfxline_t* gfxline_move(gfxline_t*line, double x, double y)
2181 gfxline_t*l = line = gfxline_clone(line);
2193 //#define NORMALIZE_POLYGON_POSITIONS
2195 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)
2197 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2198 int type = gfxline_type(line);
2199 int has_dots = gfxline_has_dots(line);
2200 gfxbbox_t r = gfxline_getbbox(line);
2201 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2203 /* TODO: * split line into segments, and perform this check for all segments */
2206 (width <= i->config_caplinewidth
2207 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2208 || (cap_style == gfx_capRound && type<=2))) {} else
2210 /* convert line to polygon */
2211 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2213 gfxline_fix_short_edges(line);
2214 /* we need to convert the line into a polygon */
2215 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2216 gfxline_t*gfxline = SVPtogfxline(svp);
2217 dev->fill(dev, gfxline, color);
2223 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2226 #ifdef NORMALIZE_POLYGON_POSITIONS
2228 double startx = 0, starty = 0;
2229 if(line && line->type == gfx_moveTo) {
2233 line = gfxline_move(line, -startx, -starty);
2234 i->shapeposx = (int)(startx*20);
2235 i->shapeposy = (int)(starty*20);
2238 swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a);
2239 swfoutput_setlinewidth(dev, width);
2242 drawgfxline(dev, line);
2244 #ifdef NORMALIZE_POLYGON_POSITIONS
2245 free(line); //account for _move
2249 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2251 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2252 gfxbbox_t r = gfxline_getbbox(line);
2253 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2256 if(!i->config_ignoredraworder)
2259 #ifdef NORMALIZE_POLYGON_POSITIONS
2261 double startx = 0, starty = 0;
2262 if(line && line->type == gfx_moveTo) {
2266 line = gfxline_move(line, -startx, -starty);
2267 i->shapeposx = (int)(startx*20);
2268 i->shapeposy = (int)(starty*20);
2271 swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a);
2275 drawgfxline(dev, line);
2276 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2278 #ifdef NORMALIZE_POLYGON_POSITIONS
2279 free(line); //account for _move
2282 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2284 msg("<error> Gradient filling not implemented yet");
2287 static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
2289 SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
2292 swffont->version = 2;
2293 swffont->name = (U8*)strdup(id);
2294 swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
2295 swffont->layout->ascent = 0; /* ? */
2296 swffont->layout->descent = 0;
2297 swffont->layout->leading = 0;
2298 swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
2299 swffont->encoding = FONT_ENCODING_UNICODE;
2300 swffont->numchars = font->num_glyphs;
2301 swffont->maxascii = font->max_unicode;
2302 swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
2303 swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
2304 swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
2305 swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
2306 for(t=0;t<font->max_unicode;t++) {
2307 swffont->ascii2glyph[t] = font->unicode2glyph[t];
2309 for(t=0;t<font->num_glyphs;t++) {
2312 swffont->glyph2ascii[t] = font->glyphs[t].unicode;
2313 if(font->glyphs[t].name) {
2314 swffont->glyphnames[t] = strdup(font->glyphs[t].name);
2316 swffont->glyphnames[t] = 0;
2318 swffont->glyph[t].advance = (int)(font->glyphs[t].advance * 20);
2320 swf_Shape01DrawerInit(&draw, 0);
2321 line = font->glyphs[t].line;
2324 c.x = line->sx; c.y = line->sy;
2325 to.x = line->x; to.y = line->y;
2326 if(line->type == gfx_moveTo) {
2327 draw.moveTo(&draw, &to);
2328 } else if(line->type == gfx_lineTo) {
2329 draw.lineTo(&draw, &to);
2330 } else if(line->type == gfx_splineTo) {
2331 draw.splineTo(&draw, &c, &to);
2336 swffont->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
2337 swffont->layout->bounds[t] = swf_ShapeDrawerGetBBox(&draw);
2338 draw.dealloc(&draw);
2343 static void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font)
2345 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2347 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2348 return; // the requested font is the current font
2350 fontlist_t*last=0,*l = i->fontlist;
2353 if(!strcmp((char*)l->swffont->name, fontid)) {
2354 return; // we already know this font
2358 l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
2359 l->swffont = gfxfont_to_swffont(font, fontid);
2366 swf_FontSetID(l->swffont, getNewID(i->dev));
2368 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
2370 // print font information
2371 msg("<debug> Font %s",fontid);
2372 msg("<debug> | ID: %d", l->swffont->id);
2373 msg("<debug> | Version: %d", l->swffont->version);
2374 msg("<debug> | Name: %s", l->swffont->name);
2375 msg("<debug> | Numchars: %d", l->swffont->numchars);
2376 msg("<debug> | Maxascii: %d", l->swffont->maxascii);
2377 msg("<debug> | Style: %d", l->swffont->style);
2378 msg("<debug> | Encoding: %d", l->swffont->encoding);
2379 for(iii=0; iii<l->swffont->numchars;iii++) {
2380 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,
2381 l->swffont->layout->bounds[iii].xmin/20.0,
2382 l->swffont->layout->bounds[iii].ymin/20.0,
2383 l->swffont->layout->bounds[iii].xmax/20.0,
2384 l->swffont->layout->bounds[iii].ymax/20.0
2387 for(t=0;t<l->swffont->maxascii;t++) {
2388 if(l->swffont->ascii2glyph[t] == iii)
2389 msg("<debug> | - maps to %d",t);
2395 static void swf_switchfont(gfxdevice_t*dev, char*fontid)
2397 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2399 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2400 return; // the requested font is the current font
2402 fontlist_t*l = i->fontlist;
2404 if(!strcmp((char*)l->swffont->name, fontid)) {
2405 i->swffont = l->swffont;
2410 msg("<error> Unknown font id: %s", fontid);
2414 static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
2416 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2418 if(!i->swffont || !i->swffont->name || strcmp((char*)i->swffont->name,fontid)) // not equal to current font
2420 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
2421 with multiple fonts */
2424 swf_switchfont(dev, fontid); // set the current font
2426 swfoutput_setfontmatrix(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
2436 /* printf("%f %f\n", m.m31, m.m32);
2438 static int xpos = 40;
2439 static int ypos = 200;
2446 drawchar(dev, i->swffont, glyph, &m, color);