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 memset(charname, t*sizeof(char*), 0);
523 used = (char*)malloc(t*sizeof(char));
524 char2swfcharid = (U16*)malloc(t*2);
525 swfcharid2char = (U16*)malloc(t*2);
528 memset(used,0,t*sizeof(char));
530 this->swfid = ++currentswfid;
544 int ret = T1_ReencodeFont(id, map);
548 int ret = T1_ReencodeFont(id, map);
550 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
556 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
557 this->charname[outlinepos] = strdup(T1_GetCharName(id, s));
565 /* free all tables, write out definefont tags */
571 if(storeallcharacters)
574 for(t=0;t<this->charnum;t++)
576 if(this->charname[t])
577 getSWFCharID(this->charname[t]);
581 ptr = (int*)malloc(swfcharpos*sizeof(int));
583 for(t=0;t<charnum;t++)
584 if(used[t]) usednum++;
586 if(usednum && !drawonlyshapes)
588 logf("<verbose> Font %s has %d used characters",fontid, usednum);
589 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
590 swf_SetU16(ftag, this->swfid);
591 int initpos = swf_GetDataSize(ftag);
598 for(t=0;t<swfcharpos;t++)
600 ptr[t] = swf_GetDataSize(ftag);
601 swf_SetU16(ftag, 0x1234);
603 for(t=0;t<swfcharpos;t++)
605 *(U16*)&ftag->data[ptr[t]] = swf_GetDataSize(ftag)-initpos;
608 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
612 swf_ShapeSetStyle(ftag,&s,0,1,0);
616 drawpath(ftag, outline[swfcharid2char[t]],&m);
619 swf_ShapeSetEnd(ftag);
621 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
622 swf_SetU16(ftag, this->swfid);
624 swf_SetU8(ftag, strlen(this->fontid));
625 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
629 swf_SetU8(ftag, 0); //flags
630 for(t=0;t<swfcharpos;t++)
633 char * name = this->charname[this->swfcharid2char[t]];
635 if(standardEncodingNames[s] &&
636 !strcmp(name,standardEncodingNames[s]))
639 swf_SetU8(ftag, (U8)s);
645 for(t=0;t<charnum;t++)
649 free(swfcharid2char);
650 free(char2swfcharid);
653 T1_OUTLINE*SWFFont::getOutline(char*name)
656 for(t=0;t<this->charnum;t++) {
657 if(!strcmp(this->charname[t],name)) {
660 swfcharid2char[swfcharpos] = t;
661 char2swfcharid[t] = swfcharpos;
671 int SWFFont::getSWFCharID(char*name)
674 for(t=0;t<this->charnum;t++) {
675 if(!strcmp(this->charname[t],name)) {
678 swfcharid2char[swfcharpos] = t;
679 char2swfcharid[t] = swfcharpos++;
682 return char2swfcharid[t];
685 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
689 char*SWFFont::getName()
700 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
701 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
703 fontlist_t*last=0,*iterator;
704 if(obj->font && !strcmp(obj->font->fontid,fontid))
709 if(!strcmp(iterator->font->fontid,fontid))
712 iterator = iterator->next;
716 obj->font = iterator->font;
721 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
724 SWFFont*font = new SWFFont(fontid, t1id, filename);
725 iterator = new fontlist_t;
726 iterator->font = font;
730 last->next = iterator;
736 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
738 fontlist_t *iterator = fontlist;
740 if(!strcmp(iterator->font->fontid,fontid))
742 iterator = iterator->next;
747 /* set's the matrix which is to be applied to characters drawn by
748 swfoutput_drawchar() */
749 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
750 double m21,double m22)
752 if(obj->fontm11 == m11 &&
753 obj->fontm12 == m12 &&
754 obj->fontm21 == m21 &&
765 /* draws a character at x,y. */
766 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character)
769 m.m11 = obj->fontm11;
770 m.m12 = obj->fontm12;
771 m.m21 = obj->fontm21;
772 m.m22 = obj->fontm22;
775 drawchar(obj, obj->font, character, &m);
778 /* initialize the swf writer */
779 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
784 memset(obj, 0, sizeof(struct swfoutput));
785 filename = _filename;
789 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
793 memset(&swf,0x00,sizeof(SWF));
796 swf.frameRate = 0x0040; // 1 frame per 4 seconds
797 swf.movieSize.xmax = 20*sizex;
798 swf.movieSize.ymax = 20*sizey;
800 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
805 swf_SetRGB(tag,&rgb);
806 if(flag_protected) // good practice! /r
807 tag = swf_InsertTag(tag, ST_PROTECT);
812 void swfoutput_setprotected() //write PROTECT tag
817 void startshape(struct swfoutput*obj)
825 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
827 swf_ShapeNew(&shape);
828 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
829 rgb.r = obj->fillrgb.r;
830 rgb.g = obj->fillrgb.g;
831 rgb.b = obj->fillrgb.b;
832 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
834 shapeid = ++currentswfid;
835 swf_SetU16(tag,shapeid); // ID
844 swf_SetShapeStyles(tag,shape);
845 swf_ShapeCountBits(shape,NULL,NULL);
846 swf_SetShapeBits(tag,shape);
848 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
853 void starttext(struct swfoutput*obj)
859 tag = swf_InsertTag(tag,ST_DEFINETEXT);
860 textid = ++currentswfid;
861 swf_SetU16(tag, textid);
877 swf_SetMatrix(tag,&m);
885 swf_ShapeSetEnd(tag);
886 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
887 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
897 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
898 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
902 void endpage(struct swfoutput*obj)
909 swfoutput_endclip(obj);
910 tag = swf_InsertTag(tag,ST_SHOWFRAME);
913 void swfoutput_newpage(struct swfoutput*obj)
917 for(depth--;depth>=startdepth;depth--) {
918 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
919 swf_SetU16(tag,depth);
926 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
927 up, complete the swf, and write it out. */
928 void swfoutput_destroy(struct swfoutput* obj)
931 fontlist_t *tmp,*iterator = fontlist;
933 delete iterator->font;
936 iterator = iterator->next;
944 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
949 logf("<fatal> Could not create \"%s\". ", filename);
953 tag = swf_InsertTag(tag,ST_END);
955 if FAILED(swf_WriteSWF(fi,&swf))
956 logf("<error> WriteSWF() failed.\n");
959 logf("<notice> SWF written\n");
962 void swfoutput_setdrawmode(swfoutput* obj, int mode)
965 if(mode == DRAWMODE_FILL)
967 else if(mode == DRAWMODE_EOFILL)
969 else if(mode == DRAWMODE_STROKE)
971 else if(mode == DRAWMODE_CLIP)
973 else if(mode == DRAWMODE_EOCLIP)
977 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
979 if(obj->fillrgb.r == r &&
980 obj->fillrgb.g == g &&
981 obj->fillrgb.b == b &&
982 obj->fillrgb.a == a) return;
992 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
994 if(obj->strokergb.r == r &&
995 obj->strokergb.g == g &&
996 obj->strokergb.b == b &&
997 obj->strokergb.a == a) return;
1001 obj->strokergb.r = r;
1002 obj->strokergb.g = g;
1003 obj->strokergb.b = b;
1004 obj->strokergb.a = a;
1007 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
1009 if(obj->linewidth == (u16)(linewidth*20))
1014 obj->linewidth = (u16)(linewidth*20);
1018 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1027 logf("<warning> Too many clip levels.");
1032 int olddrawmode = drawmode;
1033 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1034 swfoutput_drawpath(obj, outline, m);
1035 swf_ShapeSetEnd(tag);
1036 swfoutput_setdrawmode(obj, olddrawmode);
1038 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1039 cliptags[clippos] = tag;
1040 clipshapes[clippos] = shapeid;
1041 clipdepths[clippos] = depth++;
1046 void swfoutput_endclip(swfoutput*obj)
1054 logf("<error> Invalid end of clipping region");
1058 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1061 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1063 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1072 actions = swf_ActionStart();
1074 action_GetUrl(url, "_parent");
1076 action_GetUrl(url, "_this");
1080 drawlink(obj, actions, points);
1082 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1091 actions = swf_ActionStart();
1092 action_GotoFrame(page);
1096 drawlink(obj, actions, points);
1099 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1105 struct plotxy p1,p2,p3,p4;
1109 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1111 int buttonid = ++currentswfid;
1114 if(points[t].x>xmax) xmax=points[t].x;
1115 if(points[t].y>ymax) ymax=points[t].y;
1116 if(points[t].x<xmin) xmin=points[t].x;
1117 if(points[t].y<ymin) ymin=points[t].y;
1119 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1120 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1123 myshapeid = ++currentswfid;
1124 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1125 swf_ShapeNew(&shape);
1126 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1127 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1128 swf_SetU16(tag, myshapeid);
1129 r.xmin = (int)(xmin*20);
1130 r.ymin = (int)(ymin*20);
1131 r.xmax = (int)(xmax*20);
1132 r.ymax = (int)(ymax*20);
1133 swf_SetRect(tag,&r);
1134 swf_SetShapeStyles(tag,shape);
1135 swf_ShapeCountBits(shape,NULL,NULL);
1136 swf_SetShapeBits(tag,shape);
1137 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1138 swflastx = swflasty = 0;
1144 swf_ShapeSetEnd(tag);
1147 myshapeid2 = ++currentswfid;
1148 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1149 swf_ShapeNew(&shape);
1150 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1152 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1153 swf_SetU16(tag, myshapeid2);
1154 r.xmin = (int)(xmin*20);
1155 r.ymin = (int)(ymin*20);
1156 r.xmax = (int)(xmax*20);
1157 r.ymax = (int)(ymax*20);
1158 swf_SetRect(tag,&r);
1159 swf_SetShapeStyles(tag,shape);
1160 swf_ShapeCountBits(shape,NULL,NULL);
1161 swf_SetShapeBits(tag,shape);
1162 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1163 swflastx = swflasty = 0;
1169 swf_ShapeSetEnd(tag);
1171 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1172 swf_SetU16(tag,buttonid); //id
1173 swf_ButtonSetFlags(tag, 0); //menu=no
1174 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1175 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1176 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1177 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1179 swf_ActionSet(tag,actions);
1182 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1183 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1186 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1187 double x1,double y1,
1188 double x2,double y2,
1189 double x3,double y3,
1190 double x4,double y4)
1196 struct plotxy p1,p2,p3,p4;
1198 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1199 if(x2>xmax) xmax=x2;
1200 if(y2>ymax) ymax=y2;
1201 if(x2<xmin) xmin=x2;
1202 if(y2<ymin) ymin=y2;
1203 if(x3>xmax) xmax=x3;
1204 if(y3>ymax) ymax=y3;
1205 if(x3<xmin) xmin=x3;
1206 if(y3<ymin) ymin=y3;
1207 if(x4>xmax) xmax=x4;
1208 if(y4>ymax) ymax=y4;
1209 if(x4<xmin) xmin=x4;
1210 if(y4<ymin) ymin=y4;
1221 m.sx = (int)(65536*20*(x4-x1))/sizex;
1222 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1223 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1224 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1226 m.tx = (int)(x1*20);
1227 m.ty = (int)(y1*20);
1230 myshapeid = ++currentswfid;
1231 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1232 swf_ShapeNew(&shape);
1233 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1234 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1235 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1236 swf_SetU16(tag, myshapeid);
1237 r.xmin = (int)(xmin*20);
1238 r.ymin = (int)(ymin*20);
1239 r.xmax = (int)(xmax*20);
1240 r.ymax = (int)(ymax*20);
1241 swf_SetRect(tag,&r);
1242 swf_SetShapeStyles(tag,shape);
1243 swf_ShapeCountBits(shape,NULL,NULL);
1244 swf_SetShapeBits(tag,shape);
1245 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1246 swflastx = swflasty = 0;
1253 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1254 ShapeSetLine (tag, shape, (int)(x1*20);
1255 ShapeSetLine (tag, shape, x*20,0);
1256 ShapeSetLine (tag, shape, 0,-y*20);
1257 ShapeSetLine (tag, shape, -x*20,0);*/
1258 swf_ShapeSetEnd(tag);
1261 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1262 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1265 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1266 double x1,double y1,
1267 double x2,double y2,
1268 double x3,double y3,
1269 double x4,double y4)
1276 int bitid = ++currentswfid;
1277 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1278 swf_SetU16(tag, bitid);
1279 swf_SetJPEGBits(tag, filename, jpegquality);
1281 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1285 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1286 double x1,double y1,
1287 double x2,double y2,
1288 double x3,double y3,
1289 double x4,double y4)
1296 int bitid = ++currentswfid;
1297 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1298 swf_SetU16(tag, bitid);
1299 swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT);
1301 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1305 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1306 double x1,double y1,
1307 double x2,double y2,
1308 double x3,double y3,
1309 double x4,double y4)
1316 int bitid = ++currentswfid;
1317 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1318 swf_SetU16(tag, bitid);
1319 swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256);
1321 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1325 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1326 double x1,double y1,
1327 double x2,double y2,
1328 double x3,double y3,
1329 double x4,double y4)
1336 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);