2 Implements generation of swf files using the rfxswf lib. The routines
3 in this file are called from pdf2swf.
5 This file is part of swftools.
7 Swftools is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Swftools is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with swftools; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "../config.h"
33 #include "swfoutput.h"
36 #include "../lib/log.h"
37 #include "../lib/rfxswf.h"
38 #include "../lib/gfxdevice.h"
39 #include "../lib/gfxtools.h"
41 #include "../lib/art/libart.h"
43 #define CHARDATAMAX 8192
47 typedef struct _chardata {
49 int fontid; /* TODO: use a SWFFONT instead */
62 typedef long int twip;
65 double m11,m12,m21,m22,m31,m32;
68 typedef struct _swfoutput_internal
70 gfxdevice_t*dev; // the gfxdevice object where this internal struct resides
72 double config_dumpfonts;
73 double config_ppmsubpixels;
74 double config_jpegsubpixels;
75 int config_opennewwindow;
76 int config_ignoredraworder;
77 int config_drawonlyshapes;
78 int config_jpegquality;
79 int config_storeallcharacters;
80 int config_generate_fake_tags;
81 int config_enablezlib;
82 int config_insertstoptag;
83 int config_flashversion;
84 int config_splinemaxerror;
85 int config_fontsplinemaxerror;
86 int config_filloverlap;
89 float config_minlinewidth;
90 double config_caplinewidth;
91 char* config_linktarget;
130 int pic_height[1024];
136 char fillstylechanged;
138 int jpeg; //next image type
143 chardata_t chardata[CHARDATAMAX];
151 double fontm11,fontm12,fontm21,fontm22;
160 } swfoutput_internal;
162 static void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
163 static int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
164 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);
165 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
166 static void swf_endclip(gfxdevice_t*dev);
167 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);
168 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
169 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
170 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
171 static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
172 static void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font);
173 static void swf_drawlink(gfxdevice_t*dev, gfxline_t*line, char*action);
174 static void swf_startframe(gfxdevice_t*dev, int width, int height);
175 static void swf_endframe(gfxdevice_t*dev);
176 static gfxresult_t* swf_finish(gfxdevice_t*driver);
178 static swfoutput_internal* init_internal_struct()
180 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
181 memset(i, 0, sizeof(swfoutput_internal));
203 i->fillstylechanged = 0;
210 i->config_dumpfonts=0;
211 i->config_ppmsubpixels=0;
212 i->config_jpegsubpixels=0;
213 i->config_opennewwindow=1;
214 i->config_ignoredraworder=0;
215 i->config_drawonlyshapes=0;
216 i->config_jpegquality=85;
217 i->config_storeallcharacters=0;
218 i->config_enablezlib=0;
219 i->config_generate_fake_tags=0;
220 i->config_insertstoptag=0;
221 i->config_flashversion=6;
222 i->config_splinemaxerror=1;
223 i->config_fontsplinemaxerror=1;
224 i->config_filloverlap=0;
226 i->config_bboxvars=0;
227 i->config_minlinewidth=0.05;
228 i->config_caplinewidth=1;
229 i->config_linktarget=0;
234 static int id_error = 0;
236 static U16 getNewID(gfxdevice_t* dev)
238 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
239 if(i->currentswfid == 65535) {
241 msg("<error> ID Table overflow");
245 return ++i->currentswfid;
247 static U16 getNewDepth(gfxdevice_t* dev)
249 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
250 if(i->depth == 65535) {
252 msg("<error> Depth Table overflow");
259 static void startshape(gfxdevice_t* dev);
260 static void starttext(gfxdevice_t* dev);
261 static void endshape(gfxdevice_t* dev);
262 static void endtext(gfxdevice_t* dev);
264 // write a move-to command into the swf
265 static int moveto(gfxdevice_t*dev, TAG*tag, plotxy p0)
267 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
268 int rx = (int)(p0.x*20);
269 int ry = (int)(p0.y*20);
270 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
271 swf_ShapeSetMove (tag, i->shape, rx,ry);
272 i->fillstylechanged = 0;
279 static int moveto(gfxdevice_t*dev, TAG*tag, double x, double y)
281 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
285 return moveto(dev, tag, p);
287 static void addPointToBBox(gfxdevice_t*dev, int px, int py)
289 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
295 swf_ExpandRect(&i->bboxrect, p);
297 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
301 /*static void plot(gfxdevice_t*dev, int x, int y, TAG*tag)
303 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
304 int width = i->linewidth/4;
308 //swf_ShapeSetLine(tag, i->shape,-width,-width);
309 //swf_ShapeSetLine(tag, i->shape,width*2,0);
310 //swf_ShapeSetLine(tag, i->shape,0,width*2);
311 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
312 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
313 //swf_ShapeSetLine(tag, i->shape,width,width);
316 swf_ShapeSetLine(tag, i->shape,-width,0);
317 swf_ShapeSetLine(tag, i->shape,width,-width);
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,0);
323 addPointToBBox(dev, x-width ,y-width);
324 addPointToBBox(dev, x+width ,y+width);
327 // write a line-to command into the swf
328 static void lineto(gfxdevice_t*dev, TAG*tag, plotxy p0)
330 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
331 int px = (int)(p0.x*20);
332 int py = (int)(p0.y*20);
333 int rx = (px-i->swflastx);
334 int ry = (py-i->swflasty);
336 swf_ShapeSetLine (tag, i->shape, rx,ry);
337 addPointToBBox(dev, i->swflastx,i->swflasty);
338 addPointToBBox(dev, px,py);
339 }/* else if(!i->fill) {
340 // treat lines of length 0 as plots, making them
341 // at least 1 twip wide so Flash will display them
342 plot(dev, i->swflastx, i->swflasty, tag);
349 static void lineto(gfxdevice_t*dev, TAG*tag, double x, double y)
357 // write a spline-to command into the swf
358 static void splineto(gfxdevice_t*dev, TAG*tag, plotxy control,plotxy end)
360 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
361 int lastlastx = i->swflastx;
362 int lastlasty = i->swflasty;
364 int cx = ((int)(control.x*20)-i->swflastx);
365 int cy = ((int)(control.y*20)-i->swflasty);
368 int ex = ((int)(end.x*20)-i->swflastx);
369 int ey = ((int)(end.y*20)-i->swflasty);
373 if(cx || cy || ex || ey) {
374 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
375 addPointToBBox(dev, lastlastx ,lastlasty );
376 addPointToBBox(dev, lastlastx+cx,lastlasty+cy);
377 addPointToBBox(dev, lastlastx+cx+ex,lastlasty+cy+ey);
378 }/* else if(!i->fill) {
379 // treat splines of length 0 as plots
380 plot(dev, lastlastx, lastlasty, tag);
385 /* write a line, given two points and the transformation
387 /*static void line(gfxdevice_t*dev, TAG*tag, plotxy p0, plotxy p1)
389 moveto(dev, tag, p0);
390 lineto(dev, tag, p1);
393 void resetdrawer(gfxdevice_t*dev)
395 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
400 static void stopFill(gfxdevice_t*dev)
402 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
405 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
406 i->fillstylechanged = 1;
410 static void startFill(gfxdevice_t*dev)
412 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
415 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
416 i->fillstylechanged = 1;
421 static inline int colorcompare(gfxdevice_t*dev, RGBA*a,RGBA*b)
433 static SRECT getcharacterbbox(gfxdevice_t*dev, SWFFONT*font, MATRIX* m)
435 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
438 memset(&r, 0, sizeof(r));
441 if(debug) printf("\n");
442 for(t=0;t<i->chardatapos;t++)
444 if(i->chardata[t].fontid != font->id) {
445 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
448 SRECT b = font->layout->bounds[i->chardata[t].charid];
449 b.xmin *= i->chardata[t].size;
450 b.ymin *= i->chardata[t].size;
451 b.xmax *= i->chardata[t].size;
452 b.ymax *= i->chardata[t].size;
454 /* divide by 1024, rounding xmax/ymax up */
455 b.xmax += 1023; b.ymax += 1023; b.xmin /= 1024; b.ymin /= 1024; b.xmax /= 1024; b.ymax /= 1024;
457 b.xmin += i->chardata[t].x;
458 b.ymin += i->chardata[t].y;
459 b.xmax += i->chardata[t].x;
460 b.ymax += i->chardata[t].y;
462 /* until we solve the INTERNAL_SCALING problem (see below)
463 make sure the bounding box is big enough */
469 b = swf_TurnRect(b, m);
471 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
472 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
473 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
474 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
475 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
480 i->chardata[t].fontid,
482 i->chardata[t].charid
484 swf_ExpandRect2(&r, &b);
486 if(debug) printf("-----> (%f,%f,%f,%f)\n",
494 static void putcharacters(gfxdevice_t*dev, TAG*tag)
496 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
500 color.r = i->chardata[0].color.r^255;
509 int charadvance[128];
512 int glyphbits=1; //TODO: can this be zero?
515 if(tag->id != ST_DEFINETEXT &&
516 tag->id != ST_DEFINETEXT2) {
517 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
520 if(!i->chardatapos) {
521 msg("<warning> putcharacters called with zero characters");
524 for(pass = 0; pass < 2; pass++)
534 advancebits++; // add sign bit
535 swf_SetU8(tag, glyphbits);
536 swf_SetU8(tag, advancebits);
539 for(t=0;t<=i->chardatapos;t++)
541 if(lastfontid != i->chardata[t].fontid ||
542 lastx!=i->chardata[t].x ||
543 lasty!=i->chardata[t].y ||
544 !colorcompare(dev,&color, &i->chardata[t].color) ||
546 lastsize != i->chardata[t].size ||
549 if(charstorepos && pass==0)
552 for(s=0;s<charstorepos;s++)
554 while(charids[s]>=(1<<glyphbits))
556 while(charadvance[s]>=(1<<advancebits))
560 if(charstorepos && pass==1)
562 tag->writeBit = 0; // Q&D
563 swf_SetBits(tag, 0, 1); // GLYPH Record
564 swf_SetBits(tag, charstorepos, 7); // number of glyphs
566 for(s=0;s<charstorepos;s++)
568 swf_SetBits(tag, charids[s], glyphbits);
569 swf_SetBits(tag, charadvance[s], advancebits);
574 if(pass == 1 && t<i->chardatapos)
580 if(lastx != i->chardata[t].x ||
581 lasty != i->chardata[t].y)
583 newx = i->chardata[t].x;
584 newy = i->chardata[t].y;
590 if(!colorcompare(dev,&color, &i->chardata[t].color))
592 color = i->chardata[t].color;
595 font.id = i->chardata[t].fontid;
596 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
599 tag->writeBit = 0; // Q&D
600 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
603 lastfontid = i->chardata[t].fontid;
604 lastx = i->chardata[t].x;
605 lasty = i->chardata[t].y;
606 lastsize = i->chardata[t].size;
609 if(t==i->chardatapos)
613 int nextt = t==i->chardatapos-1?t:t+1;
614 int rel = i->chardata[nextt].x-i->chardata[t].x;
615 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
617 lastx=i->chardata[nextt].x;
621 lastx=i->chardata[t].x;
623 charids[charstorepos] = i->chardata[t].charid;
624 charadvance[charstorepos] = advance;
631 static void putcharacter(gfxdevice_t*dev, int fontid, int charid, int x,int y, int size, RGBA color)
633 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
634 if(i->chardatapos == CHARDATAMAX)
636 msg("<warning> Character buffer too small. SWF will be slightly bigger");
640 i->chardata[i->chardatapos].fontid = fontid;
641 i->chardata[i->chardatapos].charid = charid;
642 i->chardata[i->chardatapos].x = x;
643 i->chardata[i->chardatapos].y = y;
644 i->chardata[i->chardatapos].color = color;
645 i->chardata[i->chardatapos].size = size;
649 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
650 So if we set this value to high, the char coordinates will overflow.
651 If we set it to low, however, the char positions will be inaccurate */
652 #define FONT_INTERNAL_SIZE 4
654 /* process a character. */
655 static int drawchar(gfxdevice_t*dev, SWFFONT *swffont, int charid, swfmatrix*m, gfxcolor_t*col)
657 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
659 msg("<warning> Font is NULL");
663 if(charid<0 || charid>=swffont->numchars) {
664 msg("<warning> No character %d in font %s ", charid, FIXNULL((char*)swffont->name));
667 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
668 msg("<warning> Glyph %d in current charset (%s, %d characters) is empty",
669 charid, FIXNULL((char*)swffont->name), swffont->numchars);
680 float det = ((m->m11*m->m22)-(m->m21*m->m12));
681 if(fabs(det) < 0.0005) {
682 /* x direction equals y direction- the text is invisible */
685 det = 20*FONT_INTERNAL_SIZE / det;
688 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
689 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
691 RGBA rgba = *(RGBA*)col;
692 putcharacter(dev, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
693 swf_FontUseGlyph(swffont, charid);
697 static void endtext(gfxdevice_t*dev)
699 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
703 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
704 swf_SetU16(i->tag, i->textid);
707 r = getcharacterbbox(dev, i->swffont, &i->fontmatrix);
709 swf_SetRect(i->tag,&r);
711 swf_SetMatrix(i->tag,&i->fontmatrix);
713 msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
715 putcharacters(dev, i->tag);
717 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
719 swf_ObjectPlace(i->tag,i->textid,getNewDepth(dev),&i->page_matrix,NULL,NULL);
723 /* set's the matrix which is to be applied to characters drawn by swfoutput_drawchar() */
724 static void swfoutput_setfontmatrix(gfxdevice_t*dev,double m11,double m21,
725 double m12,double m22)
731 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
732 if(i->fontm11 == m11 &&
745 m.sx = (U32)(((i->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((i->fontm12)*65536)/FONT_INTERNAL_SIZE);
746 m.r0 = (U32)(((i->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((i->fontm22)*65536)/FONT_INTERNAL_SIZE);
752 static void endpage(gfxdevice_t*dev)
754 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
764 void swf_startframe(gfxdevice_t*dev, int width, int height)
766 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
767 if(!i->firstpage && !i->pagefinished)
769 msg("<verbose> Starting new SWF page of size %dx%d", width, height);
771 swf_GetMatrix(0, &i->page_matrix);
772 i->page_matrix.tx = 0;
773 i->page_matrix.ty = 0;
779 /* set clipping/background rectangle */
780 /* TODO: this should all be done in SWFOutputDev */
781 //setBackground(dev, x1, y1, x2, y2);
783 /* increase SWF's bounding box */
789 swf_ExpandRect2(&i->swf->movieSize, &r);
791 i->lastframeno = i->frameno;
796 void swf_endframe(gfxdevice_t*dev)
798 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
803 if(i->config_insertstoptag) {
805 atag = action_Stop(atag);
806 atag = action_End(atag);
807 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
808 swf_ActionSet(i->tag,atag);
810 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
813 for(i->depth;i->depth>i->startdepth;i->depth--) {
814 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
815 swf_SetU16(i->tag,i->depth);
817 i->depth = i->startdepth;
820 static void setBackground(gfxdevice_t*dev, int x1, int y1, int x2, int y2)
822 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
824 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
828 int shapeid = getNewID(dev);
833 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
835 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
836 swf_SetU16(i->tag,shapeid);
837 swf_SetRect(i->tag,&r);
838 swf_SetShapeHeader(i->tag,s);
839 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
840 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
841 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
842 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
843 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
844 swf_ShapeSetEnd(i->tag);
846 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
847 swf_ObjectPlace(i->tag,shapeid,getNewDepth(dev),0,0,0);
848 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
849 swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(dev),0,0,0,65535);
852 /* initialize the swf writer */
853 void gfxdevice_swf_init(gfxdevice_t* dev)
855 memset(dev, 0, sizeof(gfxdevice_t));
856 dev->internal = init_internal_struct();
858 dev->startpage = swf_startframe;
859 dev->endpage = swf_endframe;
860 dev->finish = swf_finish;
861 dev->fillbitmap = swf_fillbitmap;
862 dev->setparameter = swf_setparameter;
863 dev->stroke = swf_stroke;
864 dev->startclip = swf_startclip;
865 dev->endclip = swf_endclip;
866 dev->fill = swf_fill;
867 dev->fillbitmap = swf_fillbitmap;
868 dev->fillgradient = swf_fillgradient;
869 dev->addfont = swf_addfont;
870 dev->drawchar = swf_drawchar;
871 dev->drawlink = swf_drawlink;
873 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
879 msg("<verbose> initializing swf output\n", i->max_x,i->max_y);
883 i->swf = (SWF*)rfx_calloc(sizeof(SWF));
884 i->swf->fileVersion = i->config_flashversion;
885 i->swf->frameRate = 0x0040; // 1 frame per 4 seconds
886 i->swf->movieSize.xmin = 0;
887 i->swf->movieSize.ymin = 0;
888 i->swf->movieSize.xmax = 0;
889 i->swf->movieSize.ymax = 0;
891 i->swf->firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
892 i->tag = i->swf->firstTag;
893 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
894 swf_SetRGB(i->tag,&rgb);
896 i->startdepth = i->depth = 0;
898 if(i->config_protect)
899 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
902 static void startshape(gfxdevice_t*dev)
904 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
913 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
915 swf_ShapeNew(&i->shape);
916 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&i->strokergb);
917 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&i->fillrgb);
919 i->shapeid = getNewID(dev);
921 msg("<debug> Using shape id %d", i->shapeid);
923 swf_SetU16(i->tag,i->shapeid); // ID
925 i->bboxrectpos = i->tag->len;
929 r.xmax = 20*i->max_x;
930 r.ymax = 20*i->max_y;
931 swf_SetRect(i->tag,&r);
933 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
935 swf_SetShapeStyles(i->tag,i->shape);
936 swf_ShapeCountBits(i->shape,NULL,NULL);
937 swf_SetShapeBits(i->tag,i->shape);
939 /* TODO: do we really need this? */
940 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
941 i->swflastx=i->swflasty=0;
946 static void starttext(gfxdevice_t*dev)
948 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
952 i->textid = getNewID(dev);
954 i->swflastx=i->swflasty=0;
958 /* TODO: move to ../lib/rfxswf */
959 void changeRect(gfxdevice_t*dev, TAG*tag, int pos, SRECT*newrect)
961 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
962 /* determine length of old rect */
966 swf_GetRect(tag, &old);
967 swf_ResetReadBits(tag);
968 int pos_end = tag->pos;
970 int len = tag->len - pos_end;
971 U8*data = (U8*)malloc(len);
972 memcpy(data, &tag->data[pos_end], len);
975 swf_SetRect(tag, newrect);
976 swf_SetBlock(tag, data, len);
978 tag->pos = tag->readBit = 0;
981 void cancelshape(gfxdevice_t*dev)
983 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
984 /* delete old shape tag */
986 i->tag = i->tag->prev;
987 swf_DeleteTag(todel);
988 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
993 void fixAreas(gfxdevice_t*dev)
995 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
996 if(!i->shapeisempty && i->fill &&
997 (i->bboxrect.xmin == i->bboxrect.xmax ||
998 i->bboxrect.ymin == i->bboxrect.ymax) &&
999 i->config_minlinewidth >= 0.001
1001 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1002 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1003 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1006 SRECT r = i->bboxrect;
1008 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1009 /* this thing comes down to a single dot- nothing to fix here */
1015 RGBA save_col = i->strokergb;
1016 int save_width = i->linewidth;
1018 i->strokergb = i->fillrgb;
1019 i->linewidth = (int)(i->config_minlinewidth*20);
1020 if(i->linewidth==0) i->linewidth = 1;
1024 moveto(dev, i->tag, r.xmin/20.0,r.ymin/20.0);
1025 lineto(dev, i->tag, r.xmax/20.0,r.ymax/20.0);
1027 i->strokergb = save_col;
1028 i->linewidth = save_width;
1033 static void endshape_noput(gfxdevice_t*dev)
1035 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1038 //changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1041 swf_ShapeFree(i->shape);
1049 static void endshape(gfxdevice_t*dev)
1051 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1057 if(i->shapeisempty ||
1059 (i->bboxrect.xmin == i->bboxrect.xmax &&
1060 i->bboxrect.ymin == i->bboxrect.ymax))
1062 // delete the shape again, we didn't do anything
1063 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1064 i->bboxrect.xmin /20.0,
1065 i->bboxrect.ymin /20.0,
1066 i->bboxrect.xmax /20.0,
1067 i->bboxrect.ymax /20.0
1073 swf_ShapeSetEnd(i->tag);
1075 changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1077 msg("<trace> Placing shape id %d", i->shapeid);
1079 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1080 MATRIX m = i->page_matrix;
1081 m.tx += i->shapeposx;
1082 m.ty += i->shapeposy;
1083 swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(dev),&m,NULL,NULL);
1085 swf_ShapeFree(i->shape);
1088 i->bboxrectpos = -1;
1095 void wipeSWF(SWF*swf)
1097 TAG*tag = swf->firstTag;
1099 TAG*next = tag->next;
1100 if(tag->id != ST_SETBACKGROUNDCOLOR &&
1101 tag->id != ST_END &&
1102 tag->id != ST_DOACTION &&
1103 tag->id != ST_SHOWFRAME) {
1111 void swfoutput_finalize(gfxdevice_t*dev)
1113 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1115 if(i->tag && i->tag->id == ST_END)
1116 return; //already done
1118 if(i->config_bboxvars) {
1119 TAG* tag = swf_InsertTag(i->swf->firstTag, ST_DOACTION);
1121 a = action_PushString(a, "xmin");
1122 a = action_PushFloat(a, i->swf->movieSize.xmin / 20.0);
1123 a = action_SetVariable(a);
1124 a = action_PushString(a, "ymin");
1125 a = action_PushFloat(a, i->swf->movieSize.ymin / 20.0);
1126 a = action_SetVariable(a);
1127 a = action_PushString(a, "xmax");
1128 a = action_PushFloat(a, i->swf->movieSize.xmax / 20.0);
1129 a = action_SetVariable(a);
1130 a = action_PushString(a, "ymax");
1131 a = action_PushFloat(a, i->swf->movieSize.ymax / 20.0);
1132 a = action_SetVariable(a);
1133 a = action_PushString(a, "width");
1134 a = action_PushFloat(a, (i->swf->movieSize.xmax - i->swf->movieSize.xmin) / 20.0);
1135 a = action_SetVariable(a);
1136 a = action_PushString(a, "height");
1137 a = action_PushFloat(a, (i->swf->movieSize.ymax - i->swf->movieSize.ymin) / 20.0);
1138 a = action_SetVariable(a);
1140 swf_ActionSet(tag, a);
1144 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1148 fontlist_t *tmp,*iterator = i->fontlist;
1150 TAG*mtag = i->swf->firstTag;
1151 if(iterator->swffont) {
1152 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1153 if(!i->config_storeallcharacters) {
1154 msg("<debug> Reducing font %s", iterator->swffont->name);
1155 swf_FontReduce(iterator->swffont);
1157 swf_FontSetDefine2(mtag, iterator->swffont);
1160 iterator = iterator->next;
1162 i->tag = swf_InsertTag(i->tag,ST_END);
1163 TAG* tag = i->tag->prev;
1165 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1166 and the ST_END- they confuse the flash player */
1167 while(tag->id == ST_REMOVEOBJECT2) {
1168 TAG* prev = tag->prev;
1176 if(i->config_enablezlib || i->config_flashversion>=6) {
1177 i->swf->compressed = 1;
1181 int swfresult_save(gfxresult_t*gfx, char*filename)
1183 SWF*swf = (SWF*)gfx->internal;
1186 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1191 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1195 if(swf->compressed) {
1196 if FAILED(swf_WriteSWC(fi,swf))
1197 msg("<error> WriteSWC() failed.\n");
1199 if FAILED(swf_WriteSWF(fi,swf))
1200 msg("<error> WriteSWF() failed.\n");
1207 void* swfresult_get(gfxresult_t*gfx, char*name)
1209 SWF*swf = (SWF*)gfx->internal;
1210 if(!strcmp(name, "swf")) {
1211 return (void*)swf_CopySWF(swf);
1212 } else if(!strcmp(name, "xmin")) {
1213 return (void*)(swf->movieSize.xmin/20);
1214 } else if(!strcmp(name, "ymin")) {
1215 return (void*)(swf->movieSize.ymin/20);
1216 } else if(!strcmp(name, "xmax")) {
1217 return (void*)(swf->movieSize.xmax/20);
1218 } else if(!strcmp(name, "ymax")) {
1219 return (void*)(swf->movieSize.ymax/20);
1220 } else if(!strcmp(name, "width")) {
1221 return (void*)((swf->movieSize.xmax - swf->movieSize.xmin)/20);
1222 } else if(!strcmp(name, "height")) {
1223 return (void*)((swf->movieSize.ymax - swf->movieSize.ymin)/20);
1227 void swfresult_destroy(gfxresult_t*gfx)
1230 swf_FreeTags((SWF*)gfx->internal);
1231 free(gfx->internal);
1234 memset(gfx, 0, sizeof(gfxresult_t));
1238 static void swfoutput_destroy(gfxdevice_t* dev);
1240 gfxresult_t* swf_finish(gfxdevice_t* dev)
1242 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1245 if(i->config_linktarget) {
1246 free(i->config_linktarget);
1247 i->config_linktarget = 0;
1250 swfoutput_finalize(dev);
1251 SWF* swf = i->swf;i->swf = 0;
1252 swfoutput_destroy(dev);
1254 result = (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t));
1255 result->internal = swf;
1256 result->save = swfresult_save;
1258 result->get = swfresult_get;
1259 result->destroy = swfresult_destroy;
1263 /* Perform cleaning up */
1264 static void swfoutput_destroy(gfxdevice_t* dev)
1266 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1268 /* not initialized yet- nothing to destroy */
1272 fontlist_t *tmp,*iterator = i->fontlist;
1274 if(iterator->swffont) {
1275 swf_FontFree(iterator->swffont);iterator->swffont=0;
1278 iterator = iterator->next;
1281 if(i->swf) {swf_FreeTags(i->swf);free(i->swf);i->swf = 0;}
1284 memset(dev, 0, sizeof(gfxdevice_t));
1287 static void swfoutput_setfillcolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1289 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1290 if(i->fillrgb.r == r &&
1291 i->fillrgb.g == g &&
1292 i->fillrgb.b == b &&
1293 i->fillrgb.a == a) return;
1303 static void swfoutput_setstrokecolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1305 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1306 if(i->strokergb.r == r &&
1307 i->strokergb.g == g &&
1308 i->strokergb.b == b &&
1309 i->strokergb.a == a) return;
1319 //#define ROUND_UP 19
1320 //#define ROUND_UP 10
1322 static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth)
1324 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1325 if(i->linewidth == (U16)(_linewidth*20+19.0/20.0))
1329 i->linewidth = (U16)(_linewidth*20+19.0/20.0);
1333 static void drawlink(gfxdevice_t*dev, ActionTAG*,ActionTAG*, gfxline_t*points, char mouseover);
1334 static void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points);
1335 static void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points);
1336 static void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points);
1338 void swfoutput_drawlink(gfxdevice_t*dev, char*url, gfxline_t*points)
1340 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1341 dev->drawlink(dev, points, url);
1344 void swf_drawlink(gfxdevice_t*dev, gfxline_t*points, char*url)
1346 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1348 if(!strncmp("http://pdf2swf:", url, 15)) {
1349 char*tmp = strdup(url);
1350 int l = strlen(tmp);
1353 swfoutput_namedlink(dev, tmp+15, points);
1356 } else if(!strncmp("page", url, 4)) {
1359 if(url[t]<'0' || url[t]>'9')
1362 int page = atoi(&url[4]) - 1;
1363 if(page<0) page = 0;
1364 swfoutput_linktopage(dev, page, points);
1367 swfoutput_linktourl(dev, url, points);
1370 void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points)
1373 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1379 if(!i->config_linktarget) {
1380 if(!i->config_opennewwindow)
1381 actions = action_GetUrl(0, url, "_parent");
1383 actions = action_GetUrl(0, url, "_this");
1385 actions = action_GetUrl(0, url, i->config_linktarget);
1387 actions = action_End(actions);
1389 drawlink(dev, actions, 0, points,0);
1391 void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points)
1393 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1401 actions = action_GotoFrame(0, page);
1402 actions = action_End(actions);
1404 drawlink(dev, actions, 0, points,0);
1407 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1408 of the viewer objects, like subtitles, index elements etc.
1410 void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points)
1412 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1413 ActionTAG *actions1,*actions2;
1414 char*tmp = strdup(name);
1422 if(!strncmp(tmp, "call:", 5))
1424 char*x = strchr(&tmp[5], ':');
1426 actions1 = action_PushInt(0, 0); //number of parameters (0)
1427 actions1 = action_PushString(actions1, &tmp[5]); //function name
1428 actions1 = action_CallFunction(actions1);
1431 actions1 = action_PushString(0, x+1); //parameter
1432 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1433 actions1 = action_PushString(actions1, &tmp[5]); //function name
1434 actions1 = action_CallFunction(actions1);
1436 actions2 = action_End(0);
1441 actions1 = action_PushString(0, "/:subtitle");
1442 actions1 = action_PushString(actions1, name);
1443 actions1 = action_SetVariable(actions1);
1444 actions1 = action_End(actions1);
1446 actions2 = action_PushString(0, "/:subtitle");
1447 actions2 = action_PushString(actions2, "");
1448 actions2 = action_SetVariable(actions2);
1449 actions2 = action_End(actions2);
1452 drawlink(dev, actions1, actions2, points,mouseover);
1454 swf_ActionFree(actions1);
1455 swf_ActionFree(actions2);
1459 static void drawgfxline(gfxdevice_t*dev, gfxline_t*line)
1461 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1462 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1467 /* check whether the next segment is zero */
1468 if(line->type == gfx_moveTo) {
1469 msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
1470 moveto(dev, i->tag, line->x, line->y);
1471 px = lastx = line->x;
1472 py = lasty = line->y;
1474 } if(line->type == gfx_lineTo) {
1475 msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
1476 lineto(dev, i->tag, line->x, line->y);
1480 } else if(line->type == gfx_splineTo) {
1481 msg("<trace> ======== splineTo %.2f %.2f", line->x, line->y);
1483 s.x = line->sx;p.x = line->x;
1484 s.y = line->sy;p.y = line->y;
1485 splineto(dev, i->tag, s, p);
1495 static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gfxline_t*points, char mouseover)
1497 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1502 struct plotxy p1,p2,p3,p4;
1508 int buttonid = getNewID(dev);
1509 gfxbbox_t bbox = gfxline_getbbox(points);
1512 myshapeid = getNewID(dev);
1513 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1514 swf_ShapeNew(&i->shape);
1515 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1516 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1517 swf_SetU16(i->tag, myshapeid);
1518 r.xmin = (int)(bbox.xmin*20);
1519 r.ymin = (int)(bbox.ymin*20);
1520 r.xmax = (int)(bbox.xmax*20);
1521 r.ymax = (int)(bbox.ymax*20);
1522 swf_SetRect(i->tag,&r);
1523 swf_SetShapeStyles(i->tag,i->shape);
1524 swf_ShapeCountBits(i->shape,NULL,NULL);
1525 swf_SetShapeBits(i->tag,i->shape);
1526 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1527 i->swflastx = i->swflasty = 0;
1528 drawgfxline(dev, points);
1529 swf_ShapeSetEnd(i->tag);
1532 myshapeid2 = getNewID(dev);
1533 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1534 swf_ShapeNew(&i->shape);
1535 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1537 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1538 swf_SetU16(i->tag, myshapeid2);
1539 r.xmin = (int)(bbox.xmin*20);
1540 r.ymin = (int)(bbox.ymin*20);
1541 r.xmax = (int)(bbox.xmax*20);
1542 r.ymax = (int)(bbox.ymax*20);
1543 swf_SetRect(i->tag,&r);
1544 swf_SetShapeStyles(i->tag,i->shape);
1545 swf_ShapeCountBits(i->shape,NULL,NULL);
1546 swf_SetShapeBits(i->tag,i->shape);
1547 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1548 i->swflastx = i->swflasty = 0;
1549 drawgfxline(dev, points);
1550 swf_ShapeSetEnd(i->tag);
1554 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1555 swf_SetU16(i->tag,buttonid); //id
1556 swf_ButtonSetFlags(i->tag, 0); //menu=no
1557 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1558 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1559 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1560 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1561 swf_SetU8(i->tag,0);
1562 swf_ActionSet(i->tag,actions1);
1563 swf_SetU8(i->tag,0);
1567 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1568 swf_SetU16(i->tag,buttonid); //id
1569 swf_ButtonSetFlags(i->tag, 0); //menu=no
1570 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1571 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1572 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1573 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1574 swf_SetU8(i->tag,0); // end of button records
1575 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1576 swf_ActionSet(i->tag,actions1);
1578 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1579 swf_ActionSet(i->tag,actions2);
1580 swf_SetU8(i->tag,0);
1581 swf_ButtonPostProcess(i->tag, 2);
1583 swf_SetU8(i->tag,0);
1584 swf_ButtonPostProcess(i->tag, 1);
1588 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1590 if(posx!=0 || posy!=0) {
1592 p.x = (int)(posx*20);
1593 p.y = (int)(posy*20);
1594 p = swf_TurnPoint(p, &i->page_matrix);
1599 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&m,0,0);
1601 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&i->page_matrix,0,0);
1608 for(t=0;t<picpos;t++)
1610 if(pic_xids[t] == xid &&
1611 pic_yids[t] == yid) {
1612 width = pic_width[t];
1613 height = pic_height[t];
1617 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1618 pic_xids[picpos] = xid;
1619 pic_yids[picpos] = yid;
1620 pic_width[picpos] = width;
1621 pic_height[picpos] = height;
1624 pic[width*y+x] = buf[0];
1628 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1629 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1633 xid += x*r+x*b*3+x*g*7+x*a*11;
1634 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1636 for(t=0;t<picpos;t++)
1638 if(pic_xids[t] == xid &&
1639 pic_yids[t] == yid) {
1648 int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
1650 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1652 if(!strcmp(name, "jpegsubpixels")) {
1653 i->config_jpegsubpixels = atof(value);
1654 } else if(!strcmp(name, "ppmsubpixels")) {
1655 i->config_ppmsubpixels = atof(value);
1656 } else if(!strcmp(name, "drawonlyshapes")) {
1657 i->config_drawonlyshapes = atoi(value);
1658 } else if(!strcmp(name, "ignoredraworder")) {
1659 i->config_ignoredraworder = atoi(value);
1660 } else if(!strcmp(name, "filloverlap")) {
1661 i->config_filloverlap = atoi(value);
1662 } else if(!strcmp(name, "linksopennewwindow")) {
1663 i->config_opennewwindow = atoi(value);
1664 } else if(!strcmp(name, "opennewwindow")) {
1665 i->config_opennewwindow = atoi(value);
1666 } else if(!strcmp(name, "storeallcharacters")) {
1667 i->config_storeallcharacters = atoi(value);
1668 } else if(!strcmp(name, "enablezlib")) {
1669 i->config_enablezlib = atoi(value);
1670 } else if(!strcmp(name, "bboxvars")) {
1671 i->config_bboxvars = atoi(value);
1672 } else if(!strcmp(name, "insertstop")) {
1673 i->config_insertstoptag = atoi(value);
1674 } else if(!strcmp(name, "protect")) {
1675 i->config_protect = atoi(value);
1676 if(i->config_protect && i->tag) {
1677 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1679 } else if(!strcmp(name, "faketags")) {
1680 i->config_generate_fake_tags = atoi(value);
1681 } else if(!strcmp(name, "flashversion")) {
1682 i->config_flashversion = atoi(value);
1684 i->swf->fileVersion = i->config_flashversion;
1686 } else if(!strcmp(name, "minlinewidth")) {
1687 i->config_minlinewidth = atof(value);
1688 } else if(!strcmp(name, "caplinewidth")) {
1689 i->config_caplinewidth = atof(value);
1690 } else if(!strcmp(name, "linktarget")) {
1691 i->config_linktarget = strdup(value);
1692 } else if(!strcmp(name, "dumpfonts")) {
1693 i->config_dumpfonts = atoi(value);
1694 } else if(!strcmp(name, "next_bitmap_is_jpeg")) {
1696 } else if(!strcmp(name, "jpegquality")) {
1697 int val = atoi(value);
1699 if(val>100) val=100;
1700 i->config_jpegquality = val;
1701 } else if(!strcmp(name, "splinequality")) {
1702 int v = atoi(value);
1703 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1705 i->config_splinemaxerror = v;
1706 } else if(!strcmp(name, "fontquality")) {
1707 int v = atoi(value);
1708 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1710 i->config_fontsplinemaxerror = v;
1712 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1718 // --------------------------------------------------------------------
1720 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
1723 swf_GetCXForm(0, &cx, 1);
1726 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
1727 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
1728 c->br!=0 || c->bg!=0 || c->ba!=0 ||
1729 c->ar!=0 || c->ag!=0 || c->ab!=0)
1730 msg("<warning> CXForm not SWF-compatible");
1732 cx.a0 = (S16)(c->aa*256);
1733 cx.r0 = (S16)(c->rr*256);
1734 cx.g0 = (S16)(c->gg*256);
1735 cx.b0 = (S16)(c->bb*256);
1743 static ArtVpath* gfxline_to_ArtVpath(gfxline_t*line)
1745 ArtVpath *vec = NULL;
1750 /* factor which determines into how many line fragments a spline is converted */
1751 double subfraction = 2.4;//0.3
1755 if(l2->type == gfx_moveTo) {
1757 } if(l2->type == gfx_lineTo) {
1759 } if(l2->type == gfx_splineTo) {
1760 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))*subfraction);
1761 if(!parts) parts = 1;
1771 vec = art_new (ArtVpath, len);
1776 if(l2->type == gfx_moveTo) {
1777 vec[pos].code = ART_MOVETO;
1782 } else if(l2->type == gfx_lineTo) {
1783 vec[pos].code = ART_LINETO;
1788 } else if(l2->type == gfx_splineTo) {
1790 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))*subfraction);
1791 if(!parts) parts = 1;
1792 for(i=0;i<=parts;i++) {
1793 double t = (double)i/(double)parts;
1794 vec[pos].code = ART_LINETO;
1795 vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
1796 vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
1805 vec[pos].code = ART_END;
1810 static ArtSVP* gfxfillToSVP(gfxline_t*line)
1812 ArtVpath* vec = gfxline_to_ArtVpath(line);
1813 ArtSVP *svp = art_svp_from_vpath(vec);
1818 static ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
1820 ArtVpath* vec = gfxline_to_ArtVpath(line);
1821 ArtSVP *svp = art_svp_vpath_stroke (vec,
1822 (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
1823 ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
1824 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
1825 (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
1826 ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
1827 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
1829 miterLimit, //miter_limit
1836 static gfxline_t* SVPtogfxline(ArtSVP*svp)
1841 for(t=0;t<svp->n_segs;t++) {
1842 size += svp->segs[t].n_points + 1;
1844 gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
1846 for(t=0;t<svp->n_segs;t++) {
1847 ArtSVPSeg* seg = &svp->segs[t];
1849 for(p=0;p<seg->n_points;p++) {
1850 lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
1851 ArtPoint* point = &seg->points[p];
1852 lines[pos].x = point->x;
1853 lines[pos].y = point->y;
1854 lines[pos].next = &lines[pos+1];
1859 lines[pos-1].next = 0;
1867 static int imageInCache(gfxdevice_t*dev, void*data, int width, int height)
1871 static void addImageToCache(gfxdevice_t*dev, void*data, int width, int height)
1875 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
1877 gfxdevice_t*dev = i->dev;
1879 RGBA*mem = (RGBA*)img->data;
1881 int sizex = img->width;
1882 int sizey = img->height;
1883 int is_jpeg = i->jpeg;
1886 int newsizex=sizex, newsizey=sizey;
1889 if(is_jpeg && i->config_jpegsubpixels) {
1890 newsizex = (int)(targetwidth*i->config_jpegsubpixels+0.5);
1891 newsizey = (int)(targetheight*i->config_jpegsubpixels+0.5);
1892 } else if(!is_jpeg && i->config_ppmsubpixels) {
1893 newsizex = (int)(targetwidth*i->config_ppmsubpixels+0.5);
1894 newsizey = (int)(targetheight*i->config_ppmsubpixels+0.5);
1898 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
1901 /* TODO: cache images */
1903 if(newsizex<sizex || newsizey<sizey) {
1904 msg("<verbose> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
1905 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
1906 *newwidth = sizex = newsizex;
1907 *newheight = sizey = newsizey;
1910 *newwidth = newsizex = sizex;
1911 *newheight = newsizey = sizey;
1914 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
1915 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
1917 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
1919 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
1922 targetwidth, targetheight,
1923 /*newsizex, newsizey,*/
1924 num_colors>256?">":"", num_colors>256?256:num_colors);
1926 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
1927 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
1929 for(t=0;t<num_colors;t++) {
1930 printf("%02x%02x%02x%02x ",
1931 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
1938 int cacheid = imageInCache(dev, mem, sizex, sizey);
1941 bitid = getNewID(dev);
1942 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, i->config_jpegquality);
1943 addImageToCache(dev, mem, sizex, sizey);
1953 static SRECT gfxline_getSWFbbox(gfxline_t*line)
1955 gfxbbox_t bbox = gfxline_getbbox(line);
1957 r.xmin = (int)(bbox.xmin*20);
1958 r.ymin = (int)(bbox.ymin*20);
1959 r.xmax = (int)(bbox.xmax*20);
1960 r.ymax = (int)(bbox.ymax*20);
1964 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
1966 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1971 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
1972 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
1974 int newwidth=0,newheight=0;
1975 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
1978 double fx = (double)img->width / (double)newwidth;
1979 double fy = (double)img->height / (double)newheight;
1984 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
1985 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
1986 m.tx = (int)(matrix->tx*20);
1987 m.ty = (int)(matrix->ty*20);
1990 int myshapeid = getNewID(dev);
1991 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
1993 swf_ShapeNew(&shape);
1994 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
1995 swf_SetU16(i->tag, myshapeid);
1996 SRECT r = gfxline_getSWFbbox(line);
1997 swf_SetRect(i->tag,&r);
1998 swf_SetShapeStyles(i->tag,shape);
1999 swf_ShapeCountBits(shape,NULL,NULL);
2000 swf_SetShapeBits(i->tag,shape);
2001 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2002 i->swflastx = i->swflasty = UNDEFINED_COORD;
2003 drawgfxline(dev, line);
2004 swf_ShapeSetEnd(i->tag);
2005 swf_ShapeFree(shape);
2007 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2008 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
2009 swf_ObjectPlace(i->tag,myshapeid,getNewDepth(dev),&i->page_matrix,&cxform2,NULL);
2012 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
2014 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2019 if(i->clippos >= 127)
2021 msg("<warning> Too many clip levels.");
2025 int myshapeid = getNewID(dev);
2026 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2028 memset(&col, 0, sizeof(RGBA));
2030 swf_ShapeNew(&shape);
2031 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2032 swf_SetU16(i->tag,myshapeid);
2033 SRECT r = gfxline_getSWFbbox(line);
2034 swf_SetRect(i->tag,&r);
2035 swf_SetShapeStyles(i->tag,shape);
2036 swf_ShapeCountBits(shape,NULL,NULL);
2037 swf_SetShapeBits(i->tag,shape);
2038 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2039 i->swflastx = i->swflasty = UNDEFINED_COORD;
2040 drawgfxline(dev, line);
2041 swf_ShapeSetEnd(i->tag);
2042 swf_ShapeFree(shape);
2044 /* TODO: remember the bbox, and check all shapes against it */
2046 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2047 i->cliptags[i->clippos] = i->tag;
2048 i->clipshapes[i->clippos] = myshapeid;
2049 i->clipdepths[i->clippos] = getNewDepth(dev);
2053 static void swf_endclip(gfxdevice_t*dev)
2055 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2062 msg("<error> Invalid end of clipping region");
2066 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2067 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2069 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2071 static int gfxline_type(gfxline_t*line)
2077 int haszerosegments=0;
2079 if(line->type == gfx_moveTo) {
2082 } else if(line->type == gfx_lineTo) {
2086 } else if(line->type == gfx_splineTo) {
2088 if(tmpsplines>lines)
2093 if(lines==0 && splines==0) return 0;
2094 else if(lines==1 && splines==0) return 1;
2095 else if(lines==0 && splines==1) return 2;
2096 else if(splines==0) return 3;
2100 static int gfxline_has_dots(gfxline_t*line)
2107 if(line->type == gfx_moveTo) {
2108 if(isline && dist < 1) {
2113 } else if(line->type == gfx_lineTo) {
2114 dist += fabs(line->x - x) + fabs(line->y - y);
2116 } else if(line->type == gfx_splineTo) {
2117 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2118 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2125 if(isline && dist < 1) {
2131 static int gfxline_fix_short_edges(gfxline_t*line)
2135 if(line->type == gfx_lineTo) {
2136 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2139 } else if(line->type == gfx_splineTo) {
2140 if(fabs(line->sx - x) + fabs(line->sy - y) +
2141 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2152 static char is_inside_page(gfxdevice_t*dev, gfxcoord_t x, gfxcoord_t y)
2154 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2155 if(x<i->min_x || x>i->max_x) return 0;
2156 if(y<i->min_y || y>i->max_y) return 0;
2160 static void show_path(ArtSVP*path)
2163 printf("Segments: %d\n", path->n_segs);
2164 for(t=0;t<path->n_segs;t++) {
2165 ArtSVPSeg* seg = &path->segs[t];
2166 printf("Segment %d: %d points, %s, BBox: (%f,%f,%f,%f)\n",
2167 t, seg->n_points, seg->dir==0?"UP ":"DOWN",
2168 seg->bbox.x0, seg->bbox.y0, seg->bbox.x1, seg->bbox.y1);
2170 for(p=0;p<seg->n_points;p++) {
2171 ArtPoint* point = &seg->points[p];
2172 printf(" (%f,%f)\n", point->x, point->y);
2178 gfxline_t* gfxline_move(gfxline_t*line, double x, double y)
2180 gfxline_t*l = line = gfxline_clone(line);
2192 //#define NORMALIZE_POLYGON_POSITIONS
2194 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)
2196 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2197 int type = gfxline_type(line);
2198 int has_dots = gfxline_has_dots(line);
2199 gfxbbox_t r = gfxline_getbbox(line);
2200 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2202 /* TODO: * split line into segments, and perform this check for all segments */
2205 (width <= i->config_caplinewidth
2206 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2207 || (cap_style == gfx_capRound && type<=2))) {} else
2209 /* convert line to polygon */
2210 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2212 gfxline_fix_short_edges(line);
2213 /* we need to convert the line into a polygon */
2214 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2215 gfxline_t*gfxline = SVPtogfxline(svp);
2216 dev->fill(dev, gfxline, color);
2222 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2225 #ifdef NORMALIZE_POLYGON_POSITIONS
2227 double startx = 0, starty = 0;
2228 if(line && line->type == gfx_moveTo) {
2232 line = gfxline_move(line, -startx, -starty);
2233 i->shapeposx = (int)(startx*20);
2234 i->shapeposy = (int)(starty*20);
2237 swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a);
2238 swfoutput_setlinewidth(dev, width);
2241 drawgfxline(dev, line);
2243 #ifdef NORMALIZE_POLYGON_POSITIONS
2244 free(line); //account for _move
2248 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2250 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2251 gfxbbox_t r = gfxline_getbbox(line);
2252 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2255 if(!i->config_ignoredraworder)
2258 #ifdef NORMALIZE_POLYGON_POSITIONS
2260 double startx = 0, starty = 0;
2261 if(line && line->type == gfx_moveTo) {
2265 line = gfxline_move(line, -startx, -starty);
2266 i->shapeposx = (int)(startx*20);
2267 i->shapeposy = (int)(starty*20);
2270 swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a);
2274 drawgfxline(dev, line);
2275 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2277 #ifdef NORMALIZE_POLYGON_POSITIONS
2278 free(line); //account for _move
2281 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2283 msg("<error> Gradient filling not implemented yet");
2286 static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
2288 SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
2291 swffont->version = 2;
2292 swffont->name = (U8*)strdup(id);
2293 swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
2294 swffont->layout->ascent = 0; /* ? */
2295 swffont->layout->descent = 0;
2296 swffont->layout->leading = 0;
2297 swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
2298 swffont->encoding = FONT_ENCODING_UNICODE;
2299 swffont->numchars = font->num_glyphs;
2300 swffont->maxascii = font->max_unicode;
2301 swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
2302 swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
2303 swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
2304 swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
2305 for(t=0;t<font->max_unicode;t++) {
2306 swffont->ascii2glyph[t] = font->unicode2glyph[t];
2308 for(t=0;t<font->num_glyphs;t++) {
2311 swffont->glyph2ascii[t] = font->glyphs[t].unicode;
2312 if(font->glyphs[t].name) {
2313 swffont->glyphnames[t] = strdup(font->glyphs[t].name);
2315 swffont->glyphnames[t] = 0;
2317 swffont->glyph[t].advance = (int)(font->glyphs[t].advance * 20);
2319 swf_Shape01DrawerInit(&draw, 0);
2320 line = font->glyphs[t].line;
2323 c.x = line->sx; c.y = line->sy;
2324 to.x = line->x; to.y = line->y;
2325 if(line->type == gfx_moveTo) {
2326 draw.moveTo(&draw, &to);
2327 } else if(line->type == gfx_lineTo) {
2328 draw.lineTo(&draw, &to);
2329 } else if(line->type == gfx_splineTo) {
2330 draw.splineTo(&draw, &c, &to);
2335 swffont->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
2336 swffont->layout->bounds[t] = swf_ShapeDrawerGetBBox(&draw);
2337 draw.dealloc(&draw);
2342 static void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font)
2344 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2346 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2347 return; // the requested font is the current font
2349 fontlist_t*last=0,*l = i->fontlist;
2352 if(!strcmp((char*)l->swffont->name, fontid)) {
2353 return; // we already know this font
2357 l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
2358 l->swffont = gfxfont_to_swffont(font, fontid);
2365 swf_FontSetID(l->swffont, getNewID(i->dev));
2367 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
2368 // print font information
2369 msg("<debug> Font %s",fontid);
2370 msg("<debug> | ID: %d", l->swffont->id);
2371 msg("<debug> | Version: %d", l->swffont->version);
2372 msg("<debug> | Name: %s", l->swffont->name);
2373 msg("<debug> | Numchars: %d", l->swffont->numchars);
2374 msg("<debug> | Maxascii: %d", l->swffont->maxascii);
2375 msg("<debug> | Style: %d", l->swffont->style);
2376 msg("<debug> | Encoding: %d", l->swffont->encoding);
2377 for(int iii=0; iii<l->swffont->numchars;iii++) {
2378 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,
2379 l->swffont->layout->bounds[iii].xmin/20.0,
2380 l->swffont->layout->bounds[iii].ymin/20.0,
2381 l->swffont->layout->bounds[iii].xmax/20.0,
2382 l->swffont->layout->bounds[iii].ymax/20.0
2385 for(t=0;t<l->swffont->maxascii;t++) {
2386 if(l->swffont->ascii2glyph[t] == iii)
2387 msg("<debug> | - maps to %d",t);
2393 static void swf_switchfont(gfxdevice_t*dev, char*fontid)
2395 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2397 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2398 return; // the requested font is the current font
2400 fontlist_t*l = i->fontlist;
2402 if(!strcmp((char*)l->swffont->name, fontid)) {
2403 i->swffont = l->swffont;
2408 msg("<error> Unknown font id: %s", fontid);
2412 static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
2414 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2416 if(!i->swffont || !i->swffont->name || strcmp((char*)i->swffont->name,fontid)) // not equal to current font
2418 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
2419 with multiple fonts */
2422 swf_switchfont(dev, fontid); // set the current font
2424 swfoutput_setfontmatrix(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
2434 /* printf("%f %f\n", m.m31, m.m32);
2436 static int xpos = 40;
2437 static int ypos = 200;
2444 drawchar(dev, i->swffont, glyph, &m, color);