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]] = swf_GetTagLen(ftag)-initpos;
630 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
634 swf_ShapeSetStyle(ftag,&s,0,1,0);
638 drawpath(ftag, outline[swfcharid2char[t]],&m, 0);
641 swf_ShapeSetEnd(ftag);
643 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
644 swf_SetU16(ftag, this->swfid);
646 swf_SetU8(ftag, strlen(this->fontid));
647 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
651 swf_SetU8(ftag, 0); //flags
652 for(t=0;t<swfcharpos;t++)
655 char * name = this->charname[this->swfcharid2char[t]];
657 if(standardEncodingNames[s] &&
658 !strcmp(name,standardEncodingNames[s]))
661 swf_SetU8(ftag, (U8)s);
667 for(t=0;t<charnum;t++)
669 for(t=0;t<standardtablesize;t++)
670 if(standardtable[t]) {
671 free(standardtable[t]);
677 free(swfcharid2char);
678 free(char2swfcharid);
681 T1_OUTLINE*SWFFont::getOutline(char*name)
684 for(t=0;t<this->charnum;t++) {
685 if(!strcmp(this->charname[t],name)) {
688 swfcharid2char[swfcharpos] = t;
689 char2swfcharid[t] = swfcharpos;
699 int SWFFont::getWidth(char*name)
702 for(t=0;t<this->charnum;t++) {
703 if(!strcmp(this->charname[t],name)) {
704 return this->width[t];
710 int SWFFont::getSWFCharID(char*name, int charnr)
713 for(t=0;t<this->charnum;t++) {
714 if(!strcmp(this->charname[t],name)) {
717 swfcharid2char[swfcharpos] = t;
718 char2swfcharid[t] = swfcharpos++;
721 return char2swfcharid[t];
724 if(this->standardtable && charnr>=0 && charnr < this->standardtablesize) {
725 return getSWFCharID(this->standardtable[charnr], -1);
727 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
731 char*SWFFont::getName()
742 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
743 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
745 fontlist_t*last=0,*iterator;
746 if(obj->font && !strcmp(obj->font->fontid,fontid))
751 if(!strcmp(iterator->font->fontid,fontid))
754 iterator = iterator->next;
758 obj->font = iterator->font;
763 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
766 SWFFont*font = new SWFFont(fontid, t1id, filename);
767 iterator = new fontlist_t;
768 iterator->font = font;
772 last->next = iterator;
778 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
780 fontlist_t *iterator = fontlist;
782 if(!strcmp(iterator->font->fontid,fontid))
784 iterator = iterator->next;
789 /* set's the matrix which is to be applied to characters drawn by
790 swfoutput_drawchar() */
791 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
792 double m21,double m22)
794 if(obj->fontm11 == m11 &&
795 obj->fontm12 == m12 &&
796 obj->fontm21 == m21 &&
807 /* draws a character at x,y. */
808 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr)
811 m.m11 = obj->fontm11;
812 m.m12 = obj->fontm12;
813 m.m21 = obj->fontm21;
814 m.m22 = obj->fontm22;
817 drawchar(obj, obj->font, character, charnr, &m);
820 /* initialize the swf writer */
821 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
826 memset(obj, 0, sizeof(struct swfoutput));
827 filename = _filename;
831 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
835 memset(&swf,0x00,sizeof(SWF));
838 swf.frameRate = 0x0040; // 1 frame per 4 seconds
839 swf.movieSize.xmax = 20*sizex;
840 swf.movieSize.ymax = 20*sizey;
842 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
847 swf_SetRGB(tag,&rgb);
848 if(flag_protected) // good practice! /r
849 tag = swf_InsertTag(tag, ST_PROTECT);
854 void swfoutput_setprotected() //write PROTECT tag
859 void startshape(struct swfoutput*obj)
867 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
869 swf_ShapeNew(&shape);
870 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
871 rgb.r = obj->fillrgb.r;
872 rgb.g = obj->fillrgb.g;
873 rgb.b = obj->fillrgb.b;
874 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
876 shapeid = ++currentswfid;
877 swf_SetU16(tag,shapeid); // ID
886 swf_SetShapeStyles(tag,shape);
887 swf_ShapeCountBits(shape,NULL,NULL);
888 swf_SetShapeBits(tag,shape);
890 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
895 void starttext(struct swfoutput*obj)
901 tag = swf_InsertTag(tag,ST_DEFINETEXT);
902 textid = ++currentswfid;
903 swf_SetU16(tag, textid);
919 swf_SetMatrix(tag,&m);
927 swf_ShapeSetEnd(tag);
928 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
929 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
939 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
940 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
944 void endpage(struct swfoutput*obj)
951 swfoutput_endclip(obj);
952 tag = swf_InsertTag(tag,ST_SHOWFRAME);
955 void swfoutput_newpage(struct swfoutput*obj)
959 for(depth--;depth>=startdepth;depth--) {
960 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
961 swf_SetU16(tag,depth);
968 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
969 up, complete the swf, and write it out. */
970 void swfoutput_destroy(struct swfoutput* obj)
973 fontlist_t *tmp,*iterator = fontlist;
975 delete iterator->font;
978 iterator = iterator->next;
986 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
991 logf("<fatal> Could not create \"%s\". ", filename);
995 tag = swf_InsertTag(tag,ST_END);
997 if FAILED(swf_WriteSWF(fi,&swf))
998 logf("<error> WriteSWF() failed.\n");
1001 logf("<notice> SWF written\n");
1004 void swfoutput_setdrawmode(swfoutput* obj, int mode)
1007 if(mode == DRAWMODE_FILL)
1009 else if(mode == DRAWMODE_EOFILL)
1011 else if(mode == DRAWMODE_STROKE)
1013 else if(mode == DRAWMODE_CLIP)
1015 else if(mode == DRAWMODE_EOCLIP)
1019 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1021 if(obj->fillrgb.r == r &&
1022 obj->fillrgb.g == g &&
1023 obj->fillrgb.b == b &&
1024 obj->fillrgb.a == a) return;
1034 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1036 if(obj->strokergb.r == r &&
1037 obj->strokergb.g == g &&
1038 obj->strokergb.b == b &&
1039 obj->strokergb.a == a) return;
1043 obj->strokergb.r = r;
1044 obj->strokergb.g = g;
1045 obj->strokergb.b = b;
1046 obj->strokergb.a = a;
1049 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
1051 if(obj->linewidth == (u16)(linewidth*20))
1056 obj->linewidth = (u16)(linewidth*20);
1060 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1069 logf("<warning> Too many clip levels.");
1074 int olddrawmode = drawmode;
1075 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1076 swfoutput_drawpath(obj, outline, m);
1077 swf_ShapeSetEnd(tag);
1078 swfoutput_setdrawmode(obj, olddrawmode);
1080 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1081 cliptags[clippos] = tag;
1082 clipshapes[clippos] = shapeid;
1083 clipdepths[clippos] = depth++;
1088 void swfoutput_endclip(swfoutput*obj)
1096 logf("<error> Invalid end of clipping region");
1100 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1103 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1105 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1114 actions = swf_ActionStart();
1116 action_GetUrl(url, "_parent");
1118 action_GetUrl(url, "_this");
1122 drawlink(obj, actions, points);
1124 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1133 actions = swf_ActionStart();
1134 action_GotoFrame(page);
1138 drawlink(obj, actions, points);
1141 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1147 struct plotxy p1,p2,p3,p4;
1151 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1153 int buttonid = ++currentswfid;
1156 if(points[t].x>xmax) xmax=points[t].x;
1157 if(points[t].y>ymax) ymax=points[t].y;
1158 if(points[t].x<xmin) xmin=points[t].x;
1159 if(points[t].y<ymin) ymin=points[t].y;
1161 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1162 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1165 myshapeid = ++currentswfid;
1166 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1167 swf_ShapeNew(&shape);
1168 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1169 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1170 swf_SetU16(tag, myshapeid);
1171 r.xmin = (int)(xmin*20);
1172 r.ymin = (int)(ymin*20);
1173 r.xmax = (int)(xmax*20);
1174 r.ymax = (int)(ymax*20);
1175 swf_SetRect(tag,&r);
1176 swf_SetShapeStyles(tag,shape);
1177 swf_ShapeCountBits(shape,NULL,NULL);
1178 swf_SetShapeBits(tag,shape);
1179 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1180 swflastx = swflasty = 0;
1186 swf_ShapeSetEnd(tag);
1189 myshapeid2 = ++currentswfid;
1190 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1191 swf_ShapeNew(&shape);
1192 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1194 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1195 swf_SetU16(tag, myshapeid2);
1196 r.xmin = (int)(xmin*20);
1197 r.ymin = (int)(ymin*20);
1198 r.xmax = (int)(xmax*20);
1199 r.ymax = (int)(ymax*20);
1200 swf_SetRect(tag,&r);
1201 swf_SetShapeStyles(tag,shape);
1202 swf_ShapeCountBits(shape,NULL,NULL);
1203 swf_SetShapeBits(tag,shape);
1204 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1205 swflastx = swflasty = 0;
1211 swf_ShapeSetEnd(tag);
1213 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1214 swf_SetU16(tag,buttonid); //id
1215 swf_ButtonSetFlags(tag, 0); //menu=no
1216 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1217 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1218 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1219 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1221 swf_ActionSet(tag,actions);
1224 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1225 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1228 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1229 double x1,double y1,
1230 double x2,double y2,
1231 double x3,double y3,
1232 double x4,double y4)
1238 struct plotxy p1,p2,p3,p4;
1240 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1241 if(x2>xmax) xmax=x2;
1242 if(y2>ymax) ymax=y2;
1243 if(x2<xmin) xmin=x2;
1244 if(y2<ymin) ymin=y2;
1245 if(x3>xmax) xmax=x3;
1246 if(y3>ymax) ymax=y3;
1247 if(x3<xmin) xmin=x3;
1248 if(y3<ymin) ymin=y3;
1249 if(x4>xmax) xmax=x4;
1250 if(y4>ymax) ymax=y4;
1251 if(x4<xmin) xmin=x4;
1252 if(y4<ymin) ymin=y4;
1263 m.sx = (int)(65536*20*(x4-x1))/sizex;
1264 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1265 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1266 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1268 m.tx = (int)(x1*20);
1269 m.ty = (int)(y1*20);
1272 myshapeid = ++currentswfid;
1273 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1274 swf_ShapeNew(&shape);
1275 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1276 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1277 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1278 swf_SetU16(tag, myshapeid);
1279 r.xmin = (int)(xmin*20);
1280 r.ymin = (int)(ymin*20);
1281 r.xmax = (int)(xmax*20);
1282 r.ymax = (int)(ymax*20);
1283 swf_SetRect(tag,&r);
1284 swf_SetShapeStyles(tag,shape);
1285 swf_ShapeCountBits(shape,NULL,NULL);
1286 swf_SetShapeBits(tag,shape);
1287 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1288 swflastx = swflasty = 0;
1295 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1296 ShapeSetLine (tag, shape, (int)(x1*20);
1297 ShapeSetLine (tag, shape, x*20,0);
1298 ShapeSetLine (tag, shape, 0,-y*20);
1299 ShapeSetLine (tag, shape, -x*20,0);*/
1300 swf_ShapeSetEnd(tag);
1303 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1304 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1307 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1308 double x1,double y1,
1309 double x2,double y2,
1310 double x3,double y3,
1311 double x4,double y4)
1319 int bitid = ++currentswfid;
1321 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1322 swf_SetU16(tag, bitid);
1323 if(swf_SetJPEGBits(tag, filename, jpegquality)<0) {
1329 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1333 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1334 double x1,double y1,
1335 double x2,double y2,
1336 double x3,double y3,
1337 double x4,double y4)
1345 int bitid = ++currentswfid;
1347 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1348 swf_SetU16(tag, bitid);
1349 if(swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT)<0) {
1355 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1359 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1360 double x1,double y1,
1361 double x2,double y2,
1362 double x3,double y3,
1363 double x4,double y4)
1371 int bitid = ++currentswfid;
1373 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1374 swf_SetU16(tag, bitid);
1375 if(swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256)<0) {
1381 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1385 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1386 double x1,double y1,
1387 double x2,double y2,
1388 double x3,double y3,
1389 double x4,double y4)
1397 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);