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);
163 /* draw a T1 outline. These are generated by pdf2swf and by t1lib.
164 (representing characters) */
165 void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m, int log)
167 if(tag->id != ST_DEFINEFONT &&
168 tag->id != ST_DEFINESHAPE &&
169 tag->id != ST_DEFINESHAPE2 &&
170 tag->id != ST_DEFINESHAPE3)
172 logf("<error> internal error: drawpath needs a shape tag, not %d\n",tag->id);
176 double lastx=0,lasty=0;
177 double firstx=0,firsty=0;
182 x += (outline->dest.x/(float)0xffff);
183 y += (outline->dest.y/(float)0xffff);
184 if(outline->type == T1_PATHTYPE_MOVE)
186 if(((int)(lastx*20) != (int)(firstx*20) ||
187 (int)(lasty*20) != (int)(firsty*20)) &&
196 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
197 line(tag, p0, p1, m);
203 else if(outline->type == T1_PATHTYPE_LINE)
211 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
214 else if(outline->type == T1_PATHTYPE_BEZIER)
220 T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
223 p1.x=o2->C.x/(float)0xffff+lastx;
224 p1.y=o2->C.y/(float)0xffff+lasty;
225 p2.x=o2->B.x/(float)0xffff+lastx;
226 p2.y=o2->B.y/(float)0xffff+lasty;
229 if(log) printf("spline: %f,%f -> %f,%f\n",p3.x,p3.y,p0.x,p0.y);
230 spline(tag,p0,p1,p2,p3,m);
233 logf("<error> drawpath: unknown outline type:%d\n", outline->type);
237 outline = outline->link;
239 if(((int)(lastx*20) != (int)(firstx*20) ||
240 (int)(lasty*20) != (int)(firsty*20)) &&
249 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
250 line(tag, p0, p1, m);
254 int colorcompare(RGBA*a,RGBA*b)
266 static const int CHARDATAMAX = 1024;
274 } chardata[CHARDATAMAX];
277 void putcharacters(TAG*tag)
282 color.r = chardata[0].color.r^255;
291 int charadvance[128];
294 int glyphbits=1; //TODO: can this be zero?
297 if(tag->id != ST_DEFINETEXT &&
298 tag->id != ST_DEFINETEXT2) {
299 logf("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
303 logf("<warning> putcharacters called with zero characters");
306 for(pass = 0; pass < 2; pass++)
316 advancebits++; // add sign bit
317 swf_SetU8(tag, glyphbits);
318 swf_SetU8(tag, advancebits);
321 for(t=0;t<=chardatapos;t++)
323 if(lastfontid != chardata[t].fontid ||
324 lastx!=chardata[t].x ||
325 lasty!=chardata[t].y ||
326 !colorcompare(&color, &chardata[t].color) ||
328 lastsize != chardata[t].size ||
331 if(charstorepos && pass==0)
334 for(s=0;s<charstorepos;s++)
336 while(charids[s]>=(1<<glyphbits))
338 while(charadvance[s]>=(1<<advancebits))
342 if(charstorepos && pass==1)
344 tag->writeBit = 0; // Q&D
345 swf_SetBits(tag, 0, 1); // GLYPH Record
346 swf_SetBits(tag, charstorepos, 7); // number of glyphs
348 for(s=0;s<charstorepos;s++)
350 swf_SetBits(tag, charids[s], glyphbits);
351 swf_SetBits(tag, charadvance[s], advancebits);
356 if(pass == 1 && t<chardatapos)
362 if(lastx != chardata[t].x ||
363 lasty != chardata[t].y)
368 if(!colorcompare(&color, &chardata[t].color))
370 color = chardata[t].color;
373 font.id = chardata[t].fontid;
374 if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
377 tag->writeBit = 0; // Q&D
378 swf_TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
381 lastfontid = chardata[t].fontid;
382 lastx = chardata[t].x;
383 lasty = chardata[t].y;
384 lastsize = chardata[t].size;
391 int nextt = t==chardatapos-1?t:t+1;
392 int rel = chardata[nextt].x-chardata[t].x;
393 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
395 lastx=chardata[nextt].x;
401 charids[charstorepos] = chardata[t].charid;
402 charadvance[charstorepos] = advance;
409 void putcharacter(struct swfoutput*obj, int fontid, int charid,
410 int x,int y, int size)
412 if(chardatapos == CHARDATAMAX)
417 chardata[chardatapos].fontid = fontid;
418 chardata[chardatapos].charid = charid;
419 chardata[chardatapos].x = x;
420 chardata[chardatapos].y = y;
421 chardata[chardatapos].color = obj->fillrgb;
422 chardata[chardatapos].size = size;
427 /* process a character. */
428 void drawchar(struct swfoutput*obj, SWFFont*font, char*character, int charnr, swfmatrix*m)
431 if(m->m12!=0 || m->m21!=0)
436 if(usefonts && ! drawonlyshapes)
438 int charid = font->getSWFCharID(character, charnr);
443 putcharacter(obj, font->swfid, charid,(int)(m->m13*20),(int)(m->m23*20),
444 (int)(m->m11*20/2+0.5)); //where does the /2 come from?
448 T1_OUTLINE*outline = font->getOutline(character);
449 char* charname = character;
452 logf("<warning> Didn't find %s in current charset (%s)",
453 character,font->getName());
469 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
474 drawpath(tag, outline, &m2, 0);
479 /* draw a curved polygon. */
480 void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline,
488 if(lastwasfill && !fill)
490 swf_ShapeSetStyle(tag,shape,linestyleid,0x8000,0);
493 if(!lastwasfill && fill)
495 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
499 drawpath(tag, outline,m, 0);
502 /* SWFFont: copy all t1 font outlines to a local
504 SWFFont::SWFFont(char*name, int id, char*filename)
506 if(!T1_GetFontName(id))
509 this->name = strdup(T1_GetFontFileName(id));
510 this->fontid = strdup(name);
513 char**a= T1_GetAllCharNames(id);
524 logf("<verbose> Font %s(%d): Storing %d outlines.\n", name, id, charnum);
526 this->standardtablesize = 256;
527 if(this->charnum < this->standardtablesize)
528 this->standardtablesize = this->charnum;
529 this->standardtable = (char**)malloc(standardtablesize*sizeof(char*));
531 for(t = 0; t < this->standardtablesize; t++) {
532 char*name = T1_GetCharName(id,t);
535 standardtable[t] = strdup(name);
538 outline = (T1_OUTLINE**)malloc(charnum*sizeof(T1_OUTLINE*));
539 charname = (char**)malloc(charnum*sizeof(char*));
540 width = (int*)malloc(charnum*sizeof(int));
541 memset(width, 0, charnum*sizeof(int));
542 memset(charname, 0, charnum*sizeof(char*));
543 used = (char*)malloc(charnum*sizeof(char));
544 char2swfcharid = (U16*)malloc(charnum*2);
545 swfcharid2char = (U16*)malloc(charnum*2);
548 memset(used,0,charnum*sizeof(char));
550 this->swfid = ++currentswfid;
563 int ret = T1_ReencodeFont(id, map);
567 int ret = T1_ReencodeFont(id, map);
569 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
575 char* name = T1_GetCharName(id, s);
577 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
578 this->width[outlinepos] = T1_GetCharWidth(id, s);
579 this->charname[outlinepos] = strdup(name);
587 /* free all tables, write out definefont tags */
593 if(storeallcharacters)
596 for(t=0;t<this->charnum;t++)
598 if(this->charname[t])
599 getSWFCharID(this->charname[t], -1);
603 ptr = (int*)malloc(swfcharpos*sizeof(int));
605 for(t=0;t<charnum;t++)
606 if(used[t]) usednum++;
608 if(usednum && !drawonlyshapes)
610 logf("<verbose> Font %s has %d used characters",fontid, usednum);
611 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
612 swf_SetU16(ftag, this->swfid);
613 int initpos = swf_GetTagLen(ftag);
620 for(t=0;t<swfcharpos;t++)
622 ptr[t] = swf_GetTagLen(ftag);
623 swf_SetU16(ftag, 0x1234);
625 for(t=0;t<swfcharpos;t++)
627 *(U16*)&ftag->data[ptr[t]] =
628 SWAP16(swf_GetTagLen(ftag)-initpos);
632 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
636 swf_ShapeSetStyle(ftag,&s,0,1,0);
640 drawpath(ftag, outline[swfcharid2char[t]],&m, 0);
643 swf_ShapeSetEnd(ftag);
645 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
646 swf_SetU16(ftag, this->swfid);
648 swf_SetU8(ftag, strlen(this->fontid));
649 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
653 swf_SetU8(ftag, 0); //flags
654 for(t=0;t<swfcharpos;t++)
657 char * name = this->charname[this->swfcharid2char[t]];
659 if(standardEncodingNames[s] &&
660 !strcmp(name,standardEncodingNames[s]))
663 swf_SetU8(ftag, (U8)s);
669 for(t=0;t<charnum;t++)
671 for(t=0;t<standardtablesize;t++)
672 if(standardtable[t]) {
673 free(standardtable[t]);
679 free(swfcharid2char);
680 free(char2swfcharid);
683 T1_OUTLINE*SWFFont::getOutline(char*name)
686 for(t=0;t<this->charnum;t++) {
687 if(!strcmp(this->charname[t],name)) {
690 swfcharid2char[swfcharpos] = t;
691 char2swfcharid[t] = swfcharpos;
701 int SWFFont::getWidth(char*name)
704 for(t=0;t<this->charnum;t++) {
705 if(!strcmp(this->charname[t],name)) {
706 return this->width[t];
712 int SWFFont::getSWFCharID(char*name, int charnr)
715 for(t=0;t<this->charnum;t++) {
716 if(!strcmp(this->charname[t],name)) {
719 swfcharid2char[swfcharpos] = t;
720 char2swfcharid[t] = swfcharpos++;
723 return char2swfcharid[t];
726 if(this->standardtable && charnr>=0 && charnr < this->standardtablesize) {
727 return getSWFCharID(this->standardtable[charnr], -1);
729 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
733 char*SWFFont::getName()
744 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
745 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
747 fontlist_t*last=0,*iterator;
748 if(obj->font && !strcmp(obj->font->fontid,fontid))
753 if(!strcmp(iterator->font->fontid,fontid))
756 iterator = iterator->next;
760 obj->font = iterator->font;
765 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
768 SWFFont*font = new SWFFont(fontid, t1id, filename);
769 iterator = new fontlist_t;
770 iterator->font = font;
774 last->next = iterator;
780 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
782 fontlist_t *iterator = fontlist;
784 if(!strcmp(iterator->font->fontid,fontid))
786 iterator = iterator->next;
791 /* set's the matrix which is to be applied to characters drawn by
792 swfoutput_drawchar() */
793 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
794 double m21,double m22)
796 if(obj->fontm11 == m11 &&
797 obj->fontm12 == m12 &&
798 obj->fontm21 == m21 &&
809 /* draws a character at x,y. */
810 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr)
813 m.m11 = obj->fontm11;
814 m.m12 = obj->fontm12;
815 m.m21 = obj->fontm21;
816 m.m22 = obj->fontm22;
819 drawchar(obj, obj->font, character, charnr, &m);
822 /* initialize the swf writer */
823 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
828 memset(obj, 0, sizeof(struct swfoutput));
829 filename = _filename;
833 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
837 memset(&swf,0x00,sizeof(SWF));
840 swf.frameRate = 0x0040; // 1 frame per 4 seconds
841 swf.movieSize.xmax = 20*sizex;
842 swf.movieSize.ymax = 20*sizey;
844 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
849 swf_SetRGB(tag,&rgb);
850 if(flag_protected) // good practice! /r
851 tag = swf_InsertTag(tag, ST_PROTECT);
856 void swfoutput_setprotected() //write PROTECT tag
861 void startshape(struct swfoutput*obj)
869 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
871 swf_ShapeNew(&shape);
872 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
873 rgb.r = obj->fillrgb.r;
874 rgb.g = obj->fillrgb.g;
875 rgb.b = obj->fillrgb.b;
876 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
878 shapeid = ++currentswfid;
879 swf_SetU16(tag,shapeid); // ID
888 swf_SetShapeStyles(tag,shape);
889 swf_ShapeCountBits(shape,NULL,NULL);
890 swf_SetShapeBits(tag,shape);
892 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
897 void starttext(struct swfoutput*obj)
903 tag = swf_InsertTag(tag,ST_DEFINETEXT);
904 textid = ++currentswfid;
905 swf_SetU16(tag, textid);
921 swf_SetMatrix(tag,&m);
929 swf_ShapeSetEnd(tag);
930 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
931 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
941 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
942 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
946 void endpage(struct swfoutput*obj)
953 swfoutput_endclip(obj);
954 tag = swf_InsertTag(tag,ST_SHOWFRAME);
957 void swfoutput_newpage(struct swfoutput*obj)
961 for(depth--;depth>=startdepth;depth--) {
962 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
963 swf_SetU16(tag,depth);
970 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
971 up, complete the swf, and write it out. */
972 void swfoutput_destroy(struct swfoutput* obj)
975 fontlist_t *tmp,*iterator = fontlist;
977 delete iterator->font;
980 iterator = iterator->next;
988 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
993 logf("<fatal> Could not create \"%s\". ", filename);
997 tag = swf_InsertTag(tag,ST_END);
999 if FAILED(swf_WriteSWF(fi,&swf))
1000 logf("<error> WriteSWF() failed.\n");
1003 logf("<notice> SWF written\n");
1006 void swfoutput_setdrawmode(swfoutput* obj, int mode)
1009 if(mode == DRAWMODE_FILL)
1011 else if(mode == DRAWMODE_EOFILL)
1013 else if(mode == DRAWMODE_STROKE)
1015 else if(mode == DRAWMODE_CLIP)
1017 else if(mode == DRAWMODE_EOCLIP)
1021 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1023 if(obj->fillrgb.r == r &&
1024 obj->fillrgb.g == g &&
1025 obj->fillrgb.b == b &&
1026 obj->fillrgb.a == a) return;
1036 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1038 if(obj->strokergb.r == r &&
1039 obj->strokergb.g == g &&
1040 obj->strokergb.b == b &&
1041 obj->strokergb.a == a) return;
1045 obj->strokergb.r = r;
1046 obj->strokergb.g = g;
1047 obj->strokergb.b = b;
1048 obj->strokergb.a = a;
1051 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
1053 if(obj->linewidth == (u16)(linewidth*20))
1058 obj->linewidth = (u16)(linewidth*20);
1062 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1071 logf("<warning> Too many clip levels.");
1076 int olddrawmode = drawmode;
1077 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1078 swfoutput_drawpath(obj, outline, m);
1079 swf_ShapeSetEnd(tag);
1080 swfoutput_setdrawmode(obj, olddrawmode);
1082 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1083 cliptags[clippos] = tag;
1084 clipshapes[clippos] = shapeid;
1085 clipdepths[clippos] = depth++;
1090 void swfoutput_endclip(swfoutput*obj)
1098 logf("<error> Invalid end of clipping region");
1102 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1105 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1107 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1116 actions = swf_ActionStart();
1118 action_GetUrl(url, "_parent");
1120 action_GetUrl(url, "_this");
1124 drawlink(obj, actions, points);
1126 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1135 actions = swf_ActionStart();
1136 action_GotoFrame(page);
1140 drawlink(obj, actions, points);
1143 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1149 struct plotxy p1,p2,p3,p4;
1153 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1155 int buttonid = ++currentswfid;
1158 if(points[t].x>xmax) xmax=points[t].x;
1159 if(points[t].y>ymax) ymax=points[t].y;
1160 if(points[t].x<xmin) xmin=points[t].x;
1161 if(points[t].y<ymin) ymin=points[t].y;
1163 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1164 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1167 myshapeid = ++currentswfid;
1168 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1169 swf_ShapeNew(&shape);
1170 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1171 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1172 swf_SetU16(tag, myshapeid);
1173 r.xmin = (int)(xmin*20);
1174 r.ymin = (int)(ymin*20);
1175 r.xmax = (int)(xmax*20);
1176 r.ymax = (int)(ymax*20);
1177 swf_SetRect(tag,&r);
1178 swf_SetShapeStyles(tag,shape);
1179 swf_ShapeCountBits(shape,NULL,NULL);
1180 swf_SetShapeBits(tag,shape);
1181 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1182 swflastx = swflasty = 0;
1188 swf_ShapeSetEnd(tag);
1191 myshapeid2 = ++currentswfid;
1192 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1193 swf_ShapeNew(&shape);
1194 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1196 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1197 swf_SetU16(tag, myshapeid2);
1198 r.xmin = (int)(xmin*20);
1199 r.ymin = (int)(ymin*20);
1200 r.xmax = (int)(xmax*20);
1201 r.ymax = (int)(ymax*20);
1202 swf_SetRect(tag,&r);
1203 swf_SetShapeStyles(tag,shape);
1204 swf_ShapeCountBits(shape,NULL,NULL);
1205 swf_SetShapeBits(tag,shape);
1206 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1207 swflastx = swflasty = 0;
1213 swf_ShapeSetEnd(tag);
1215 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1216 swf_SetU16(tag,buttonid); //id
1217 swf_ButtonSetFlags(tag, 0); //menu=no
1218 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1219 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1220 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1221 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1223 swf_ActionSet(tag,actions);
1226 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1227 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1230 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1231 double x1,double y1,
1232 double x2,double y2,
1233 double x3,double y3,
1234 double x4,double y4)
1240 struct plotxy p1,p2,p3,p4;
1242 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1243 if(x2>xmax) xmax=x2;
1244 if(y2>ymax) ymax=y2;
1245 if(x2<xmin) xmin=x2;
1246 if(y2<ymin) ymin=y2;
1247 if(x3>xmax) xmax=x3;
1248 if(y3>ymax) ymax=y3;
1249 if(x3<xmin) xmin=x3;
1250 if(y3<ymin) ymin=y3;
1251 if(x4>xmax) xmax=x4;
1252 if(y4>ymax) ymax=y4;
1253 if(x4<xmin) xmin=x4;
1254 if(y4<ymin) ymin=y4;
1265 m.sx = (int)(65536*20*(x4-x1))/sizex;
1266 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1267 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1268 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1270 m.tx = (int)(x1*20);
1271 m.ty = (int)(y1*20);
1274 myshapeid = ++currentswfid;
1275 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1276 swf_ShapeNew(&shape);
1277 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1278 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1279 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1280 swf_SetU16(tag, myshapeid);
1281 r.xmin = (int)(xmin*20);
1282 r.ymin = (int)(ymin*20);
1283 r.xmax = (int)(xmax*20);
1284 r.ymax = (int)(ymax*20);
1285 swf_SetRect(tag,&r);
1286 swf_SetShapeStyles(tag,shape);
1287 swf_ShapeCountBits(shape,NULL,NULL);
1288 swf_SetShapeBits(tag,shape);
1289 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1290 swflastx = swflasty = 0;
1297 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1298 ShapeSetLine (tag, shape, (int)(x1*20);
1299 ShapeSetLine (tag, shape, x*20,0);
1300 ShapeSetLine (tag, shape, 0,-y*20);
1301 ShapeSetLine (tag, shape, -x*20,0);*/
1302 swf_ShapeSetEnd(tag);
1305 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1306 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1309 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1310 double x1,double y1,
1311 double x2,double y2,
1312 double x3,double y3,
1313 double x4,double y4)
1321 int bitid = ++currentswfid;
1323 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1324 swf_SetU16(tag, bitid);
1325 if(swf_SetJPEGBits(tag, filename, jpegquality)<0) {
1331 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1335 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1336 double x1,double y1,
1337 double x2,double y2,
1338 double x3,double y3,
1339 double x4,double y4)
1347 int bitid = ++currentswfid;
1349 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1350 swf_SetU16(tag, bitid);
1351 if(swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT)<0) {
1357 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1361 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1362 double x1,double y1,
1363 double x2,double y2,
1364 double x3,double y3,
1365 double x4,double y4)
1373 int bitid = ++currentswfid;
1375 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1376 swf_SetU16(tag, bitid);
1377 if(swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256)<0) {
1383 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1387 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1388 double x1,double y1,
1389 double x2,double y2,
1390 double x3,double y3,
1391 double x4,double y4)
1399 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);