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 RGBA config_linkcolor;
86 float config_minlinewidth;
87 double config_caplinewidth;
88 char* config_linktarget;
89 char*config_internallinkfunction;
128 int pic_height[1024];
134 char fillstylechanged;
136 int jpeg; //next image type
141 chardata_t chardata[CHARDATAMAX];
149 double fontm11,fontm12,fontm21,fontm22;
158 } swfoutput_internal;
160 static void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform);
161 static int swf_setparameter(gfxdevice_t*driver, const char*key, const char*value);
162 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);
163 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line);
164 static void swf_endclip(gfxdevice_t*dev);
165 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);
166 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color);
167 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform);
168 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix);
169 static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix);
170 static void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font);
171 static void swf_drawlink(gfxdevice_t*dev, gfxline_t*line, char*action);
172 static void swf_startframe(gfxdevice_t*dev, int width, int height);
173 static void swf_endframe(gfxdevice_t*dev);
174 static gfxresult_t* swf_finish(gfxdevice_t*driver);
176 static swfoutput_internal* init_internal_struct()
178 swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal));
179 memset(i, 0, sizeof(swfoutput_internal));
201 i->fillstylechanged = 0;
208 i->config_dumpfonts=0;
209 i->config_ppmsubpixels=0;
210 i->config_jpegsubpixels=0;
211 i->config_opennewwindow=1;
212 i->config_ignoredraworder=0;
213 i->config_drawonlyshapes=0;
214 i->config_jpegquality=85;
215 i->config_storeallcharacters=0;
216 i->config_enablezlib=0;
217 i->config_generate_fake_tags=0;
218 i->config_insertstoptag=0;
219 i->config_flashversion=6;
220 i->config_splinemaxerror=1;
221 i->config_fontsplinemaxerror=1;
222 i->config_filloverlap=0;
224 i->config_bboxvars=0;
225 i->config_minlinewidth=0.05;
226 i->config_caplinewidth=1;
227 i->config_linktarget=0;
228 i->config_internallinkfunction=0;
230 i->config_linkcolor.r = i->config_linkcolor.g = i->config_linkcolor.b = 255;
231 i->config_linkcolor.a = 0x40;
236 static int id_error = 0;
238 static U16 getNewID(gfxdevice_t* dev)
240 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
241 if(i->currentswfid == 65535) {
243 msg("<error> ID Table overflow");
247 return ++i->currentswfid;
249 static U16 getNewDepth(gfxdevice_t* dev)
251 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
252 if(i->depth == 65535) {
254 msg("<error> Depth Table overflow");
261 static void startshape(gfxdevice_t* dev);
262 static void starttext(gfxdevice_t* dev);
263 static void endshape(gfxdevice_t* dev);
264 static void endtext(gfxdevice_t* dev);
266 typedef struct _plotxy
271 // write a move-to command into the swf
272 static int movetoxy(gfxdevice_t*dev, TAG*tag, plotxy_t p0)
274 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
275 int rx = (int)(p0.x*20);
276 int ry = (int)(p0.y*20);
277 if(rx!=i->swflastx || ry!=i->swflasty || i->fillstylechanged) {
278 swf_ShapeSetMove (tag, i->shape, rx,ry);
279 i->fillstylechanged = 0;
286 static int moveto(gfxdevice_t*dev, TAG*tag, double x, double y)
288 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
292 return movetoxy(dev, tag, p);
294 static void addPointToBBox(gfxdevice_t*dev, int px, int py)
296 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
302 swf_ExpandRect(&i->bboxrect, p);
304 swf_ExpandRect3(&i->bboxrect, p, i->linewidth*3/2);
308 /*static void plot(gfxdevice_t*dev, int x, int y, TAG*tag)
310 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
311 int width = i->linewidth/4;
315 //swf_ShapeSetLine(tag, i->shape,-width,-width);
316 //swf_ShapeSetLine(tag, i->shape,width*2,0);
317 //swf_ShapeSetLine(tag, i->shape,0,width*2);
318 //swf_ShapeSetLine(tag, i->shape,-width*2,0);
319 //swf_ShapeSetLine(tag, i->shape,0,-width*2);
320 //swf_ShapeSetLine(tag, i->shape,width,width);
323 swf_ShapeSetLine(tag, i->shape,-width,0);
324 swf_ShapeSetLine(tag, i->shape,width,-width);
325 swf_ShapeSetLine(tag, i->shape,width,width);
326 swf_ShapeSetLine(tag, i->shape,-width,width);
327 swf_ShapeSetLine(tag, i->shape,-width,-width);
328 swf_ShapeSetLine(tag, i->shape,width,0);
330 addPointToBBox(dev, x-width ,y-width);
331 addPointToBBox(dev, x+width ,y+width);
334 // write a line-to command into the swf
335 static void linetoxy(gfxdevice_t*dev, TAG*tag, plotxy_t p0)
337 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
338 int px = (int)(p0.x*20);
339 int py = (int)(p0.y*20);
340 int rx = (px-i->swflastx);
341 int ry = (py-i->swflasty);
343 swf_ShapeSetLine (tag, i->shape, rx,ry);
344 addPointToBBox(dev, i->swflastx,i->swflasty);
345 addPointToBBox(dev, px,py);
346 }/* else if(!i->fill) {
347 // treat lines of length 0 as plots, making them
348 // at least 1 twip wide so Flash will display them
349 plot(dev, i->swflastx, i->swflasty, tag);
356 static void lineto(gfxdevice_t*dev, TAG*tag, double x, double y)
361 linetoxy(dev,tag, p);
364 // write a spline-to command into the swf
365 static void splineto(gfxdevice_t*dev, TAG*tag, plotxy_t control,plotxy_t end)
367 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
368 int lastlastx = i->swflastx;
369 int lastlasty = i->swflasty;
371 int cx = ((int)(control.x*20)-i->swflastx);
372 int cy = ((int)(control.y*20)-i->swflasty);
375 int ex = ((int)(end.x*20)-i->swflastx);
376 int ey = ((int)(end.y*20)-i->swflasty);
380 if(cx || cy || ex || ey) {
381 swf_ShapeSetCurve(tag, i->shape, cx,cy,ex,ey);
382 addPointToBBox(dev, lastlastx ,lastlasty );
383 addPointToBBox(dev, lastlastx+cx,lastlasty+cy);
384 addPointToBBox(dev, lastlastx+cx+ex,lastlasty+cy+ey);
385 }/* else if(!i->fill) {
386 // treat splines of length 0 as plots
387 plot(dev, lastlastx, lastlasty, tag);
392 /* write a line, given two points and the transformation
394 /*static void line(gfxdevice_t*dev, TAG*tag, plotxy_t p0, plotxy_t p1)
396 moveto(dev, tag, p0);
397 lineto(dev, tag, p1);
400 void resetdrawer(gfxdevice_t*dev)
402 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
407 static void stopFill(gfxdevice_t*dev)
409 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
412 swf_ShapeSetStyle(i->tag,i->shape,i->linestyleid,0x8000,0);
413 i->fillstylechanged = 1;
417 static void startFill(gfxdevice_t*dev)
419 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
422 swf_ShapeSetStyle(i->tag,i->shape,0x8000,i->fillstyleid,0);
423 i->fillstylechanged = 1;
428 static inline int colorcompare(gfxdevice_t*dev, RGBA*a,RGBA*b)
440 static SRECT getcharacterbbox(gfxdevice_t*dev, SWFFONT*font, MATRIX* m)
442 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
445 memset(&r, 0, sizeof(r));
448 if(debug) printf("\n");
449 for(t=0;t<i->chardatapos;t++)
451 if(i->chardata[t].fontid != font->id) {
452 msg("<error> Internal error: fontid %d != fontid %d", i->chardata[t].fontid, font->id);
455 SRECT b = font->layout->bounds[i->chardata[t].charid];
456 b.xmin *= i->chardata[t].size;
457 b.ymin *= i->chardata[t].size;
458 b.xmax *= i->chardata[t].size;
459 b.ymax *= i->chardata[t].size;
461 /* divide by 1024, rounding xmax/ymax up */
462 b.xmax += 1023; b.ymax += 1023; b.xmin /= 1024; b.ymin /= 1024; b.xmax /= 1024; b.ymax /= 1024;
464 b.xmin += i->chardata[t].x;
465 b.ymin += i->chardata[t].y;
466 b.xmax += i->chardata[t].x;
467 b.ymax += i->chardata[t].y;
469 /* until we solve the INTERNAL_SCALING problem (see below)
470 make sure the bounding box is big enough */
476 b = swf_TurnRect(b, m);
478 if(debug) printf("(%f,%f,%f,%f) -> (%f,%f,%f,%f) [font %d/%d, char %d]\n",
479 font->layout->bounds[i->chardata[t].charid].xmin/20.0,
480 font->layout->bounds[i->chardata[t].charid].ymin/20.0,
481 font->layout->bounds[i->chardata[t].charid].xmax/20.0,
482 font->layout->bounds[i->chardata[t].charid].ymax/20.0,
487 i->chardata[t].fontid,
489 i->chardata[t].charid
491 swf_ExpandRect2(&r, &b);
493 if(debug) printf("-----> (%f,%f,%f,%f)\n",
501 static void putcharacters(gfxdevice_t*dev, TAG*tag)
503 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
507 color.r = i->chardata[0].color.r^255;
516 int charadvance[128];
519 int glyphbits=1; //TODO: can this be zero?
522 if(tag->id != ST_DEFINETEXT &&
523 tag->id != ST_DEFINETEXT2) {
524 msg("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
527 if(!i->chardatapos) {
528 msg("<warning> putcharacters called with zero characters");
531 for(pass = 0; pass < 2; pass++)
541 advancebits++; // add sign bit
542 swf_SetU8(tag, glyphbits);
543 swf_SetU8(tag, advancebits);
546 for(t=0;t<=i->chardatapos;t++)
548 if(lastfontid != i->chardata[t].fontid ||
549 lastx!=i->chardata[t].x ||
550 lasty!=i->chardata[t].y ||
551 !colorcompare(dev,&color, &i->chardata[t].color) ||
553 lastsize != i->chardata[t].size ||
556 if(charstorepos && pass==0)
559 for(s=0;s<charstorepos;s++)
561 while(charids[s]>=(1<<glyphbits))
563 while(charadvance[s]>=(1<<advancebits))
567 if(charstorepos && pass==1)
569 tag->writeBit = 0; // Q&D
570 swf_SetBits(tag, 0, 1); // GLYPH Record
571 swf_SetBits(tag, charstorepos, 7); // number of glyphs
573 for(s=0;s<charstorepos;s++)
575 swf_SetBits(tag, charids[s], glyphbits);
576 swf_SetBits(tag, charadvance[s], advancebits);
581 if(pass == 1 && t<i->chardatapos)
587 if(lastx != i->chardata[t].x ||
588 lasty != i->chardata[t].y)
590 newx = i->chardata[t].x;
591 newy = i->chardata[t].y;
597 if(!colorcompare(dev,&color, &i->chardata[t].color))
599 color = i->chardata[t].color;
602 font.id = i->chardata[t].fontid;
603 if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
606 tag->writeBit = 0; // Q&D
607 swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
610 lastfontid = i->chardata[t].fontid;
611 lastx = i->chardata[t].x;
612 lasty = i->chardata[t].y;
613 lastsize = i->chardata[t].size;
616 if(t==i->chardatapos)
620 int nextt = t==i->chardatapos-1?t:t+1;
621 int rel = i->chardata[nextt].x-i->chardata[t].x;
622 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
624 lastx=i->chardata[nextt].x;
628 lastx=i->chardata[t].x;
630 charids[charstorepos] = i->chardata[t].charid;
631 charadvance[charstorepos] = advance;
638 static void putcharacter(gfxdevice_t*dev, int fontid, int charid, int x,int y, int size, RGBA color)
640 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
641 if(i->chardatapos == CHARDATAMAX)
643 msg("<warning> Character buffer too small. SWF will be slightly bigger");
647 i->chardata[i->chardatapos].fontid = fontid;
648 i->chardata[i->chardatapos].charid = charid;
649 i->chardata[i->chardatapos].x = x;
650 i->chardata[i->chardatapos].y = y;
651 i->chardata[i->chardatapos].color = color;
652 i->chardata[i->chardatapos].size = size;
656 /* Notice: we can only put chars in the range -1639,1638 (-32768/20,32768/20).
657 So if we set this value to high, the char coordinates will overflow.
658 If we set it to low, however, the char positions will be inaccurate */
659 #define FONT_INTERNAL_SIZE 4
661 /* process a character. */
662 static int drawchar(gfxdevice_t*dev, SWFFONT *swffont, int charid, swfmatrix_t*m, gfxcolor_t*col)
664 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
666 msg("<warning> Font is NULL");
670 if(charid<0 || charid>=swffont->numchars) {
671 msg("<warning> No character %d in font %s ", charid, FIXNULL((char*)swffont->name));
674 /*if(swffont->glyph[charid].shape->bitlen <= 16) {
675 msg("<warning> Glyph %d in current charset (%s, %d characters) is empty",
676 charid, FIXNULL((char*)swffont->name), swffont->numchars);
687 float det = ((m->m11*m->m22)-(m->m21*m->m12));
688 if(fabs(det) < 0.0005) {
689 /* x direction equals y direction- the text is invisible */
692 det = 20*FONT_INTERNAL_SIZE / det;
695 p.x = (SCOORD)(( x * m->m22 - y * m->m12)*det);
696 p.y = (SCOORD)((- x * m->m21 + y * m->m11)*det);
698 RGBA rgba = *(RGBA*)col;
699 putcharacter(dev, swffont->id, charid,p.x,p.y,FONT_INTERNAL_SIZE, rgba);
700 swf_FontUseGlyph(swffont, charid);
704 static void endtext(gfxdevice_t*dev)
706 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
710 i->tag = swf_InsertTag(i->tag,ST_DEFINETEXT);
711 swf_SetU16(i->tag, i->textid);
714 r = getcharacterbbox(dev, i->swffont, &i->fontmatrix);
716 swf_SetRect(i->tag,&r);
718 swf_SetMatrix(i->tag,&i->fontmatrix);
720 msg("<trace> Placing text (%d characters) as ID %d", i->chardatapos, i->textid);
722 putcharacters(dev, i->tag);
724 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
726 swf_ObjectPlace(i->tag,i->textid,getNewDepth(dev),&i->page_matrix,NULL,NULL);
730 /* set's the matrix which is to be applied to characters drawn by swfoutput_drawchar() */
731 static void swfoutput_setfontmatrix(gfxdevice_t*dev,double m11,double m21,
732 double m12,double m22)
738 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
739 if(i->fontm11 == m11 &&
752 m.sx = (U32)(((i->fontm11)*65536)/FONT_INTERNAL_SIZE); m.r1 = (U32)(((i->fontm12)*65536)/FONT_INTERNAL_SIZE);
753 m.r0 = (U32)(((i->fontm21)*65536)/FONT_INTERNAL_SIZE); m.sy = (U32)(((i->fontm22)*65536)/FONT_INTERNAL_SIZE);
759 static void endpage(gfxdevice_t*dev)
761 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
771 void swf_startframe(gfxdevice_t*dev, int width, int height)
773 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
774 if(!i->firstpage && !i->pagefinished)
776 msg("<verbose> Starting new SWF page of size %dx%d", width, height);
778 swf_GetMatrix(0, &i->page_matrix);
779 i->page_matrix.tx = 0;
780 i->page_matrix.ty = 0;
786 /* set clipping/background rectangle */
787 /* TODO: this should all be done in SWFOutputDev */
788 //setBackground(dev, x1, y1, x2, y2);
790 /* increase SWF's bounding box */
796 swf_ExpandRect2(&i->swf->movieSize, &r);
798 i->lastframeno = i->frameno;
803 void swf_endframe(gfxdevice_t*dev)
805 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
810 if(i->config_insertstoptag) {
812 atag = action_Stop(atag);
813 atag = action_End(atag);
814 i->tag = swf_InsertTag(i->tag,ST_DOACTION);
815 swf_ActionSet(i->tag,atag);
817 i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME);
820 for(i->depth;i->depth>i->startdepth;i->depth--) {
821 i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2);
822 swf_SetU16(i->tag,i->depth);
824 i->depth = i->startdepth;
827 static void setBackground(gfxdevice_t*dev, int x1, int y1, int x2, int y2)
829 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
831 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
835 int shapeid = getNewID(dev);
840 i->tag = swf_InsertTag(i->tag, ST_DEFINESHAPE);
842 fs1 = swf_ShapeAddSolidFillStyle(s, &rgb);
843 swf_SetU16(i->tag,shapeid);
844 swf_SetRect(i->tag,&r);
845 swf_SetShapeHeader(i->tag,s);
846 swf_ShapeSetAll(i->tag,s,x1,y1,ls1,fs1,0);
847 swf_ShapeSetLine(i->tag,s,(x2-x1),0);
848 swf_ShapeSetLine(i->tag,s,0,(y2-y1));
849 swf_ShapeSetLine(i->tag,s,(x1-x2),0);
850 swf_ShapeSetLine(i->tag,s,0,(y1-y2));
851 swf_ShapeSetEnd(i->tag);
853 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
854 swf_ObjectPlace(i->tag,shapeid,getNewDepth(dev),0,0,0);
855 i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2);
856 swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(dev),0,0,0,65535);
859 /* initialize the swf writer */
860 void gfxdevice_swf_init(gfxdevice_t* dev)
862 memset(dev, 0, sizeof(gfxdevice_t));
863 dev->internal = init_internal_struct();
865 dev->startpage = swf_startframe;
866 dev->endpage = swf_endframe;
867 dev->finish = swf_finish;
868 dev->fillbitmap = swf_fillbitmap;
869 dev->setparameter = swf_setparameter;
870 dev->stroke = swf_stroke;
871 dev->startclip = swf_startclip;
872 dev->endclip = swf_endclip;
873 dev->fill = swf_fill;
874 dev->fillbitmap = swf_fillbitmap;
875 dev->fillgradient = swf_fillgradient;
876 dev->addfont = swf_addfont;
877 dev->drawchar = swf_drawchar;
878 dev->drawlink = swf_drawlink;
880 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
886 msg("<verbose> initializing swf output\n", i->max_x,i->max_y);
890 i->swf = (SWF*)rfx_calloc(sizeof(SWF));
891 i->swf->fileVersion = i->config_flashversion;
892 i->swf->frameRate = 0x0040; // 1 frame per 4 seconds
893 i->swf->movieSize.xmin = 0;
894 i->swf->movieSize.ymin = 0;
895 i->swf->movieSize.xmax = 0;
896 i->swf->movieSize.ymax = 0;
898 i->swf->firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
899 i->tag = i->swf->firstTag;
900 rgb.a = rgb.r = rgb.g = rgb.b = 0xff;
901 swf_SetRGB(i->tag,&rgb);
903 i->startdepth = i->depth = 0;
905 if(i->config_protect)
906 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
909 static void startshape(gfxdevice_t*dev)
911 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
920 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
922 swf_ShapeNew(&i->shape);
923 i->linestyleid = swf_ShapeAddLineStyle(i->shape,i->linewidth,&i->strokergb);
924 i->fillstyleid = swf_ShapeAddSolidFillStyle(i->shape,&i->fillrgb);
926 i->shapeid = getNewID(dev);
928 msg("<debug> Using shape id %d", i->shapeid);
930 swf_SetU16(i->tag,i->shapeid); // ID
932 i->bboxrectpos = i->tag->len;
936 r.xmax = 20*i->max_x;
937 r.ymax = 20*i->max_y;
938 swf_SetRect(i->tag,&r);
940 memset(&i->bboxrect, 0, sizeof(i->bboxrect));
942 swf_SetShapeStyles(i->tag,i->shape);
943 swf_ShapeCountBits(i->shape,NULL,NULL);
944 swf_SetShapeBits(i->tag,i->shape);
946 /* TODO: do we really need this? */
947 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,i->linestyleid,0,0);
948 i->swflastx=i->swflasty=0;
953 static void starttext(gfxdevice_t*dev)
955 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
959 i->textid = getNewID(dev);
961 i->swflastx=i->swflasty=0;
965 /* TODO: move to ../lib/rfxswf */
966 void changeRect(gfxdevice_t*dev, TAG*tag, int pos, SRECT*newrect)
968 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
969 /* determine length of old rect */
973 swf_GetRect(tag, &old);
974 swf_ResetReadBits(tag);
975 int pos_end = tag->pos;
977 int len = tag->len - pos_end;
978 U8*data = (U8*)malloc(len);
979 memcpy(data, &tag->data[pos_end], len);
982 swf_SetRect(tag, newrect);
983 swf_SetBlock(tag, data, len);
985 tag->pos = tag->readBit = 0;
988 void cancelshape(gfxdevice_t*dev)
990 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
991 /* delete old shape tag */
993 i->tag = i->tag->prev;
994 swf_DeleteTag(todel);
995 if(i->shape) {swf_ShapeFree(i->shape);i->shape=0;}
1000 void fixAreas(gfxdevice_t*dev)
1002 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1003 if(!i->shapeisempty && i->fill &&
1004 (i->bboxrect.xmin == i->bboxrect.xmax ||
1005 i->bboxrect.ymin == i->bboxrect.ymax) &&
1006 i->config_minlinewidth >= 0.001
1008 msg("<debug> Shape has size 0: width=%.2f height=%.2f",
1009 (i->bboxrect.xmax-i->bboxrect.xmin)/20.0,
1010 (i->bboxrect.ymax-i->bboxrect.ymin)/20.0
1013 SRECT r = i->bboxrect;
1015 if(r.xmin == r.xmax && r.ymin == r.ymax) {
1016 /* this thing comes down to a single dot- nothing to fix here */
1022 RGBA save_col = i->strokergb;
1023 int save_width = i->linewidth;
1025 i->strokergb = i->fillrgb;
1026 i->linewidth = (int)(i->config_minlinewidth*20);
1027 if(i->linewidth==0) i->linewidth = 1;
1031 moveto(dev, i->tag, r.xmin/20.0,r.ymin/20.0);
1032 lineto(dev, i->tag, r.xmax/20.0,r.ymax/20.0);
1034 i->strokergb = save_col;
1035 i->linewidth = save_width;
1040 static void endshape_noput(gfxdevice_t*dev)
1042 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1045 //changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1048 swf_ShapeFree(i->shape);
1056 static void endshape(gfxdevice_t*dev)
1058 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1064 if(i->shapeisempty ||
1066 (i->bboxrect.xmin == i->bboxrect.xmax &&
1067 i->bboxrect.ymin == i->bboxrect.ymax))
1069 // delete the shape again, we didn't do anything
1070 msg("<debug> cancelling shape: bbox is (%f,%f,%f,%f)",
1071 i->bboxrect.xmin /20.0,
1072 i->bboxrect.ymin /20.0,
1073 i->bboxrect.xmax /20.0,
1074 i->bboxrect.ymax /20.0
1080 swf_ShapeSetEnd(i->tag);
1082 changeRect(dev, i->tag, i->bboxrectpos, &i->bboxrect);
1084 msg("<trace> Placing shape id %d", i->shapeid);
1086 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1087 MATRIX m = i->page_matrix;
1088 m.tx += i->shapeposx;
1089 m.ty += i->shapeposy;
1090 swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(dev),&m,NULL,NULL);
1092 swf_ShapeFree(i->shape);
1095 i->bboxrectpos = -1;
1102 void wipeSWF(SWF*swf)
1104 TAG*tag = swf->firstTag;
1106 TAG*next = tag->next;
1107 if(tag->id != ST_SETBACKGROUNDCOLOR &&
1108 tag->id != ST_END &&
1109 tag->id != ST_DOACTION &&
1110 tag->id != ST_SHOWFRAME) {
1118 void swfoutput_finalize(gfxdevice_t*dev)
1120 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1122 if(i->tag && i->tag->id == ST_END)
1123 return; //already done
1125 if(i->config_bboxvars) {
1126 TAG* tag = swf_InsertTag(i->swf->firstTag, ST_DOACTION);
1128 a = action_PushString(a, "xmin");
1129 a = action_PushFloat(a, i->swf->movieSize.xmin / 20.0);
1130 a = action_SetVariable(a);
1131 a = action_PushString(a, "ymin");
1132 a = action_PushFloat(a, i->swf->movieSize.ymin / 20.0);
1133 a = action_SetVariable(a);
1134 a = action_PushString(a, "xmax");
1135 a = action_PushFloat(a, i->swf->movieSize.xmax / 20.0);
1136 a = action_SetVariable(a);
1137 a = action_PushString(a, "ymax");
1138 a = action_PushFloat(a, i->swf->movieSize.ymax / 20.0);
1139 a = action_SetVariable(a);
1140 a = action_PushString(a, "width");
1141 a = action_PushFloat(a, (i->swf->movieSize.xmax - i->swf->movieSize.xmin) / 20.0);
1142 a = action_SetVariable(a);
1143 a = action_PushString(a, "height");
1144 a = action_PushFloat(a, (i->swf->movieSize.ymax - i->swf->movieSize.ymin) / 20.0);
1145 a = action_SetVariable(a);
1147 swf_ActionSet(tag, a);
1151 if(i->frameno == i->lastframeno) // fix: add missing pagefeed
1155 fontlist_t *tmp,*iterator = i->fontlist;
1157 TAG*mtag = i->swf->firstTag;
1158 if(iterator->swffont) {
1159 mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
1160 if(!i->config_storeallcharacters) {
1161 msg("<debug> Reducing font %s", iterator->swffont->name);
1162 swf_FontReduce(iterator->swffont);
1164 swf_FontSetDefine2(mtag, iterator->swffont);
1167 iterator = iterator->next;
1169 i->tag = swf_InsertTag(i->tag,ST_END);
1170 TAG* tag = i->tag->prev;
1172 /* remove the removeobject2 tags between the last ST_SHOWFRAME
1173 and the ST_END- they confuse the flash player */
1174 while(tag->id == ST_REMOVEOBJECT2) {
1175 TAG* prev = tag->prev;
1183 if(i->config_enablezlib || i->config_flashversion>=6) {
1184 i->swf->compressed = 1;
1188 int swfresult_save(gfxresult_t*gfx, char*filename)
1190 SWF*swf = (SWF*)gfx->internal;
1193 fi = open(filename, O_BINARY|O_CREAT|O_TRUNC|O_WRONLY, 0777);
1198 msg("<fatal> Could not create \"%s\". ", FIXNULL(filename));
1202 if(swf->compressed) {
1203 if FAILED(swf_WriteSWC(fi,swf))
1204 msg("<error> WriteSWC() failed.\n");
1206 if FAILED(swf_WriteSWF(fi,swf))
1207 msg("<error> WriteSWF() failed.\n");
1214 void* swfresult_get(gfxresult_t*gfx, char*name)
1216 SWF*swf = (SWF*)gfx->internal;
1217 if(!strcmp(name, "swf")) {
1218 return (void*)swf_CopySWF(swf);
1219 } else if(!strcmp(name, "xmin")) {
1220 return (void*)(swf->movieSize.xmin/20);
1221 } else if(!strcmp(name, "ymin")) {
1222 return (void*)(swf->movieSize.ymin/20);
1223 } else if(!strcmp(name, "xmax")) {
1224 return (void*)(swf->movieSize.xmax/20);
1225 } else if(!strcmp(name, "ymax")) {
1226 return (void*)(swf->movieSize.ymax/20);
1227 } else if(!strcmp(name, "width")) {
1228 return (void*)((swf->movieSize.xmax - swf->movieSize.xmin)/20);
1229 } else if(!strcmp(name, "height")) {
1230 return (void*)((swf->movieSize.ymax - swf->movieSize.ymin)/20);
1234 void swfresult_destroy(gfxresult_t*gfx)
1237 swf_FreeTags((SWF*)gfx->internal);
1238 free(gfx->internal);
1241 memset(gfx, 0, sizeof(gfxresult_t));
1245 static void swfoutput_destroy(gfxdevice_t* dev);
1247 gfxresult_t* swf_finish(gfxdevice_t* dev)
1249 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1252 if(i->config_linktarget) {
1253 free(i->config_linktarget);
1254 i->config_linktarget = 0;
1257 swfoutput_finalize(dev);
1258 SWF* swf = i->swf;i->swf = 0;
1259 swfoutput_destroy(dev);
1261 result = (gfxresult_t*)rfx_calloc(sizeof(gfxresult_t));
1262 result->internal = swf;
1263 result->save = swfresult_save;
1265 result->get = swfresult_get;
1266 result->destroy = swfresult_destroy;
1270 /* Perform cleaning up */
1271 static void swfoutput_destroy(gfxdevice_t* dev)
1273 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1275 /* not initialized yet- nothing to destroy */
1279 fontlist_t *tmp,*iterator = i->fontlist;
1281 if(iterator->swffont) {
1282 swf_FontFree(iterator->swffont);iterator->swffont=0;
1285 iterator = iterator->next;
1288 if(i->swf) {swf_FreeTags(i->swf);free(i->swf);i->swf = 0;}
1291 memset(dev, 0, sizeof(gfxdevice_t));
1294 static void swfoutput_setfillcolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1296 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1297 if(i->fillrgb.r == r &&
1298 i->fillrgb.g == g &&
1299 i->fillrgb.b == b &&
1300 i->fillrgb.a == a) return;
1310 static void swfoutput_setstrokecolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
1312 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1313 if(i->strokergb.r == r &&
1314 i->strokergb.g == g &&
1315 i->strokergb.b == b &&
1316 i->strokergb.a == a) return;
1326 //#define ROUND_UP 19
1327 //#define ROUND_UP 10
1329 static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth)
1331 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1332 if(i->linewidth == (U16)(_linewidth*20+19.0/20.0))
1336 i->linewidth = (U16)(_linewidth*20+19.0/20.0);
1340 static void drawlink(gfxdevice_t*dev, ActionTAG*,ActionTAG*, gfxline_t*points, char mouseover);
1341 static void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points);
1342 static void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points);
1343 static void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points);
1345 void swfoutput_drawlink(gfxdevice_t*dev, char*url, gfxline_t*points)
1347 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1348 dev->drawlink(dev, points, url);
1351 void swf_drawlink(gfxdevice_t*dev, gfxline_t*points, char*url)
1353 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1355 if(!strncmp("http://pdf2swf:", url, 15)) {
1356 char*tmp = strdup(url);
1357 int l = strlen(tmp);
1360 swfoutput_namedlink(dev, tmp+15, points);
1363 } else if(!strncmp("page", url, 4)) {
1366 if(url[t]<'0' || url[t]>'9')
1369 int page = atoi(&url[4]) - 1;
1370 if(page<0) page = 0;
1371 swfoutput_linktopage(dev, page, points);
1374 swfoutput_linktourl(dev, url, points);
1377 void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points)
1380 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1386 if(!i->config_linktarget) {
1387 if(!i->config_opennewwindow)
1388 actions = action_GetUrl(0, url, "_parent");
1390 actions = action_GetUrl(0, url, "_this");
1392 actions = action_GetUrl(0, url, i->config_linktarget);
1394 actions = action_End(actions);
1396 drawlink(dev, actions, 0, points,0);
1398 void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points)
1400 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1401 ActionTAG* actions = 0;
1408 if(!i->config_internallinkfunction) {
1409 actions = action_GotoFrame(actions, page);
1410 actions = action_End(actions);
1412 actions = action_PushInt(actions, page); //parameter
1413 actions = action_PushInt(actions, 1); //number of parameters (1)
1414 actions = action_PushString(actions, i->config_internallinkfunction); //function name
1415 actions = action_CallFunction(actions);
1418 drawlink(dev, actions, 0, points,0);
1421 /* Named Links (a.k.a. Acrobatmenu) are used to implement various gadgets
1422 of the viewer objects, like subtitles, index elements etc.
1424 void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points)
1426 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1427 ActionTAG *actions1,*actions2;
1428 char*tmp = strdup(name);
1436 if(!strncmp(tmp, "call:", 5))
1438 char*x = strchr(&tmp[5], ':');
1440 actions1 = action_PushInt(0, 0); //number of parameters (0)
1441 actions1 = action_PushString(actions1, &tmp[5]); //function name
1442 actions1 = action_CallFunction(actions1);
1445 actions1 = action_PushString(0, x+1); //parameter
1446 actions1 = action_PushInt(actions1, 1); //number of parameters (1)
1447 actions1 = action_PushString(actions1, &tmp[5]); //function name
1448 actions1 = action_CallFunction(actions1);
1450 actions2 = action_End(0);
1455 actions1 = action_PushString(0, "/:subtitle");
1456 actions1 = action_PushString(actions1, name);
1457 actions1 = action_SetVariable(actions1);
1458 actions1 = action_End(actions1);
1460 actions2 = action_PushString(0, "/:subtitle");
1461 actions2 = action_PushString(actions2, "");
1462 actions2 = action_SetVariable(actions2);
1463 actions2 = action_End(actions2);
1466 drawlink(dev, actions1, actions2, points,mouseover);
1468 swf_ActionFree(actions1);
1469 swf_ActionFree(actions2);
1473 static void drawgfxline(gfxdevice_t*dev, gfxline_t*line)
1475 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1476 gfxcoord_t lastx=0,lasty=0,px=0,py=0;
1481 /* check whether the next segment is zero */
1482 if(line->type == gfx_moveTo) {
1483 msg("<trace> ======== moveTo %.2f %.2f", line->x, line->y);
1484 moveto(dev, i->tag, line->x, line->y);
1485 px = lastx = line->x;
1486 py = lasty = line->y;
1488 } if(line->type == gfx_lineTo) {
1489 msg("<trace> ======== lineTo %.2f %.2f", line->x, line->y);
1490 lineto(dev, i->tag, line->x, line->y);
1494 } else if(line->type == gfx_splineTo) {
1495 msg("<trace> ======== splineTo %.2f %.2f", line->x, line->y);
1497 s.x = line->sx;p.x = line->x;
1498 s.y = line->sy;p.y = line->y;
1499 splineto(dev, i->tag, s, p);
1509 static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gfxline_t*points, char mouseover)
1511 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1516 plotxy_t p1,p2,p3,p4;
1522 int buttonid = getNewID(dev);
1523 gfxbbox_t bbox = gfxline_getbbox(points);
1526 myshapeid = getNewID(dev);
1527 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1528 swf_ShapeNew(&i->shape);
1529 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1530 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1531 swf_SetU16(i->tag, myshapeid);
1532 r.xmin = (int)(bbox.xmin*20);
1533 r.ymin = (int)(bbox.ymin*20);
1534 r.xmax = (int)(bbox.xmax*20);
1535 r.ymax = (int)(bbox.ymax*20);
1536 swf_SetRect(i->tag,&r);
1537 swf_SetShapeStyles(i->tag,i->shape);
1538 swf_ShapeCountBits(i->shape,NULL,NULL);
1539 swf_SetShapeBits(i->tag,i->shape);
1540 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1541 i->swflastx = i->swflasty = 0;
1542 drawgfxline(dev, points);
1543 swf_ShapeSetEnd(i->tag);
1546 myshapeid2 = getNewID(dev);
1547 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE3);
1548 swf_ShapeNew(&i->shape);
1550 rgb = i->config_linkcolor;
1552 fsid = swf_ShapeAddSolidFillStyle(i->shape,&rgb);
1553 swf_SetU16(i->tag, myshapeid2);
1554 r.xmin = (int)(bbox.xmin*20);
1555 r.ymin = (int)(bbox.ymin*20);
1556 r.xmax = (int)(bbox.xmax*20);
1557 r.ymax = (int)(bbox.ymax*20);
1558 swf_SetRect(i->tag,&r);
1559 swf_SetShapeStyles(i->tag,i->shape);
1560 swf_ShapeCountBits(i->shape,NULL,NULL);
1561 swf_SetShapeBits(i->tag,i->shape);
1562 swf_ShapeSetAll(i->tag,i->shape,/*x*/0,/*y*/0,0,fsid,0);
1563 i->swflastx = i->swflasty = 0;
1564 drawgfxline(dev, points);
1565 swf_ShapeSetEnd(i->tag);
1569 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON);
1570 swf_SetU16(i->tag,buttonid); //id
1571 swf_ButtonSetFlags(i->tag, 0); //menu=no
1572 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1573 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1574 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1575 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1576 swf_SetU8(i->tag,0);
1577 swf_ActionSet(i->tag,actions1);
1578 swf_SetU8(i->tag,0);
1582 i->tag = swf_InsertTag(i->tag,ST_DEFINEBUTTON2);
1583 swf_SetU16(i->tag,buttonid); //id
1584 swf_ButtonSetFlags(i->tag, 0); //menu=no
1585 swf_ButtonSetRecord(i->tag,0x01,myshapeid,i->depth,0,0);
1586 swf_ButtonSetRecord(i->tag,0x02,myshapeid2,i->depth,0,0);
1587 swf_ButtonSetRecord(i->tag,0x04,myshapeid2,i->depth,0,0);
1588 swf_ButtonSetRecord(i->tag,0x08,myshapeid,i->depth,0,0);
1589 swf_SetU8(i->tag,0); // end of button records
1590 swf_ButtonSetCondition(i->tag, BC_IDLE_OVERUP);
1591 swf_ActionSet(i->tag,actions1);
1593 swf_ButtonSetCondition(i->tag, BC_OVERUP_IDLE);
1594 swf_ActionSet(i->tag,actions2);
1595 swf_SetU8(i->tag,0);
1596 swf_ButtonPostProcess(i->tag, 2);
1598 swf_SetU8(i->tag,0);
1599 swf_ButtonPostProcess(i->tag, 1);
1603 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
1605 if(posx!=0 || posy!=0) {
1607 p.x = (int)(posx*20);
1608 p.y = (int)(posy*20);
1609 p = swf_TurnPoint(p, &i->page_matrix);
1614 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&m,0,0);
1616 swf_ObjectPlace(i->tag, buttonid, getNewDepth(dev),&i->page_matrix,0,0);
1623 for(t=0;t<picpos;t++)
1625 if(pic_xids[t] == xid &&
1626 pic_yids[t] == yid) {
1627 width = pic_width[t];
1628 height = pic_height[t];
1632 pic_ids[picpos] = swfoutput_drawimagelosslessN(&output, pic, pal, width, height, x1,y1,x2,y2,x3,y3,x4,y4, numpalette);
1633 pic_xids[picpos] = xid;
1634 pic_yids[picpos] = yid;
1635 pic_width[picpos] = width;
1636 pic_height[picpos] = height;
1639 pic[width*y+x] = buf[0];
1643 xid += pal[1].r*3 + pal[1].g*11 + pal[1].b*17;
1644 yid += pal[1].r*7 + pal[1].g*5 + pal[1].b*23;
1648 xid += x*r+x*b*3+x*g*7+x*a*11;
1649 yid += y*r*3+y*b*17+y*g*19+y*a*11;
1651 for(t=0;t<picpos;t++)
1653 if(pic_xids[t] == xid &&
1654 pic_yids[t] == yid) {
1663 int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
1665 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
1667 if(!strcmp(name, "jpegsubpixels")) {
1668 i->config_jpegsubpixels = atof(value);
1669 } else if(!strcmp(name, "ppmsubpixels")) {
1670 i->config_ppmsubpixels = atof(value);
1671 } else if(!strcmp(name, "subpixels")) {
1672 i->config_ppmsubpixels = i->config_jpegsubpixels = atof(value);
1673 } else if(!strcmp(name, "drawonlyshapes")) {
1674 i->config_drawonlyshapes = atoi(value);
1675 } else if(!strcmp(name, "ignoredraworder")) {
1676 i->config_ignoredraworder = atoi(value);
1677 } else if(!strcmp(name, "filloverlap")) {
1678 i->config_filloverlap = atoi(value);
1679 } else if(!strcmp(name, "linksopennewwindow")) {
1680 i->config_opennewwindow = atoi(value);
1681 } else if(!strcmp(name, "opennewwindow")) {
1682 i->config_opennewwindow = atoi(value);
1683 } else if(!strcmp(name, "storeallcharacters")) {
1684 i->config_storeallcharacters = atoi(value);
1685 } else if(!strcmp(name, "enablezlib")) {
1686 i->config_enablezlib = atoi(value);
1687 } else if(!strcmp(name, "bboxvars")) {
1688 i->config_bboxvars = atoi(value);
1689 } else if(!strcmp(name, "internallinkfunction")) {
1690 i->config_internallinkfunction = strdup(value);
1691 } else if(!strcmp(name, "insertstop")) {
1692 i->config_insertstoptag = atoi(value);
1693 } else if(!strcmp(name, "protect")) {
1694 i->config_protect = atoi(value);
1695 if(i->config_protect && i->tag) {
1696 i->tag = swf_InsertTag(i->tag, ST_PROTECT);
1698 } else if(!strcmp(name, "faketags")) {
1699 i->config_generate_fake_tags = atoi(value);
1700 } else if(!strcmp(name, "flashversion")) {
1701 i->config_flashversion = atoi(value);
1703 i->swf->fileVersion = i->config_flashversion;
1705 } else if(!strcmp(name, "minlinewidth")) {
1706 i->config_minlinewidth = atof(value);
1707 } else if(!strcmp(name, "caplinewidth")) {
1708 i->config_caplinewidth = atof(value);
1709 } else if(!strcmp(name, "linktarget")) {
1710 i->config_linktarget = strdup(value);
1711 } else if(!strcmp(name, "dumpfonts")) {
1712 i->config_dumpfonts = atoi(value);
1713 } else if(!strcmp(name, "next_bitmap_is_jpeg")) {
1715 } else if(!strcmp(name, "jpegquality")) {
1716 int val = atoi(value);
1718 if(val>100) val=100;
1719 i->config_jpegquality = val;
1720 } else if(!strcmp(name, "splinequality")) {
1721 int v = atoi(value);
1722 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1724 i->config_splinemaxerror = v;
1725 } else if(!strcmp(name, "fontquality")) {
1726 int v = atoi(value);
1727 v = 500-(v*5); // 100% = 0.25 pixel, 0% = 25 pixel
1729 i->config_fontsplinemaxerror = v;
1730 } else if(!strcmp(name, "linkcolor")) {
1731 if(strlen(value)!=8) {
1732 fprintf(stderr, "Unknown format for option 'linkcolor'. (%s <-> RRGGBBAA)\n", value);
1735 # define NIBBLE(s) (((s)>='0' && (s)<='9')?((s)-'0'):((s)&0x0f)+9)
1736 i->config_linkcolor.r = NIBBLE(value[0])<<4 | NIBBLE(value[1]);
1737 i->config_linkcolor.g = NIBBLE(value[2])<<4 | NIBBLE(value[3]);
1738 i->config_linkcolor.b = NIBBLE(value[4])<<4 | NIBBLE(value[5]);
1739 i->config_linkcolor.a = NIBBLE(value[6])<<4 | NIBBLE(value[7]);
1740 printf("%02x%02x%02x%02x\n",
1741 i->config_linkcolor.r,
1742 i->config_linkcolor.g,
1743 i->config_linkcolor.b,
1744 i->config_linkcolor.a);
1747 fprintf(stderr, "unknown parameter: %s (=%s)\n", name, value);
1753 // --------------------------------------------------------------------
1755 static CXFORM gfxcxform_to_cxform(gfxcxform_t* c)
1758 swf_GetCXForm(0, &cx, 1);
1761 if(c->rg!=0 || c->rb!=0 || c->ra!=0 ||
1762 c->gr!=0 || c->gb!=0 || c->ga!=0 ||
1763 c->br!=0 || c->bg!=0 || c->ba!=0 ||
1764 c->ar!=0 || c->ag!=0 || c->ab!=0)
1765 msg("<warning> CXForm not SWF-compatible");
1767 cx.a0 = (S16)(c->aa*256);
1768 cx.r0 = (S16)(c->rr*256);
1769 cx.g0 = (S16)(c->gg*256);
1770 cx.b0 = (S16)(c->bb*256);
1778 static ArtVpath* gfxline_to_ArtVpath(gfxline_t*line)
1780 ArtVpath *vec = NULL;
1785 /* factor which determines into how many line fragments a spline is converted */
1786 double subfraction = 2.4;//0.3
1790 if(l2->type == gfx_moveTo) {
1792 } if(l2->type == gfx_lineTo) {
1794 } if(l2->type == gfx_splineTo) {
1795 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))*subfraction);
1796 if(!parts) parts = 1;
1806 vec = art_new (ArtVpath, len);
1811 if(l2->type == gfx_moveTo) {
1812 vec[pos].code = ART_MOVETO;
1817 } else if(l2->type == gfx_lineTo) {
1818 vec[pos].code = ART_LINETO;
1823 } else if(l2->type == gfx_splineTo) {
1825 int parts = (int)(sqrt(fabs(l2->x-2*l2->sx+x) + fabs(l2->y-2*l2->sy+y))*subfraction);
1826 if(!parts) parts = 1;
1827 for(i=0;i<=parts;i++) {
1828 double t = (double)i/(double)parts;
1829 vec[pos].code = ART_LINETO;
1830 vec[pos].x = l2->x*t*t + 2*l2->sx*t*(1-t) + x*(1-t)*(1-t);
1831 vec[pos].y = l2->y*t*t + 2*l2->sy*t*(1-t) + y*(1-t)*(1-t);
1840 vec[pos].code = ART_END;
1845 static ArtSVP* gfxfillToSVP(gfxline_t*line)
1847 ArtVpath* vec = gfxline_to_ArtVpath(line);
1848 ArtSVP *svp = art_svp_from_vpath(vec);
1853 static ArtSVP* gfxstrokeToSVP(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit)
1855 ArtVpath* vec = gfxline_to_ArtVpath(line);
1856 ArtSVP *svp = art_svp_vpath_stroke (vec,
1857 (joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
1858 ((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
1859 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
1860 (cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
1861 ((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
1862 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
1864 miterLimit, //miter_limit
1871 static gfxline_t* SVPtogfxline(ArtSVP*svp)
1876 for(t=0;t<svp->n_segs;t++) {
1877 size += svp->segs[t].n_points + 1;
1879 gfxline_t* lines = (gfxline_t*)rfx_alloc(sizeof(gfxline_t)*size);
1881 for(t=0;t<svp->n_segs;t++) {
1882 ArtSVPSeg* seg = &svp->segs[t];
1884 for(p=0;p<seg->n_points;p++) {
1885 lines[pos].type = p==0?gfx_moveTo:gfx_lineTo;
1886 ArtPoint* point = &seg->points[p];
1887 lines[pos].x = point->x;
1888 lines[pos].y = point->y;
1889 lines[pos].next = &lines[pos+1];
1894 lines[pos-1].next = 0;
1902 static int imageInCache(gfxdevice_t*dev, void*data, int width, int height)
1906 static void addImageToCache(gfxdevice_t*dev, void*data, int width, int height)
1910 static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight)
1912 gfxdevice_t*dev = i->dev;
1914 RGBA*mem = (RGBA*)img->data;
1916 int sizex = img->width;
1917 int sizey = img->height;
1918 int is_jpeg = i->jpeg;
1921 int newsizex=sizex, newsizey=sizey;
1924 if(is_jpeg && i->config_jpegsubpixels) {
1925 newsizex = (int)(targetwidth*i->config_jpegsubpixels+0.5);
1926 newsizey = (int)(targetheight*i->config_jpegsubpixels+0.5);
1927 } else if(!is_jpeg && i->config_ppmsubpixels) {
1928 newsizex = (int)(targetwidth*i->config_ppmsubpixels+0.5);
1929 newsizey = (int)(targetheight*i->config_ppmsubpixels+0.5);
1933 if(sizex<=0 || sizey<=0 || newsizex<=0 || newsizey<=0)
1936 /* TODO: cache images */
1938 if(newsizex<sizex || newsizey<sizey) {
1939 msg("<verbose> Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey);
1940 newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey);
1941 *newwidth = sizex = newsizex;
1942 *newheight = sizey = newsizey;
1945 *newwidth = newsizex = sizex;
1946 *newheight = newsizey = sizey;
1949 int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0);
1950 int has_alpha = swf_ImageHasAlpha(mem,sizex,sizey);
1952 msg("<verbose> Drawing %dx%d %s%simage at size %dx%d (%dx%d), %s%d colors",
1954 has_alpha?(has_alpha==2?"semi-transparent ":"transparent "):"",
1957 targetwidth, targetheight,
1958 /*newsizex, newsizey,*/
1959 num_colors>256?">":"", num_colors>256?256:num_colors);
1961 /*RGBA* pal = (RGBA*)rfx_alloc(sizeof(RGBA)*num_colors);
1962 swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,pal);
1964 for(t=0;t<num_colors;t++) {
1965 printf("%02x%02x%02x%02x ",
1966 pal[t].r, pal[t].g, pal[t].b, pal[t].a);
1973 int cacheid = imageInCache(dev, mem, sizex, sizey);
1976 bitid = getNewID(dev);
1977 i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, i->config_jpegquality);
1978 addImageToCache(dev, mem, sizex, sizey);
1988 static SRECT gfxline_getSWFbbox(gfxline_t*line)
1990 gfxbbox_t bbox = gfxline_getbbox(line);
1992 r.xmin = (int)(bbox.xmin*20);
1993 r.ymin = (int)(bbox.ymin*20);
1994 r.xmax = (int)(bbox.xmax*20);
1995 r.ymax = (int)(bbox.ymax*20);
1999 static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
2001 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2006 int targetx = (int)(sqrt(matrix->m00*matrix->m00 + matrix->m01*matrix->m01)*img->width);
2007 int targety = (int)(sqrt(matrix->m10*matrix->m10 + matrix->m11*matrix->m11)*img->height);
2009 int newwidth=0,newheight=0;
2010 int bitid = add_image(i, img, targetx, targety, &newwidth, &newheight);
2013 double fx = (double)img->width / (double)newwidth;
2014 double fy = (double)img->height / (double)newheight;
2019 m.sx = (int)(65536*20*matrix->m00*fx); m.r1 = (int)(65536*20*matrix->m10*fy);
2020 m.r0 = (int)(65536*20*matrix->m01*fx); m.sy = (int)(65536*20*matrix->m11*fy);
2021 m.tx = (int)(matrix->tx*20);
2022 m.ty = (int)(matrix->ty*20);
2025 int myshapeid = getNewID(dev);
2026 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2028 swf_ShapeNew(&shape);
2029 int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1);
2030 swf_SetU16(i->tag, myshapeid);
2031 SRECT r = gfxline_getSWFbbox(line);
2032 swf_SetRect(i->tag,&r);
2033 swf_SetShapeStyles(i->tag,shape);
2034 swf_ShapeCountBits(shape,NULL,NULL);
2035 swf_SetShapeBits(i->tag,shape);
2036 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2037 i->swflastx = i->swflasty = UNDEFINED_COORD;
2038 drawgfxline(dev, line);
2039 swf_ShapeSetEnd(i->tag);
2040 swf_ShapeFree(shape);
2042 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2043 CXFORM cxform2 = gfxcxform_to_cxform(cxform);
2044 swf_ObjectPlace(i->tag,myshapeid,getNewDepth(dev),&i->page_matrix,&cxform2,NULL);
2047 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
2049 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2054 if(i->clippos >= 127)
2056 msg("<warning> Too many clip levels.");
2060 int myshapeid = getNewID(dev);
2061 i->tag = swf_InsertTag(i->tag,ST_DEFINESHAPE);
2063 memset(&col, 0, sizeof(RGBA));
2065 swf_ShapeNew(&shape);
2066 int fsid = swf_ShapeAddSolidFillStyle(shape,&col);
2067 swf_SetU16(i->tag,myshapeid);
2068 SRECT r = gfxline_getSWFbbox(line);
2069 swf_SetRect(i->tag,&r);
2070 swf_SetShapeStyles(i->tag,shape);
2071 swf_ShapeCountBits(shape,NULL,NULL);
2072 swf_SetShapeBits(i->tag,shape);
2073 swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0);
2074 i->swflastx = i->swflasty = UNDEFINED_COORD;
2075 drawgfxline(dev, line);
2076 swf_ShapeSetEnd(i->tag);
2077 swf_ShapeFree(shape);
2079 /* TODO: remember the bbox, and check all shapes against it */
2081 i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2);
2082 i->cliptags[i->clippos] = i->tag;
2083 i->clipshapes[i->clippos] = myshapeid;
2084 i->clipdepths[i->clippos] = getNewDepth(dev);
2088 static void swf_endclip(gfxdevice_t*dev)
2090 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2097 msg("<error> Invalid end of clipping region");
2101 /*swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,
2102 / * clip to depth: * / i->depth <= i->clipdepths[i->clippos]? i->depth : i->depth - 1);
2104 swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth);
2106 static int gfxline_type(gfxline_t*line)
2112 int haszerosegments=0;
2114 if(line->type == gfx_moveTo) {
2117 } else if(line->type == gfx_lineTo) {
2121 } else if(line->type == gfx_splineTo) {
2123 if(tmpsplines>lines)
2128 if(lines==0 && splines==0) return 0;
2129 else if(lines==1 && splines==0) return 1;
2130 else if(lines==0 && splines==1) return 2;
2131 else if(splines==0) return 3;
2135 static int gfxline_has_dots(gfxline_t*line)
2142 if(line->type == gfx_moveTo) {
2143 if(isline && dist < 1) {
2148 } else if(line->type == gfx_lineTo) {
2149 dist += fabs(line->x - x) + fabs(line->y - y);
2151 } else if(line->type == gfx_splineTo) {
2152 dist += fabs(line->sx - x) + fabs(line->sy - y) +
2153 fabs(line->x - line->sx) + fabs(line->y - line->sy);
2160 if(isline && dist < 1) {
2166 static int gfxline_fix_short_edges(gfxline_t*line)
2170 if(line->type == gfx_lineTo) {
2171 if(fabs(line->x - x) + fabs(line->y - y) < 0.01) {
2174 } else if(line->type == gfx_splineTo) {
2175 if(fabs(line->sx - x) + fabs(line->sy - y) +
2176 fabs(line->x - line->sx) + fabs(line->y - line->sy) < 0.01) {
2187 static char is_inside_page(gfxdevice_t*dev, gfxcoord_t x, gfxcoord_t y)
2189 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2190 if(x<i->min_x || x>i->max_x) return 0;
2191 if(y<i->min_y || y>i->max_y) return 0;
2195 static void show_path(ArtSVP*path)
2198 printf("Segments: %d\n", path->n_segs);
2199 for(t=0;t<path->n_segs;t++) {
2200 ArtSVPSeg* seg = &path->segs[t];
2201 printf("Segment %d: %d points, %s, BBox: (%f,%f,%f,%f)\n",
2202 t, seg->n_points, seg->dir==0?"UP ":"DOWN",
2203 seg->bbox.x0, seg->bbox.y0, seg->bbox.x1, seg->bbox.y1);
2205 for(p=0;p<seg->n_points;p++) {
2206 ArtPoint* point = &seg->points[p];
2207 printf(" (%f,%f)\n", point->x, point->y);
2213 gfxline_t* gfxline_move(gfxline_t*line, double x, double y)
2215 gfxline_t*l = line = gfxline_clone(line);
2227 //#define NORMALIZE_POLYGON_POSITIONS
2229 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)
2231 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2232 int type = gfxline_type(line);
2233 int has_dots = gfxline_has_dots(line);
2234 gfxbbox_t r = gfxline_getbbox(line);
2235 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2237 /* TODO: * split line into segments, and perform this check for all segments */
2240 (width <= i->config_caplinewidth
2241 || (cap_style == gfx_capRound && joint_style == gfx_joinRound)
2242 || (cap_style == gfx_capRound && type<=2))) {} else
2244 /* convert line to polygon */
2245 msg("<trace> draw as polygon, type=%d dots=%d", type, has_dots);
2247 gfxline_fix_short_edges(line);
2248 /* we need to convert the line into a polygon */
2249 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
2250 gfxline_t*gfxline = SVPtogfxline(svp);
2251 dev->fill(dev, gfxline, color);
2257 msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
2260 #ifdef NORMALIZE_POLYGON_POSITIONS
2262 double startx = 0, starty = 0;
2263 if(line && line->type == gfx_moveTo) {
2267 line = gfxline_move(line, -startx, -starty);
2268 i->shapeposx = (int)(startx*20);
2269 i->shapeposy = (int)(starty*20);
2272 swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a);
2273 swfoutput_setlinewidth(dev, width);
2276 drawgfxline(dev, line);
2278 #ifdef NORMALIZE_POLYGON_POSITIONS
2279 free(line); //account for _move
2283 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
2285 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2286 gfxbbox_t r = gfxline_getbbox(line);
2287 int is_outside_page = !is_inside_page(dev, r.xmin, r.ymin) || !is_inside_page(dev, r.xmax, r.ymax);
2290 if(!i->config_ignoredraworder)
2293 #ifdef NORMALIZE_POLYGON_POSITIONS
2295 double startx = 0, starty = 0;
2296 if(line && line->type == gfx_moveTo) {
2300 line = gfxline_move(line, -startx, -starty);
2301 i->shapeposx = (int)(startx*20);
2302 i->shapeposy = (int)(starty*20);
2305 swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a);
2309 drawgfxline(dev, line);
2310 msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
2312 #ifdef NORMALIZE_POLYGON_POSITIONS
2313 free(line); //account for _move
2316 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
2318 msg("<error> Gradient filling not implemented yet");
2321 static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
2323 SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
2325 SRECT bounds = {0,0,0,0};
2327 swffont->version = 2;
2328 swffont->name = (U8*)strdup(id);
2329 swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
2330 swffont->layout->ascent = 0; /* ? */
2331 swffont->layout->descent = 0;
2332 swffont->layout->leading = 0;
2333 swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
2334 swffont->encoding = FONT_ENCODING_UNICODE;
2335 swffont->numchars = font->num_glyphs;
2336 swffont->maxascii = font->max_unicode;
2337 swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
2338 swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
2339 swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
2340 swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
2341 for(t=0;t<font->max_unicode;t++) {
2342 swffont->ascii2glyph[t] = font->unicode2glyph[t];
2344 for(t=0;t<font->num_glyphs;t++) {
2347 swffont->glyph2ascii[t] = font->glyphs[t].unicode;
2348 if(font->glyphs[t].name) {
2349 swffont->glyphnames[t] = strdup(font->glyphs[t].name);
2351 swffont->glyphnames[t] = 0;
2353 swffont->glyph[t].advance = (int)(font->glyphs[t].advance * 20);
2355 swf_Shape01DrawerInit(&draw, 0);
2356 line = font->glyphs[t].line;
2359 c.x = line->sx; c.y = line->sy;
2360 to.x = line->x; to.y = line->y;
2361 if(line->type == gfx_moveTo) {
2362 draw.moveTo(&draw, &to);
2363 } else if(line->type == gfx_lineTo) {
2364 draw.lineTo(&draw, &to);
2365 } else if(line->type == gfx_splineTo) {
2366 draw.splineTo(&draw, &c, &to);
2371 swffont->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
2372 swffont->layout->bounds[t] = swf_ShapeDrawerGetBBox(&draw);
2373 draw.dealloc(&draw);
2375 swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
2377 if(bounds.ymin < 0 && bounds.ymax > 0) {
2378 swffont->layout->ascent = -bounds.ymin;
2379 swffont->layout->descent = bounds.ymax;
2380 swffont->layout->leading = bounds.ymax - bounds.ymin;
2382 swffont->layout->ascent = (bounds.ymax - bounds.ymin)/2;
2383 swffont->layout->descent = (bounds.ymax - bounds.ymin)/2;
2384 swffont->layout->leading = bounds.ymax - bounds.ymin;
2390 static void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font)
2392 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2394 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2395 return; // the requested font is the current font
2397 fontlist_t*last=0,*l = i->fontlist;
2400 if(!strcmp((char*)l->swffont->name, fontid)) {
2401 return; // we already know this font
2405 l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
2406 l->swffont = gfxfont_to_swffont(font, fontid);
2413 swf_FontSetID(l->swffont, getNewID(i->dev));
2415 if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
2417 // print font information
2418 msg("<debug> Font %s",fontid);
2419 msg("<debug> | ID: %d", l->swffont->id);
2420 msg("<debug> | Version: %d", l->swffont->version);
2421 msg("<debug> | Name: %s", l->swffont->name);
2422 msg("<debug> | Numchars: %d", l->swffont->numchars);
2423 msg("<debug> | Maxascii: %d", l->swffont->maxascii);
2424 msg("<debug> | Style: %d", l->swffont->style);
2425 msg("<debug> | Encoding: %d", l->swffont->encoding);
2426 for(iii=0; iii<l->swffont->numchars;iii++) {
2427 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,
2428 l->swffont->layout->bounds[iii].xmin/20.0,
2429 l->swffont->layout->bounds[iii].ymin/20.0,
2430 l->swffont->layout->bounds[iii].xmax/20.0,
2431 l->swffont->layout->bounds[iii].ymax/20.0
2434 for(t=0;t<l->swffont->maxascii;t++) {
2435 if(l->swffont->ascii2glyph[t] == iii)
2436 msg("<debug> | - maps to %d",t);
2442 static void swf_switchfont(gfxdevice_t*dev, char*fontid)
2444 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2446 if(i->swffont && i->swffont->name && !strcmp((char*)i->swffont->name,fontid))
2447 return; // the requested font is the current font
2449 fontlist_t*l = i->fontlist;
2451 if(!strcmp((char*)l->swffont->name, fontid)) {
2452 i->swffont = l->swffont;
2457 msg("<error> Unknown font id: %s", fontid);
2461 static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
2463 swfoutput_internal*i = (swfoutput_internal*)dev->internal;
2465 if(!i->swffont || !i->swffont->name || strcmp((char*)i->swffont->name,fontid)) // not equal to current font
2467 /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
2468 with multiple fonts */
2471 swf_switchfont(dev, fontid); // set the current font
2473 swfoutput_setfontmatrix(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
2483 /* printf("%f %f\n", m.m31, m.m32);
2485 static int xpos = 40;
2486 static int ypos = 200;
2493 drawchar(dev, i->swffont, glyph, &m, color);