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 "swfoutput.h"
27 #include "../lib/log.h"
28 #include "../lib/rfxswf.h"
30 #define standardEncodingSize 335
31 extern char *standardEncodingNames[standardEncodingSize];
34 int ignoredraworder=0;
37 static int flag_protected = 0;
39 typedef unsigned char u8;
40 typedef unsigned short int u16;
41 typedef unsigned long int u32;
44 static char* filename = 0;
47 static int currentswfid = 0;
49 static int startdepth = 1;
52 static int shapeid = -1;
53 static int textid = -1;
55 static int drawmode = -1;
56 static char storefont = 0;
57 static int fillstyleid;
58 static int linestyleid;
59 static int swflastx=0;
60 static int swflasty=0;
61 static int lastwasfill = 0;
73 void startshape(struct swfoutput* obj);
74 void starttext(struct swfoutput* obj);
78 // matrix multiplication. changes p0
79 void transform (plotxy*p0,struct swfmatrix*m)
82 x = m->m11*p0->x+m->m12*p0->y;
83 y = m->m21*p0->x+m->m22*p0->y;
88 // write a move-to command into the swf
89 void moveto(TAG*tag, plotxy p0)
91 int rx = (int)(p0.x*20);
92 int ry = (int)(p0.y*20);
93 if(rx!=swflastx || ry!=swflasty) {
94 swf_ShapeSetMove (tag, shape, rx,ry);
100 // write a line-to command into the swf
101 void lineto(TAG*tag, plotxy p0)
103 int rx = ((int)(p0.x*20)-swflastx);
104 int ry = ((int)(p0.y*20)-swflasty);
105 /* we can't skip this for rx=0,ry=0, those
107 swf_ShapeSetLine (tag, shape, rx,ry);
112 // write a spline-to command into the swf
113 void splineto(TAG*tag, plotxy control,plotxy end)
115 int cx = ((int)(control.x*20)-swflastx);
116 int cy = ((int)(control.y*20)-swflasty);
119 int ex = ((int)(end.x*20)-swflastx);
120 int ey = ((int)(end.y*20)-swflasty);
123 swf_ShapeSetCurve(tag, shape, cx,cy,ex,ey);
126 /* write a line, given two points and the transformation
128 void line(TAG*tag, plotxy p0, plotxy p1, struct swfmatrix*m)
136 /* write a cubic (!) spline. This involves calling the approximate()
137 function out of spline.cc to convert it to a quadratic spline. */
138 void spline(TAG*tag,plotxy p0,plotxy p1,plotxy p2,plotxy p3,struct swfmatrix*m)
141 struct qspline q[16];
149 num = approximate(p0,p1,p2,p3,q);
151 moveto(tag,q[t].start);
152 splineto(tag,q[t].control, q[t].end);
156 /* draw a T1 outline. These are generated by pdf2swf and by t1lib.
157 (representing characters) */
158 void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m)
160 if(tag->id != ST_DEFINEFONT &&
161 tag->id != ST_DEFINESHAPE &&
162 tag->id != ST_DEFINESHAPE2 &&
163 tag->id != ST_DEFINESHAPE3)
165 logf("<error> internal error: drawpath needs a shape tag, not %d\n",tag->id);
171 double lastx=0,lasty=0;
172 double firstx=0,firsty=0;
177 x += (outline->dest.x/(float)0xffff);
178 y += (outline->dest.y/(float)0xffff);
179 if(outline->type == T1_PATHTYPE_MOVE)
181 if(((int)(lastx*20) != (int)(firstx*20) ||
182 (int)(lasty*20) != (int)(firsty*20)) &&
191 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
192 line(tag, p0, p1, m);
198 else if(outline->type == T1_PATHTYPE_LINE)
206 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
209 else if(outline->type == T1_PATHTYPE_BEZIER)
215 T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
218 p1.x=o2->C.x/(float)0xffff+lastx;
219 p1.y=o2->C.y/(float)0xffff+lasty;
220 p2.x=o2->B.x/(float)0xffff+lastx;
221 p2.y=o2->B.y/(float)0xffff+lasty;
224 if(log) printf("spline: %f,%f -> %f,%f\n",p3.x,p3.y,p0.x,p0.y);
225 spline(tag,p0,p1,p2,p3,m);
228 logf("<error> drawpath: unknown outline type:%d\n", outline->type);
232 outline = outline->link;
234 if(((int)(lastx*20) != (int)(firstx*20) ||
235 (int)(lasty*20) != (int)(firsty*20)) &&
244 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
245 line(tag, p0, p1, m);
249 int colorcompare(RGBA*a,RGBA*b)
261 static const int CHARDATAMAX = 1024;
269 } chardata[CHARDATAMAX];
272 void putcharacters(TAG*tag)
277 color.r = chardata[0].color.r^255;
286 int charadvance[128];
289 int glyphbits=1; //TODO: can this be zero?
292 if(tag->id != ST_DEFINETEXT &&
293 tag->id != ST_DEFINETEXT2) {
294 logf("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
298 logf("<warning> putcharacters called with zero characters");
301 for(pass = 0; pass < 2; pass++)
311 advancebits++; // add sign bit
312 swf_SetU8(tag, glyphbits);
313 swf_SetU8(tag, advancebits);
316 for(t=0;t<=chardatapos;t++)
318 if(lastfontid != chardata[t].fontid ||
319 lastx!=chardata[t].x ||
320 lasty!=chardata[t].y ||
321 !colorcompare(&color, &chardata[t].color) ||
323 lastsize != chardata[t].size ||
326 if(charstorepos && pass==0)
329 for(s=0;s<charstorepos;s++)
331 while(charids[s]>=(1<<glyphbits))
333 while(charadvance[s]>=(1<<advancebits))
337 if(charstorepos && pass==1)
339 tag->writeBit = 0; // Q&D
340 swf_SetBits(tag, 0, 1); // GLYPH Record
341 swf_SetBits(tag, charstorepos, 7); // number of glyphs
343 for(s=0;s<charstorepos;s++)
345 swf_SetBits(tag, charids[s], glyphbits);
346 swf_SetBits(tag, charadvance[s], advancebits);
351 if(pass == 1 && t<chardatapos)
357 if(lastx != chardata[t].x ||
358 lasty != chardata[t].y)
363 if(!colorcompare(&color, &chardata[t].color))
365 color = chardata[t].color;
368 font.id = chardata[t].fontid;
369 if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
372 tag->writeBit = 0; // Q&D
373 swf_TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
376 lastfontid = chardata[t].fontid;
377 lastx = chardata[t].x;
378 lasty = chardata[t].y;
379 lastsize = chardata[t].size;
386 int nextt = t==chardatapos-1?t:t+1;
387 int rel = chardata[nextt].x-chardata[t].x;
388 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
390 lastx=chardata[nextt].x;
396 charids[charstorepos] = chardata[t].charid;
397 charadvance[charstorepos] = advance;
404 void putcharacter(struct swfoutput*obj, int fontid, int charid,
405 int x,int y, int size)
407 if(chardatapos == CHARDATAMAX)
412 chardata[chardatapos].fontid = fontid;
413 chardata[chardatapos].charid = charid;
414 chardata[chardatapos].x = x;
415 chardata[chardatapos].y = y;
416 chardata[chardatapos].color = obj->fillrgb;
417 chardata[chardatapos].size = size;
422 /* process a character. */
423 void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m)
426 if(m->m12!=0 || m->m21!=0)
431 if(usefonts && ! drawonlyshapes)
433 int charid = font->getSWFCharID(character);
438 putcharacter(obj, font->swfid, charid,(int)(m->m13*20),(int)(m->m23*20),
439 (int)(m->m11*20/2+0.5)); //where does the /2 come from?
443 T1_OUTLINE*outline = font->getOutline(character);
444 char* charname = character;
447 logf("<warning> Didn't find %s in current charset (%s)",
448 character,font->getName());
464 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
469 drawpath(tag, outline, &m2);
474 /* draw a curved polygon. */
475 void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline,
483 if(lastwasfill && !fill)
485 swf_ShapeSetStyle(tag,shape,linestyleid,0x8000,0);
488 if(!lastwasfill && fill)
490 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
494 drawpath(tag, outline,m);
497 /* SWFFont: copy all t1 font outlines to a local
499 SWFFont::SWFFont(char*name, int id, char*filename)
501 if(!T1_GetFontName(id))
504 this->name = strdup(T1_GetFontFileName(id));
505 this->fontid = strdup(name);
508 char**a= T1_GetAllCharNames(id);
509 int t=0, outlinepos=0;
517 logf("<verbose> Font %s(%d): Storing %d outlines.\n", name, id, t);
519 outline = (T1_OUTLINE**)malloc(t*sizeof(T1_OUTLINE*));
520 charname = (char**)malloc(t*sizeof(char*));
521 used = (char*)malloc(t*sizeof(char));
522 char2swfcharid = (U16*)malloc(t*2);
523 swfcharid2char = (U16*)malloc(t*2);
526 memset(used,0,t*sizeof(char));
528 this->swfid = ++currentswfid;
542 int ret = T1_ReencodeFont(id, map);
546 int ret = T1_ReencodeFont(id, map);
548 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
554 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
555 this->charname[outlinepos] = strdup(T1_GetCharName(id, s));
563 /* free all tables, write out definefont tags */
567 int*ptr = (int*)malloc(swfcharpos*sizeof(int));
569 for(t=0;t<charnum;t++)
570 if(used[t]) usednum++;
572 if(usednum && !drawonlyshapes)
574 logf("<verbose> Font %s has %d used characters",fontid, usednum);
575 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
576 swf_SetU16(ftag, this->swfid);
577 int initpos = swf_GetDataSize(ftag);
583 for(t=0;t<swfcharpos;t++)
585 ptr[t] = swf_GetDataSize(ftag);
586 swf_SetU16(ftag, 0x1234);
588 for(t=0;t<swfcharpos;t++)
590 *(U16*)&ftag->data[ptr[t]] = swf_GetDataSize(ftag)-initpos;
593 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
597 swf_ShapeSetStyle(ftag,&s,0,1,0);
601 drawpath(ftag, outline[swfcharid2char[t]],&m);
604 swf_ShapeSetEnd(ftag);
606 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
607 swf_SetU16(ftag, this->swfid);
608 swf_SetU8(ftag, strlen(this->fontid));
609 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
611 for(t=0;t<swfcharpos;t++)
614 char * name = this->charname[this->swfcharid2char[t]];
616 if(standardEncodingNames[s] &&
617 !strcasecmp(name,standardEncodingNames[s]))
620 swf_SetU8(ftag, (U8)s);
626 for(t=0;t<charnum;t++)
630 free(swfcharid2char);
631 free(char2swfcharid);
634 T1_OUTLINE*SWFFont::getOutline(char*name)
637 for(t=0;t<this->charnum;t++) {
638 if(!strcmp(this->charname[t],name)) {
641 swfcharid2char[swfcharpos] = t;
642 char2swfcharid[t] = swfcharpos;
652 int SWFFont::getSWFCharID(char*name)
655 for(t=0;t<this->charnum;t++) {
656 if(!strcmp(this->charname[t],name)) {
659 swfcharid2char[swfcharpos] = t;
660 char2swfcharid[t] = swfcharpos++;
663 return char2swfcharid[t];
666 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
670 char*SWFFont::getName()
681 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
682 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
684 fontlist_t*last=0,*iterator;
685 if(obj->font && !strcmp(obj->font->fontid,fontid))
690 if(!strcmp(iterator->font->fontid,fontid))
693 iterator = iterator->next;
697 obj->font = iterator->font;
702 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
705 SWFFont*font = new SWFFont(fontid, t1id, filename);
706 iterator = new fontlist_t;
707 iterator->font = font;
711 last->next = iterator;
717 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
719 fontlist_t *iterator = fontlist;
721 if(!strcmp(iterator->font->fontid,fontid))
723 iterator = iterator->next;
728 /* set's the matrix which is to be applied to characters drawn by
729 swfoutput_drawchar() */
730 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
731 double m21,double m22)
733 if(obj->fontm11 == m11 &&
734 obj->fontm12 == m12 &&
735 obj->fontm21 == m21 &&
746 /* draws a character at x,y. */
747 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character)
750 m.m11 = obj->fontm11;
751 m.m12 = obj->fontm12;
752 m.m21 = obj->fontm21;
753 m.m22 = obj->fontm22;
756 drawchar(obj, obj->font, character, &m);
759 /* initialize the swf writer */
760 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
765 memset(obj, 0, sizeof(struct swfoutput));
766 filename = _filename;
770 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
774 memset(&swf,0x00,sizeof(SWF));
777 swf.frameRate = 0x0040; // 1 frame per 4 seconds
778 swf.movieSize.xmax = 20*sizex;
779 swf.movieSize.ymax = 20*sizey;
781 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
786 swf_SetRGB(tag,&rgb);
787 if(flag_protected) // good practice! /r
788 tag = swf_InsertTag(tag, ST_PROTECT);
793 void swfoutput_setprotected() //write PROTECT tag
798 void startshape(struct swfoutput*obj)
806 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
808 swf_ShapeNew(&shape);
809 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
810 rgb.r = obj->fillrgb.r;
811 rgb.g = obj->fillrgb.g;
812 rgb.b = obj->fillrgb.b;
813 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
815 shapeid = ++currentswfid;
816 swf_SetU16(tag,shapeid); // ID
825 swf_SetShapeStyles(tag,shape);
826 swf_ShapeCountBits(shape,NULL,NULL);
827 swf_SetShapeBits(tag,shape);
829 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
834 void starttext(struct swfoutput*obj)
840 tag = swf_InsertTag(tag,ST_DEFINETEXT);
841 textid = ++currentswfid;
842 swf_SetU16(tag, textid);
858 swf_SetMatrix(tag,&m);
866 swf_ShapeSetEnd(tag);
867 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
868 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
878 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
879 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
883 void endpage(struct swfoutput*obj)
890 swfoutput_endclip(obj);
891 tag = swf_InsertTag(tag,ST_SHOWFRAME);
894 void swfoutput_newpage(struct swfoutput*obj)
898 for(depth--;depth>=startdepth;depth--) {
899 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
900 swf_SetU16(tag,depth);
907 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
908 up, complete the swf, and write it out. */
909 void swfoutput_destroy(struct swfoutput* obj)
912 fontlist_t *tmp,*iterator = fontlist;
914 delete iterator->font;
917 iterator = iterator->next;
925 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
930 logf("<fatal> Could not create \"%s\". ", filename);
934 tag = swf_InsertTag(tag,ST_END);
936 if FAILED(swf_WriteSWF(fi,&swf))
937 logf("<error> WriteSWF() failed.\n");
940 logf("<notice> SWF written\n");
943 void swfoutput_setdrawmode(swfoutput* obj, int mode)
946 if(mode == DRAWMODE_FILL)
948 else if(mode == DRAWMODE_EOFILL)
950 else if(mode == DRAWMODE_STROKE)
952 else if(mode == DRAWMODE_CLIP)
954 else if(mode == DRAWMODE_EOCLIP)
958 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
960 if(obj->fillrgb.r == r &&
961 obj->fillrgb.g == g &&
962 obj->fillrgb.b == b &&
963 obj->fillrgb.a == a) return;
973 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
975 if(obj->strokergb.r == r &&
976 obj->strokergb.g == g &&
977 obj->strokergb.b == b &&
978 obj->strokergb.a == a) return;
982 obj->strokergb.r = r;
983 obj->strokergb.g = g;
984 obj->strokergb.b = b;
985 obj->strokergb.a = a;
988 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
990 if(obj->linewidth == (u16)(linewidth*20))
995 obj->linewidth = (u16)(linewidth*20);
999 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1008 logf("<warning> Too many clip levels.");
1013 int olddrawmode = drawmode;
1014 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1015 swfoutput_drawpath(obj, outline, m);
1016 swf_ShapeSetEnd(tag);
1017 swfoutput_setdrawmode(obj, olddrawmode);
1019 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1020 cliptags[clippos] = tag;
1021 clipshapes[clippos] = shapeid;
1022 clipdepths[clippos] = depth++;
1027 void swfoutput_endclip(swfoutput*obj)
1035 logf("<error> Invalid end of clipping region");
1039 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1042 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1044 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1053 actions = swf_ActionStart();
1055 action_GetUrl(url, "_parent");
1057 action_GetUrl(url, "_this");
1061 drawlink(obj, actions, points);
1063 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1072 actions = swf_ActionStart();
1073 action_GotoFrame(page);
1077 drawlink(obj, actions, points);
1080 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1086 struct plotxy p1,p2,p3,p4;
1090 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1092 int buttonid = ++currentswfid;
1095 if(points[t].x>xmax) xmax=points[t].x;
1096 if(points[t].y>ymax) ymax=points[t].y;
1097 if(points[t].x<xmin) xmin=points[t].x;
1098 if(points[t].y<ymin) ymin=points[t].y;
1100 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1101 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1104 myshapeid = ++currentswfid;
1105 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1106 swf_ShapeNew(&shape);
1107 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1108 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1109 swf_SetU16(tag, myshapeid);
1110 r.xmin = (int)(xmin*20);
1111 r.ymin = (int)(ymin*20);
1112 r.xmax = (int)(xmax*20);
1113 r.ymax = (int)(ymax*20);
1114 swf_SetRect(tag,&r);
1115 swf_SetShapeStyles(tag,shape);
1116 swf_ShapeCountBits(shape,NULL,NULL);
1117 swf_SetShapeBits(tag,shape);
1118 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1119 swflastx = swflasty = 0;
1125 swf_ShapeSetEnd(tag);
1128 myshapeid2 = ++currentswfid;
1129 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1130 swf_ShapeNew(&shape);
1131 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1133 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1134 swf_SetU16(tag, myshapeid2);
1135 r.xmin = (int)(xmin*20);
1136 r.ymin = (int)(ymin*20);
1137 r.xmax = (int)(xmax*20);
1138 r.ymax = (int)(ymax*20);
1139 swf_SetRect(tag,&r);
1140 swf_SetShapeStyles(tag,shape);
1141 swf_ShapeCountBits(shape,NULL,NULL);
1142 swf_SetShapeBits(tag,shape);
1143 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1144 swflastx = swflasty = 0;
1150 swf_ShapeSetEnd(tag);
1152 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1153 swf_SetU16(tag,buttonid); //id
1154 swf_ButtonSetFlags(tag, 0); //menu=no
1155 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1156 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1157 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1158 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1160 swf_SetActions(tag,actions);
1163 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1164 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1167 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1168 double x1,double y1,
1169 double x2,double y2,
1170 double x3,double y3,
1171 double x4,double y4)
1177 struct plotxy p1,p2,p3,p4;
1179 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1180 if(x2>xmax) xmax=x2;
1181 if(y2>ymax) ymax=y2;
1182 if(x2<xmin) xmin=x2;
1183 if(y2<ymin) ymin=y2;
1184 if(x3>xmax) xmax=x3;
1185 if(y3>ymax) ymax=y3;
1186 if(x3<xmin) xmin=x3;
1187 if(y3<ymin) ymin=y3;
1188 if(x4>xmax) xmax=x4;
1189 if(y4>ymax) ymax=y4;
1190 if(x4<xmin) xmin=x4;
1191 if(y4<ymin) ymin=y4;
1202 m.sx = (int)(65536*20*(x4-x1))/sizex;
1203 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1204 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1205 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1207 m.tx = (int)(x1*20);
1208 m.ty = (int)(y1*20);
1211 myshapeid = ++currentswfid;
1212 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1213 swf_ShapeNew(&shape);
1214 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1215 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1216 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1217 swf_SetU16(tag, myshapeid);
1218 r.xmin = (int)(xmin*20);
1219 r.ymin = (int)(ymin*20);
1220 r.xmax = (int)(xmax*20);
1221 r.ymax = (int)(ymax*20);
1222 swf_SetRect(tag,&r);
1223 swf_SetShapeStyles(tag,shape);
1224 swf_ShapeCountBits(shape,NULL,NULL);
1225 swf_SetShapeBits(tag,shape);
1226 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1227 swflastx = swflasty = 0;
1234 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1235 ShapeSetLine (tag, shape, (int)(x1*20);
1236 ShapeSetLine (tag, shape, x*20,0);
1237 ShapeSetLine (tag, shape, 0,-y*20);
1238 ShapeSetLine (tag, shape, -x*20,0);*/
1239 swf_ShapeSetEnd(tag);
1242 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1243 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1246 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1247 double x1,double y1,
1248 double x2,double y2,
1249 double x3,double y3,
1250 double x4,double y4)
1257 int bitid = ++currentswfid;
1258 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1259 swf_SetU16(tag, bitid);
1260 swf_SetJPEGBits(tag, filename, jpegquality);
1262 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1266 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1267 double x1,double y1,
1268 double x2,double y2,
1269 double x3,double y3,
1270 double x4,double y4)
1277 int bitid = ++currentswfid;
1278 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1279 swf_SetU16(tag, bitid);
1280 swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT);
1282 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1286 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1287 double x1,double y1,
1288 double x2,double y2,
1289 double x3,double y3,
1290 double x4,double y4)
1297 int bitid = ++currentswfid;
1298 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1299 swf_SetU16(tag, bitid);
1300 swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256);
1302 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1306 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1307 double x1,double y1,
1308 double x2,double y2,
1309 double x3,double y3,
1310 double x4,double y4)
1317 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);