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 int storeallcharacters=0;
38 static int flag_protected = 0;
40 typedef unsigned char u8;
41 typedef unsigned short int u16;
42 typedef unsigned long int u32;
45 static char* filename = 0;
48 static int currentswfid = 0;
50 static int startdepth = 1;
53 static int shapeid = -1;
54 static int textid = -1;
56 static int drawmode = -1;
57 static char storefont = 0;
58 static int fillstyleid;
59 static int linestyleid;
60 static int swflastx=0;
61 static int swflasty=0;
62 static int lastwasfill = 0;
74 void startshape(struct swfoutput* obj);
75 void starttext(struct swfoutput* obj);
79 // matrix multiplication. changes p0
80 void transform (plotxy*p0,struct swfmatrix*m)
83 x = m->m11*p0->x+m->m12*p0->y;
84 y = m->m21*p0->x+m->m22*p0->y;
89 // write a move-to command into the swf
90 void moveto(TAG*tag, plotxy p0)
92 int rx = (int)(p0.x*20);
93 int ry = (int)(p0.y*20);
94 if(rx!=swflastx || ry!=swflasty) {
95 swf_ShapeSetMove (tag, shape, rx,ry);
101 // write a line-to command into the swf
102 void lineto(TAG*tag, plotxy p0)
104 int rx = ((int)(p0.x*20)-swflastx);
105 int ry = ((int)(p0.y*20)-swflasty);
106 /* we can't skip this for rx=0,ry=0, those
108 swf_ShapeSetLine (tag, shape, rx,ry);
113 // write a spline-to command into the swf
114 void splineto(TAG*tag, plotxy control,plotxy end)
116 int cx = ((int)(control.x*20)-swflastx);
117 int cy = ((int)(control.y*20)-swflasty);
120 int ex = ((int)(end.x*20)-swflastx);
121 int ey = ((int)(end.y*20)-swflasty);
124 swf_ShapeSetCurve(tag, shape, cx,cy,ex,ey);
127 /* write a line, given two points and the transformation
129 void line(TAG*tag, plotxy p0, plotxy p1, struct swfmatrix*m)
137 /* write a cubic (!) spline. This involves calling the approximate()
138 function out of spline.cc to convert it to a quadratic spline. */
139 void spline(TAG*tag,plotxy p0,plotxy p1,plotxy p2,plotxy p3,struct swfmatrix*m)
142 struct qspline q[16];
150 num = approximate(p0,p1,p2,p3,q);
152 moveto(tag,q[t].start);
153 splineto(tag,q[t].control, q[t].end);
157 /* draw a T1 outline. These are generated by pdf2swf and by t1lib.
158 (representing characters) */
159 void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m)
161 if(tag->id != ST_DEFINEFONT &&
162 tag->id != ST_DEFINESHAPE &&
163 tag->id != ST_DEFINESHAPE2 &&
164 tag->id != ST_DEFINESHAPE3)
166 logf("<error> internal error: drawpath needs a shape tag, not %d\n",tag->id);
172 double lastx=0,lasty=0;
173 double firstx=0,firsty=0;
178 x += (outline->dest.x/(float)0xffff);
179 y += (outline->dest.y/(float)0xffff);
180 if(outline->type == T1_PATHTYPE_MOVE)
182 if(((int)(lastx*20) != (int)(firstx*20) ||
183 (int)(lasty*20) != (int)(firsty*20)) &&
192 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
193 line(tag, p0, p1, m);
199 else if(outline->type == T1_PATHTYPE_LINE)
207 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
210 else if(outline->type == T1_PATHTYPE_BEZIER)
216 T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
219 p1.x=o2->C.x/(float)0xffff+lastx;
220 p1.y=o2->C.y/(float)0xffff+lasty;
221 p2.x=o2->B.x/(float)0xffff+lastx;
222 p2.y=o2->B.y/(float)0xffff+lasty;
225 if(log) printf("spline: %f,%f -> %f,%f\n",p3.x,p3.y,p0.x,p0.y);
226 spline(tag,p0,p1,p2,p3,m);
229 logf("<error> drawpath: unknown outline type:%d\n", outline->type);
233 outline = outline->link;
235 if(((int)(lastx*20) != (int)(firstx*20) ||
236 (int)(lasty*20) != (int)(firsty*20)) &&
245 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
246 line(tag, p0, p1, m);
250 int colorcompare(RGBA*a,RGBA*b)
262 static const int CHARDATAMAX = 1024;
270 } chardata[CHARDATAMAX];
273 void putcharacters(TAG*tag)
278 color.r = chardata[0].color.r^255;
287 int charadvance[128];
290 int glyphbits=1; //TODO: can this be zero?
293 if(tag->id != ST_DEFINETEXT &&
294 tag->id != ST_DEFINETEXT2) {
295 logf("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
299 logf("<warning> putcharacters called with zero characters");
302 for(pass = 0; pass < 2; pass++)
312 advancebits++; // add sign bit
313 swf_SetU8(tag, glyphbits);
314 swf_SetU8(tag, advancebits);
317 for(t=0;t<=chardatapos;t++)
319 if(lastfontid != chardata[t].fontid ||
320 lastx!=chardata[t].x ||
321 lasty!=chardata[t].y ||
322 !colorcompare(&color, &chardata[t].color) ||
324 lastsize != chardata[t].size ||
327 if(charstorepos && pass==0)
330 for(s=0;s<charstorepos;s++)
332 while(charids[s]>=(1<<glyphbits))
334 while(charadvance[s]>=(1<<advancebits))
338 if(charstorepos && pass==1)
340 tag->writeBit = 0; // Q&D
341 swf_SetBits(tag, 0, 1); // GLYPH Record
342 swf_SetBits(tag, charstorepos, 7); // number of glyphs
344 for(s=0;s<charstorepos;s++)
346 swf_SetBits(tag, charids[s], glyphbits);
347 swf_SetBits(tag, charadvance[s], advancebits);
352 if(pass == 1 && t<chardatapos)
358 if(lastx != chardata[t].x ||
359 lasty != chardata[t].y)
364 if(!colorcompare(&color, &chardata[t].color))
366 color = chardata[t].color;
369 font.id = chardata[t].fontid;
370 if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
373 tag->writeBit = 0; // Q&D
374 swf_TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
377 lastfontid = chardata[t].fontid;
378 lastx = chardata[t].x;
379 lasty = chardata[t].y;
380 lastsize = chardata[t].size;
387 int nextt = t==chardatapos-1?t:t+1;
388 int rel = chardata[nextt].x-chardata[t].x;
389 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
391 lastx=chardata[nextt].x;
397 charids[charstorepos] = chardata[t].charid;
398 charadvance[charstorepos] = advance;
405 void putcharacter(struct swfoutput*obj, int fontid, int charid,
406 int x,int y, int size)
408 if(chardatapos == CHARDATAMAX)
413 chardata[chardatapos].fontid = fontid;
414 chardata[chardatapos].charid = charid;
415 chardata[chardatapos].x = x;
416 chardata[chardatapos].y = y;
417 chardata[chardatapos].color = obj->fillrgb;
418 chardata[chardatapos].size = size;
423 /* process a character. */
424 void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m)
427 if(m->m12!=0 || m->m21!=0)
432 if(usefonts && ! drawonlyshapes)
434 int charid = font->getSWFCharID(character);
439 putcharacter(obj, font->swfid, charid,(int)(m->m13*20),(int)(m->m23*20),
440 (int)(m->m11*20/2+0.5)); //where does the /2 come from?
444 T1_OUTLINE*outline = font->getOutline(character);
445 char* charname = character;
448 logf("<warning> Didn't find %s in current charset (%s)",
449 character,font->getName());
465 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
470 drawpath(tag, outline, &m2);
475 /* draw a curved polygon. */
476 void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline,
484 if(lastwasfill && !fill)
486 swf_ShapeSetStyle(tag,shape,linestyleid,0x8000,0);
489 if(!lastwasfill && fill)
491 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
495 drawpath(tag, outline,m);
498 /* SWFFont: copy all t1 font outlines to a local
500 SWFFont::SWFFont(char*name, int id, char*filename)
502 if(!T1_GetFontName(id))
505 this->name = strdup(T1_GetFontFileName(id));
506 this->fontid = strdup(name);
509 char**a= T1_GetAllCharNames(id);
510 int t=0, outlinepos=0;
518 logf("<verbose> Font %s(%d): Storing %d outlines.\n", name, id, t);
520 outline = (T1_OUTLINE**)malloc(t*sizeof(T1_OUTLINE*));
521 charname = (char**)malloc(t*sizeof(char*));
522 width = (int*)malloc(t*sizeof(int));
523 memset(width, 0, t*sizeof(int));
524 memset(charname, 0, t*sizeof(char*));
525 used = (char*)malloc(t*sizeof(char));
526 char2swfcharid = (U16*)malloc(t*2);
527 swfcharid2char = (U16*)malloc(t*2);
530 memset(used,0,t*sizeof(char));
532 this->swfid = ++currentswfid;
546 int ret = T1_ReencodeFont(id, map);
550 int ret = T1_ReencodeFont(id, map);
552 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
558 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
559 this->width[outlinepos] = T1_GetCharWidth(id, s);
560 this->charname[outlinepos] = strdup(T1_GetCharName(id, s));
568 /* free all tables, write out definefont tags */
574 if(storeallcharacters)
577 for(t=0;t<this->charnum;t++)
579 if(this->charname[t])
580 getSWFCharID(this->charname[t]);
584 ptr = (int*)malloc(swfcharpos*sizeof(int));
586 for(t=0;t<charnum;t++)
587 if(used[t]) usednum++;
589 if(usednum && !drawonlyshapes)
591 logf("<verbose> Font %s has %d used characters",fontid, usednum);
592 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
593 swf_SetU16(ftag, this->swfid);
594 int initpos = swf_GetDataSize(ftag);
601 for(t=0;t<swfcharpos;t++)
603 ptr[t] = swf_GetDataSize(ftag);
604 swf_SetU16(ftag, 0x1234);
606 for(t=0;t<swfcharpos;t++)
608 *(U16*)&ftag->data[ptr[t]] = swf_GetDataSize(ftag)-initpos;
611 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
615 swf_ShapeSetStyle(ftag,&s,0,1,0);
619 drawpath(ftag, outline[swfcharid2char[t]],&m);
622 swf_ShapeSetEnd(ftag);
624 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
625 swf_SetU16(ftag, this->swfid);
627 swf_SetU8(ftag, strlen(this->fontid));
628 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
632 swf_SetU8(ftag, 0); //flags
633 for(t=0;t<swfcharpos;t++)
636 char * name = this->charname[this->swfcharid2char[t]];
638 if(standardEncodingNames[s] &&
639 !strcmp(name,standardEncodingNames[s]))
642 swf_SetU8(ftag, (U8)s);
648 for(t=0;t<charnum;t++)
653 free(swfcharid2char);
654 free(char2swfcharid);
657 T1_OUTLINE*SWFFont::getOutline(char*name)
660 for(t=0;t<this->charnum;t++) {
661 if(!strcmp(this->charname[t],name)) {
664 swfcharid2char[swfcharpos] = t;
665 char2swfcharid[t] = swfcharpos;
675 int SWFFont::getSWFCharID(char*name)
678 for(t=0;t<this->charnum;t++) {
679 if(!strcmp(this->charname[t],name)) {
682 swfcharid2char[swfcharpos] = t;
683 char2swfcharid[t] = swfcharpos++;
686 return char2swfcharid[t];
689 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
693 char*SWFFont::getName()
704 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
705 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
707 fontlist_t*last=0,*iterator;
708 if(obj->font && !strcmp(obj->font->fontid,fontid))
713 if(!strcmp(iterator->font->fontid,fontid))
716 iterator = iterator->next;
720 obj->font = iterator->font;
725 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
728 SWFFont*font = new SWFFont(fontid, t1id, filename);
729 iterator = new fontlist_t;
730 iterator->font = font;
734 last->next = iterator;
740 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
742 fontlist_t *iterator = fontlist;
744 if(!strcmp(iterator->font->fontid,fontid))
746 iterator = iterator->next;
751 /* set's the matrix which is to be applied to characters drawn by
752 swfoutput_drawchar() */
753 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
754 double m21,double m22)
756 if(obj->fontm11 == m11 &&
757 obj->fontm12 == m12 &&
758 obj->fontm21 == m21 &&
769 /* draws a character at x,y. */
770 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character)
773 m.m11 = obj->fontm11;
774 m.m12 = obj->fontm12;
775 m.m21 = obj->fontm21;
776 m.m22 = obj->fontm22;
779 drawchar(obj, obj->font, character, &m);
782 /* initialize the swf writer */
783 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
788 memset(obj, 0, sizeof(struct swfoutput));
789 filename = _filename;
793 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
797 memset(&swf,0x00,sizeof(SWF));
800 swf.frameRate = 0x0040; // 1 frame per 4 seconds
801 swf.movieSize.xmax = 20*sizex;
802 swf.movieSize.ymax = 20*sizey;
804 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
809 swf_SetRGB(tag,&rgb);
810 if(flag_protected) // good practice! /r
811 tag = swf_InsertTag(tag, ST_PROTECT);
816 void swfoutput_setprotected() //write PROTECT tag
821 void startshape(struct swfoutput*obj)
829 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
831 swf_ShapeNew(&shape);
832 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
833 rgb.r = obj->fillrgb.r;
834 rgb.g = obj->fillrgb.g;
835 rgb.b = obj->fillrgb.b;
836 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
838 shapeid = ++currentswfid;
839 swf_SetU16(tag,shapeid); // ID
848 swf_SetShapeStyles(tag,shape);
849 swf_ShapeCountBits(shape,NULL,NULL);
850 swf_SetShapeBits(tag,shape);
852 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
857 void starttext(struct swfoutput*obj)
863 tag = swf_InsertTag(tag,ST_DEFINETEXT);
864 textid = ++currentswfid;
865 swf_SetU16(tag, textid);
881 swf_SetMatrix(tag,&m);
889 swf_ShapeSetEnd(tag);
890 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
891 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
901 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
902 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
906 void endpage(struct swfoutput*obj)
913 swfoutput_endclip(obj);
914 tag = swf_InsertTag(tag,ST_SHOWFRAME);
917 void swfoutput_newpage(struct swfoutput*obj)
921 for(depth--;depth>=startdepth;depth--) {
922 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
923 swf_SetU16(tag,depth);
930 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
931 up, complete the swf, and write it out. */
932 void swfoutput_destroy(struct swfoutput* obj)
935 fontlist_t *tmp,*iterator = fontlist;
937 delete iterator->font;
940 iterator = iterator->next;
948 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
953 logf("<fatal> Could not create \"%s\". ", filename);
957 tag = swf_InsertTag(tag,ST_END);
959 if FAILED(swf_WriteSWF(fi,&swf))
960 logf("<error> WriteSWF() failed.\n");
963 logf("<notice> SWF written\n");
966 void swfoutput_setdrawmode(swfoutput* obj, int mode)
969 if(mode == DRAWMODE_FILL)
971 else if(mode == DRAWMODE_EOFILL)
973 else if(mode == DRAWMODE_STROKE)
975 else if(mode == DRAWMODE_CLIP)
977 else if(mode == DRAWMODE_EOCLIP)
981 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
983 if(obj->fillrgb.r == r &&
984 obj->fillrgb.g == g &&
985 obj->fillrgb.b == b &&
986 obj->fillrgb.a == a) return;
996 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
998 if(obj->strokergb.r == r &&
999 obj->strokergb.g == g &&
1000 obj->strokergb.b == b &&
1001 obj->strokergb.a == a) return;
1005 obj->strokergb.r = r;
1006 obj->strokergb.g = g;
1007 obj->strokergb.b = b;
1008 obj->strokergb.a = a;
1011 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
1013 if(obj->linewidth == (u16)(linewidth*20))
1018 obj->linewidth = (u16)(linewidth*20);
1022 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1031 logf("<warning> Too many clip levels.");
1036 int olddrawmode = drawmode;
1037 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1038 swfoutput_drawpath(obj, outline, m);
1039 swf_ShapeSetEnd(tag);
1040 swfoutput_setdrawmode(obj, olddrawmode);
1042 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1043 cliptags[clippos] = tag;
1044 clipshapes[clippos] = shapeid;
1045 clipdepths[clippos] = depth++;
1050 void swfoutput_endclip(swfoutput*obj)
1058 logf("<error> Invalid end of clipping region");
1062 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1065 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1067 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1076 actions = swf_ActionStart();
1078 action_GetUrl(url, "_parent");
1080 action_GetUrl(url, "_this");
1084 drawlink(obj, actions, points);
1086 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1095 actions = swf_ActionStart();
1096 action_GotoFrame(page);
1100 drawlink(obj, actions, points);
1103 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1109 struct plotxy p1,p2,p3,p4;
1113 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1115 int buttonid = ++currentswfid;
1118 if(points[t].x>xmax) xmax=points[t].x;
1119 if(points[t].y>ymax) ymax=points[t].y;
1120 if(points[t].x<xmin) xmin=points[t].x;
1121 if(points[t].y<ymin) ymin=points[t].y;
1123 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1124 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1127 myshapeid = ++currentswfid;
1128 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1129 swf_ShapeNew(&shape);
1130 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1131 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1132 swf_SetU16(tag, myshapeid);
1133 r.xmin = (int)(xmin*20);
1134 r.ymin = (int)(ymin*20);
1135 r.xmax = (int)(xmax*20);
1136 r.ymax = (int)(ymax*20);
1137 swf_SetRect(tag,&r);
1138 swf_SetShapeStyles(tag,shape);
1139 swf_ShapeCountBits(shape,NULL,NULL);
1140 swf_SetShapeBits(tag,shape);
1141 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1142 swflastx = swflasty = 0;
1148 swf_ShapeSetEnd(tag);
1151 myshapeid2 = ++currentswfid;
1152 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1153 swf_ShapeNew(&shape);
1154 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1156 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1157 swf_SetU16(tag, myshapeid2);
1158 r.xmin = (int)(xmin*20);
1159 r.ymin = (int)(ymin*20);
1160 r.xmax = (int)(xmax*20);
1161 r.ymax = (int)(ymax*20);
1162 swf_SetRect(tag,&r);
1163 swf_SetShapeStyles(tag,shape);
1164 swf_ShapeCountBits(shape,NULL,NULL);
1165 swf_SetShapeBits(tag,shape);
1166 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1167 swflastx = swflasty = 0;
1173 swf_ShapeSetEnd(tag);
1175 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1176 swf_SetU16(tag,buttonid); //id
1177 swf_ButtonSetFlags(tag, 0); //menu=no
1178 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1179 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1180 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1181 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1183 swf_ActionSet(tag,actions);
1186 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1187 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1190 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1191 double x1,double y1,
1192 double x2,double y2,
1193 double x3,double y3,
1194 double x4,double y4)
1200 struct plotxy p1,p2,p3,p4;
1202 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1203 if(x2>xmax) xmax=x2;
1204 if(y2>ymax) ymax=y2;
1205 if(x2<xmin) xmin=x2;
1206 if(y2<ymin) ymin=y2;
1207 if(x3>xmax) xmax=x3;
1208 if(y3>ymax) ymax=y3;
1209 if(x3<xmin) xmin=x3;
1210 if(y3<ymin) ymin=y3;
1211 if(x4>xmax) xmax=x4;
1212 if(y4>ymax) ymax=y4;
1213 if(x4<xmin) xmin=x4;
1214 if(y4<ymin) ymin=y4;
1225 m.sx = (int)(65536*20*(x4-x1))/sizex;
1226 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1227 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1228 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1230 m.tx = (int)(x1*20);
1231 m.ty = (int)(y1*20);
1234 myshapeid = ++currentswfid;
1235 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1236 swf_ShapeNew(&shape);
1237 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1238 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1239 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1240 swf_SetU16(tag, myshapeid);
1241 r.xmin = (int)(xmin*20);
1242 r.ymin = (int)(ymin*20);
1243 r.xmax = (int)(xmax*20);
1244 r.ymax = (int)(ymax*20);
1245 swf_SetRect(tag,&r);
1246 swf_SetShapeStyles(tag,shape);
1247 swf_ShapeCountBits(shape,NULL,NULL);
1248 swf_SetShapeBits(tag,shape);
1249 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1250 swflastx = swflasty = 0;
1257 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1258 ShapeSetLine (tag, shape, (int)(x1*20);
1259 ShapeSetLine (tag, shape, x*20,0);
1260 ShapeSetLine (tag, shape, 0,-y*20);
1261 ShapeSetLine (tag, shape, -x*20,0);*/
1262 swf_ShapeSetEnd(tag);
1265 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1266 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1269 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1270 double x1,double y1,
1271 double x2,double y2,
1272 double x3,double y3,
1273 double x4,double y4)
1280 int bitid = ++currentswfid;
1281 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1282 swf_SetU16(tag, bitid);
1283 swf_SetJPEGBits(tag, filename, jpegquality);
1285 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1289 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1290 double x1,double y1,
1291 double x2,double y2,
1292 double x3,double y3,
1293 double x4,double y4)
1300 int bitid = ++currentswfid;
1301 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1302 swf_SetU16(tag, bitid);
1303 swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT);
1305 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1309 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1310 double x1,double y1,
1311 double x2,double y2,
1312 double x3,double y3,
1313 double x4,double y4)
1320 int bitid = ++currentswfid;
1321 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1322 swf_SetU16(tag, bitid);
1323 swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256);
1325 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1329 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1330 double x1,double y1,
1331 double x2,double y2,
1332 double x3,double y3,
1333 double x4,double y4)
1340 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);