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 static void startshape(struct swfoutput* obj);
75 static void starttext(struct swfoutput* obj);
76 static void endshape();
77 static void endtext();
79 // matrix multiplication. changes p0
80 static 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 static 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 static 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 static 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 if(cx || cy || ex || ey)
125 swf_ShapeSetCurve(tag, shape, cx,cy,ex,ey);
128 /* write a line, given two points and the transformation
130 static void line(TAG*tag, plotxy p0, plotxy p1, struct swfmatrix*m)
138 /* write a cubic (!) spline. This involves calling the approximate()
139 function out of spline.cc to convert it to a quadratic spline. */
140 static void spline(TAG*tag,plotxy p0,plotxy p1,plotxy p2,plotxy p3,struct swfmatrix*m)
143 struct qspline q[16];
151 num = approximate(p0,p1,p2,p3,q);
153 moveto(tag,q[t].start);
154 splineto(tag,q[t].control, q[t].end);
164 /* draw a T1 outline. These are generated by pdf2swf and by t1lib.
165 (representing characters) */
166 void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m, int log)
168 if(tag->id != ST_DEFINEFONT &&
169 tag->id != ST_DEFINESHAPE &&
170 tag->id != ST_DEFINESHAPE2 &&
171 tag->id != ST_DEFINESHAPE3)
173 logf("<error> internal error: drawpath needs a shape tag, not %d\n",tag->id);
177 double lastx=0,lasty=0;
178 double firstx=0,firsty=0;
183 x += (outline->dest.x/(float)0xffff);
184 y += (outline->dest.y/(float)0xffff);
185 if(outline->type == T1_PATHTYPE_MOVE)
187 if(((int)(lastx*20) != (int)(firstx*20) ||
188 (int)(lasty*20) != (int)(firsty*20)) &&
197 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
198 line(tag, p0, p1, m);
204 else if(outline->type == T1_PATHTYPE_LINE)
212 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
215 else if(outline->type == T1_PATHTYPE_BEZIER)
221 T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
224 p1.x=o2->C.x/(float)0xffff+lastx;
225 p1.y=o2->C.y/(float)0xffff+lasty;
226 p2.x=o2->B.x/(float)0xffff+lastx;
227 p2.y=o2->B.y/(float)0xffff+lasty;
230 if(log) printf("spline: %f,%f -> %f,%f\n",p3.x,p3.y,p0.x,p0.y);
231 spline(tag,p0,p1,p2,p3,m);
234 logf("<error> drawpath: unknown outline type:%d\n", outline->type);
238 outline = outline->link;
240 if(((int)(lastx*20) != (int)(firstx*20) ||
241 (int)(lasty*20) != (int)(firsty*20)) &&
250 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
251 line(tag, p0, p1, m);
255 static inline int colorcompare(RGBA*a,RGBA*b)
267 static const int CHARDATAMAX = 1024;
275 } chardata[CHARDATAMAX];
278 static void putcharacters(TAG*tag)
283 color.r = chardata[0].color.r^255;
292 int charadvance[128];
295 int glyphbits=1; //TODO: can this be zero?
298 if(tag->id != ST_DEFINETEXT &&
299 tag->id != ST_DEFINETEXT2) {
300 logf("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
304 logf("<warning> putcharacters called with zero characters");
307 for(pass = 0; pass < 2; pass++)
317 advancebits++; // add sign bit
318 swf_SetU8(tag, glyphbits);
319 swf_SetU8(tag, advancebits);
322 for(t=0;t<=chardatapos;t++)
324 if(lastfontid != chardata[t].fontid ||
325 lastx!=chardata[t].x ||
326 lasty!=chardata[t].y ||
327 !colorcompare(&color, &chardata[t].color) ||
329 lastsize != chardata[t].size ||
332 if(charstorepos && pass==0)
335 for(s=0;s<charstorepos;s++)
337 while(charids[s]>=(1<<glyphbits))
339 while(charadvance[s]>=(1<<advancebits))
343 if(charstorepos && pass==1)
345 tag->writeBit = 0; // Q&D
346 swf_SetBits(tag, 0, 1); // GLYPH Record
347 swf_SetBits(tag, charstorepos, 7); // number of glyphs
349 for(s=0;s<charstorepos;s++)
351 swf_SetBits(tag, charids[s], glyphbits);
352 swf_SetBits(tag, charadvance[s], advancebits);
357 if(pass == 1 && t<chardatapos)
363 if(lastx != chardata[t].x ||
364 lasty != chardata[t].y)
369 if(!colorcompare(&color, &chardata[t].color))
371 color = chardata[t].color;
374 font.id = chardata[t].fontid;
375 if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
378 tag->writeBit = 0; // Q&D
379 swf_TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
382 lastfontid = chardata[t].fontid;
383 lastx = chardata[t].x;
384 lasty = chardata[t].y;
385 lastsize = chardata[t].size;
392 int nextt = t==chardatapos-1?t:t+1;
393 int rel = chardata[nextt].x-chardata[t].x;
394 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
396 lastx=chardata[nextt].x;
402 charids[charstorepos] = chardata[t].charid;
403 charadvance[charstorepos] = advance;
410 static void putcharacter(struct swfoutput*obj, int fontid, int charid,
411 int x,int y, int size)
413 if(chardatapos == CHARDATAMAX)
418 chardata[chardatapos].fontid = fontid;
419 chardata[chardatapos].charid = charid;
420 chardata[chardatapos].x = x;
421 chardata[chardatapos].y = y;
422 chardata[chardatapos].color = obj->fillrgb;
423 chardata[chardatapos].size = size;
428 /* process a character. */
429 static void drawchar(struct swfoutput*obj, SWFFont*font, char*character, int charnr, swfmatrix*m)
432 if(m->m12!=0 || m->m21!=0)
437 if(usefonts && ! drawonlyshapes)
439 int charid = font->getSWFCharID(character, charnr);
444 putcharacter(obj, font->swfid, charid,(int)(m->m13*20),(int)(m->m23*20),
445 (int)(m->m11*20/2+0.5)); //where does the /2 come from?
449 T1_OUTLINE*outline = font->getOutline(character);
450 char* charname = character;
453 logf("<warning> Didn't find %s in current charset (%s)",
454 FIXNULL(character),FIXNULL(font->getName()));
470 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
475 drawpath(tag, outline, &m2, 0);
480 /* draw a curved polygon. */
481 void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline,
489 if(lastwasfill && !fill)
491 swf_ShapeSetStyle(tag,shape,linestyleid,0x8000,0);
494 if(!lastwasfill && fill)
496 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
500 drawpath(tag, outline,m, 0);
503 /* SWFFont: copy all t1 font outlines to a local
505 SWFFont::SWFFont(char*name, int id, char*filename)
507 if(!T1_GetFontName(id))
510 this->name = strdup(T1_GetFontFileName(id));
511 this->fontid = strdup(name);
514 char**a= T1_GetAllCharNames(id);
525 logf("<verbose> Font %s(%d): Storing %d outlines.\n", FIXNULL(name), id, charnum);
527 this->standardtablesize = 256;
528 if(this->charnum < this->standardtablesize)
529 this->standardtablesize = this->charnum;
530 this->standardtable = (char**)malloc(standardtablesize*sizeof(char*));
532 for(t = 0; t < this->standardtablesize; t++) {
533 char*name = T1_GetCharName(id,t);
536 standardtable[t] = strdup(name);
539 outline = (T1_OUTLINE**)malloc(charnum*sizeof(T1_OUTLINE*));
540 charname = (char**)malloc(charnum*sizeof(char*));
541 width = (int*)malloc(charnum*sizeof(int));
542 memset(width, 0, charnum*sizeof(int));
543 memset(charname, 0, charnum*sizeof(char*));
544 used = (char*)malloc(charnum*sizeof(char));
545 char2swfcharid = (U16*)malloc(charnum*2);
546 swfcharid2char = (U16*)malloc(charnum*2);
549 memset(used,0,charnum*sizeof(char));
551 this->swfid = ++currentswfid;
564 int ret = T1_ReencodeFont(id, map);
568 int ret = T1_ReencodeFont(id, map);
570 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
576 char* name = T1_GetCharName(id, s);
578 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
579 this->width[outlinepos] = T1_GetCharWidth(id, s);
580 this->charname[outlinepos] = strdup(name);
588 /* free all tables, write out definefont tags */
594 if(storeallcharacters)
597 for(t=0;t<this->charnum;t++)
599 if(this->charname[t])
600 getSWFCharID(this->charname[t], -1);
604 ptr = (int*)malloc(swfcharpos*sizeof(int));
606 for(t=0;t<charnum;t++)
607 if(used[t]) usednum++;
609 if(usednum && !drawonlyshapes)
611 logf("<verbose> Font %s has %d used characters",FIXNULL(fontid), usednum);
612 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
613 swf_SetU16(ftag, this->swfid);
614 int initpos = swf_GetTagLen(ftag);
621 for(t=0;t<swfcharpos;t++)
623 ptr[t] = swf_GetTagLen(ftag);
624 swf_SetU16(ftag, 0x1234);
626 for(t=0;t<swfcharpos;t++)
628 *(U16*)&ftag->data[ptr[t]] =
629 SWAP16(swf_GetTagLen(ftag)-initpos);
633 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
637 swf_ShapeSetStyle(ftag,&s,0,1,0);
641 drawpath(ftag, outline[swfcharid2char[t]],&m, 0);
644 swf_ShapeSetEnd(ftag);
646 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
647 swf_SetU16(ftag, this->swfid);
649 swf_SetU8(ftag, strlen(this->fontid));
650 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
654 swf_SetU8(ftag, 0); //flags
655 for(t=0;t<swfcharpos;t++)
658 char * name = this->charname[this->swfcharid2char[t]];
660 if(standardEncodingNames[s] &&
661 !strcmp(name,standardEncodingNames[s]))
664 swf_SetU8(ftag, (U8)s);
670 for(t=0;t<charnum;t++)
672 for(t=0;t<standardtablesize;t++)
673 if(standardtable[t]) {
674 free(standardtable[t]);
680 free(swfcharid2char);
681 free(char2swfcharid);
684 T1_OUTLINE*SWFFont::getOutline(char*name)
687 for(t=0;t<this->charnum;t++) {
688 if(!strcmp(this->charname[t],name)) {
691 swfcharid2char[swfcharpos] = t;
692 char2swfcharid[t] = swfcharpos;
702 int SWFFont::getWidth(char*name)
705 for(t=0;t<this->charnum;t++) {
706 if(!strcmp(this->charname[t],name)) {
707 return this->width[t];
713 int SWFFont::getSWFCharID(char*name, int charnr)
716 for(t=0;t<this->charnum;t++) {
717 if(!strcmp(this->charname[t],name)) {
720 swfcharid2char[swfcharpos] = t;
721 char2swfcharid[t] = swfcharpos++;
724 return char2swfcharid[t];
727 if(this->standardtable && charnr>=0 && charnr < this->standardtablesize) {
728 return getSWFCharID(this->standardtable[charnr], -1);
730 logf("<warning> Didn't find character '%s' in font '%s'", FIXNULL(name), this->name);
734 char*SWFFont::getName()
745 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
746 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
748 fontlist_t*last=0,*iterator;
749 if(obj->font && !strcmp(obj->font->fontid,fontid))
754 if(!strcmp(iterator->font->fontid,fontid))
757 iterator = iterator->next;
761 obj->font = iterator->font;
766 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,FIXNULL(fontid));
769 SWFFont*font = new SWFFont(fontid, t1id, filename);
770 iterator = new fontlist_t;
771 iterator->font = font;
775 last->next = iterator;
781 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
783 fontlist_t *iterator = fontlist;
785 if(!strcmp(iterator->font->fontid,fontid))
787 iterator = iterator->next;
792 /* set's the matrix which is to be applied to characters drawn by
793 swfoutput_drawchar() */
794 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
795 double m21,double m22)
797 if(obj->fontm11 == m11 &&
798 obj->fontm12 == m12 &&
799 obj->fontm21 == m21 &&
810 /* draws a character at x,y. */
811 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr)
814 m.m11 = obj->fontm11;
815 m.m12 = obj->fontm12;
816 m.m21 = obj->fontm21;
817 m.m22 = obj->fontm22;
820 drawchar(obj, obj->font, character, charnr, &m);
823 /* initialize the swf writer */
824 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
829 memset(obj, 0, sizeof(struct swfoutput));
830 filename = _filename;
834 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
838 memset(&swf,0x00,sizeof(SWF));
841 swf.frameRate = 0x0040; // 1 frame per 4 seconds
842 swf.movieSize.xmax = 20*sizex;
843 swf.movieSize.ymax = 20*sizey;
845 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
850 swf_SetRGB(tag,&rgb);
851 if(flag_protected) // good practice! /r
852 tag = swf_InsertTag(tag, ST_PROTECT);
857 void swfoutput_setprotected() //write PROTECT tag
862 static void startshape(struct swfoutput*obj)
870 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
872 swf_ShapeNew(&shape);
873 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
874 rgb.r = obj->fillrgb.r;
875 rgb.g = obj->fillrgb.g;
876 rgb.b = obj->fillrgb.b;
877 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
879 shapeid = ++currentswfid;
880 swf_SetU16(tag,shapeid); // ID
889 swf_SetShapeStyles(tag,shape);
890 swf_ShapeCountBits(shape,NULL,NULL);
891 swf_SetShapeBits(tag,shape);
893 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
898 static void starttext(struct swfoutput*obj)
904 tag = swf_InsertTag(tag,ST_DEFINETEXT);
905 textid = ++currentswfid;
906 swf_SetU16(tag, textid);
922 swf_SetMatrix(tag,&m);
926 static void endshape()
930 swf_ShapeSetEnd(tag);
931 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
932 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
936 static void endtext()
942 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
943 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
947 static void endpage(struct swfoutput*obj)
954 swfoutput_endclip(obj);
955 tag = swf_InsertTag(tag,ST_SHOWFRAME);
958 void swfoutput_newpage(struct swfoutput*obj)
962 for(depth--;depth>=startdepth;depth--) {
963 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
964 swf_SetU16(tag,depth);
971 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
972 up, complete the swf, and write it out. */
973 void swfoutput_destroy(struct swfoutput* obj)
976 fontlist_t *tmp,*iterator = fontlist;
978 delete iterator->font;
981 iterator = iterator->next;
989 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
994 logf("<fatal> Could not create \"%s\". ", FIXNULL(filename));
998 tag = swf_InsertTag(tag,ST_END);
1000 if FAILED(swf_WriteSWF(fi,&swf))
1001 logf("<error> WriteSWF() failed.\n");
1004 logf("<notice> SWF written\n");
1007 void swfoutput_setdrawmode(swfoutput* obj, int mode)
1010 if(mode == DRAWMODE_FILL)
1012 else if(mode == DRAWMODE_EOFILL)
1014 else if(mode == DRAWMODE_STROKE)
1016 else if(mode == DRAWMODE_CLIP)
1018 else if(mode == DRAWMODE_EOCLIP)
1022 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1024 if(obj->fillrgb.r == r &&
1025 obj->fillrgb.g == g &&
1026 obj->fillrgb.b == b &&
1027 obj->fillrgb.a == a) return;
1037 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1039 if(obj->strokergb.r == r &&
1040 obj->strokergb.g == g &&
1041 obj->strokergb.b == b &&
1042 obj->strokergb.a == a) return;
1046 obj->strokergb.r = r;
1047 obj->strokergb.g = g;
1048 obj->strokergb.b = b;
1049 obj->strokergb.a = a;
1052 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
1054 if(obj->linewidth == (u16)(linewidth*20))
1059 obj->linewidth = (u16)(linewidth*20);
1063 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1072 logf("<warning> Too many clip levels.");
1077 int olddrawmode = drawmode;
1078 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1079 swfoutput_drawpath(obj, outline, m);
1080 swf_ShapeSetEnd(tag);
1081 swfoutput_setdrawmode(obj, olddrawmode);
1083 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1084 cliptags[clippos] = tag;
1085 clipshapes[clippos] = shapeid;
1086 clipdepths[clippos] = depth++;
1091 void swfoutput_endclip(swfoutput*obj)
1099 logf("<error> Invalid end of clipping region");
1103 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1106 static void drawlink(struct swfoutput*obj, ActionTAG*,ActionTAG*, swfcoord*points, char mouseover);
1108 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1117 actions = swf_ActionStart();
1119 action_GetUrl(url, "_parent");
1121 action_GetUrl(url, "_this");
1125 drawlink(obj, actions, 0, points,0);
1127 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1136 actions = swf_ActionStart();
1137 action_GotoFrame(page);
1141 drawlink(obj, actions, 0, points,0);
1143 void swfoutput_namedlink(struct swfoutput*obj, char*name, swfcoord*points)
1145 ActionTAG *actions1,*actions2;
1152 actions1 = swf_ActionStart();
1153 action_PushString("/:subtitle");
1154 action_PushString(name);
1155 action_SetVariable();
1159 actions2 = swf_ActionStart();
1160 action_PushString("/:subtitle");
1161 action_PushString("");
1162 action_SetVariable();
1166 drawlink(obj, actions1, actions2, points,1);
1168 swf_ActionFree(actions1);
1169 swf_ActionFree(actions2);
1172 static void drawlink(struct swfoutput*obj, ActionTAG*actions1, ActionTAG*actions2, swfcoord*points, char mouseover)
1178 struct plotxy p1,p2,p3,p4;
1182 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1184 int buttonid = ++currentswfid;
1187 if(points[t].x>xmax) xmax=points[t].x;
1188 if(points[t].y>ymax) ymax=points[t].y;
1189 if(points[t].x<xmin) xmin=points[t].x;
1190 if(points[t].y<ymin) ymin=points[t].y;
1192 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1193 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1196 myshapeid = ++currentswfid;
1197 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1198 swf_ShapeNew(&shape);
1199 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1200 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1201 swf_SetU16(tag, myshapeid);
1202 r.xmin = (int)(xmin*20);
1203 r.ymin = (int)(ymin*20);
1204 r.xmax = (int)(xmax*20);
1205 r.ymax = (int)(ymax*20);
1206 swf_SetRect(tag,&r);
1207 swf_SetShapeStyles(tag,shape);
1208 swf_ShapeCountBits(shape,NULL,NULL);
1209 swf_SetShapeBits(tag,shape);
1210 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1211 swflastx = swflasty = 0;
1217 swf_ShapeSetEnd(tag);
1220 myshapeid2 = ++currentswfid;
1221 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1222 swf_ShapeNew(&shape);
1223 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1225 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1226 swf_SetU16(tag, myshapeid2);
1227 r.xmin = (int)(xmin*20);
1228 r.ymin = (int)(ymin*20);
1229 r.xmax = (int)(xmax*20);
1230 r.ymax = (int)(ymax*20);
1231 swf_SetRect(tag,&r);
1232 swf_SetShapeStyles(tag,shape);
1233 swf_ShapeCountBits(shape,NULL,NULL);
1234 swf_SetShapeBits(tag,shape);
1235 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1236 swflastx = swflasty = 0;
1242 swf_ShapeSetEnd(tag);
1246 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1247 swf_SetU16(tag,buttonid); //id
1248 swf_ButtonSetFlags(tag, 0); //menu=no
1249 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1250 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1251 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1252 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1254 swf_ActionSet(tag,actions1);
1259 tag = swf_InsertTag(tag,ST_DEFINEBUTTON2);
1260 swf_SetU16(tag,buttonid); //id
1261 swf_ButtonSetFlags(tag, 0); //menu=no
1262 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1263 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1264 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1265 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1266 swf_SetU8(tag,0); // end of button records
1267 swf_ButtonSetCondition(tag, BC_IDLE_OVERUP);
1268 swf_ActionSet(tag,actions1);
1270 swf_ButtonSetCondition(tag, BC_OVERUP_IDLE);
1271 swf_ActionSet(tag,actions2);
1273 swf_ButtonPostProcess(tag, 2);
1276 swf_ButtonPostProcess(tag, 1);
1280 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1281 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1284 static void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1285 double x1,double y1,
1286 double x2,double y2,
1287 double x3,double y3,
1288 double x4,double y4)
1294 struct plotxy p1,p2,p3,p4;
1296 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1297 if(x2>xmax) xmax=x2;
1298 if(y2>ymax) ymax=y2;
1299 if(x2<xmin) xmin=x2;
1300 if(y2<ymin) ymin=y2;
1301 if(x3>xmax) xmax=x3;
1302 if(y3>ymax) ymax=y3;
1303 if(x3<xmin) xmin=x3;
1304 if(y3<ymin) ymin=y3;
1305 if(x4>xmax) xmax=x4;
1306 if(y4>ymax) ymax=y4;
1307 if(x4<xmin) xmin=x4;
1308 if(y4<ymin) ymin=y4;
1319 m.sx = (int)(65536*20*(x4-x1))/sizex;
1320 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1321 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1322 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1324 m.tx = (int)(x1*20);
1325 m.ty = (int)(y1*20);
1328 myshapeid = ++currentswfid;
1329 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1330 swf_ShapeNew(&shape);
1331 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1332 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1333 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1334 swf_SetU16(tag, myshapeid);
1335 r.xmin = (int)(xmin*20);
1336 r.ymin = (int)(ymin*20);
1337 r.xmax = (int)(xmax*20);
1338 r.ymax = (int)(ymax*20);
1339 swf_SetRect(tag,&r);
1340 swf_SetShapeStyles(tag,shape);
1341 swf_ShapeCountBits(shape,NULL,NULL);
1342 swf_SetShapeBits(tag,shape);
1343 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1344 swflastx = swflasty = 0;
1351 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1352 ShapeSetLine (tag, shape, (int)(x1*20);
1353 ShapeSetLine (tag, shape, x*20,0);
1354 ShapeSetLine (tag, shape, 0,-y*20);
1355 ShapeSetLine (tag, shape, -x*20,0);*/
1356 swf_ShapeSetEnd(tag);
1359 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1360 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1363 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1364 double x1,double y1,
1365 double x2,double y2,
1366 double x3,double y3,
1367 double x4,double y4)
1375 int bitid = ++currentswfid;
1377 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1378 swf_SetU16(tag, bitid);
1379 if(swf_SetJPEGBits(tag, filename, jpegquality)<0) {
1385 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1389 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1390 double x1,double y1,
1391 double x2,double y2,
1392 double x3,double y3,
1393 double x4,double y4)
1401 int bitid = ++currentswfid;
1403 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1404 swf_SetU16(tag, bitid);
1405 if(swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT)<0) {
1411 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1415 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1416 double x1,double y1,
1417 double x2,double y2,
1418 double x3,double y3,
1419 double x4,double y4)
1427 int bitid = ++currentswfid;
1429 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1430 swf_SetU16(tag, bitid);
1431 if(swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256)<0) {
1437 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1441 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1442 double x1,double y1,
1443 double x2,double y2,
1444 double x3,double y3,
1445 double x4,double y4)
1453 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);