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, int charnr, swfmatrix*m)
427 if(m->m12!=0 || m->m21!=0)
432 if(usefonts && ! drawonlyshapes)
434 int charid = font->getSWFCharID(character, charnr);
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);
520 logf("<verbose> Font %s(%d): Storing %d outlines.\n", name, id, charnum);
522 this->standardtablesize = 256;
523 if(this->charnum < this->standardtablesize)
524 this->standardtablesize = this->charnum;
525 this->standardtable = (char**)malloc(standardtablesize*sizeof(char*));
527 for(t = 0; t < this->standardtablesize; t++) {
528 char*name = T1_GetCharName(id,t);
531 standardtable[t] = strdup(name);
534 outline = (T1_OUTLINE**)malloc(charnum*sizeof(T1_OUTLINE*));
535 charname = (char**)malloc(charnum*sizeof(char*));
536 width = (int*)malloc(charnum*sizeof(int));
537 memset(width, 0, charnum*sizeof(int));
538 memset(charname, 0, charnum*sizeof(char*));
539 used = (char*)malloc(charnum*sizeof(char));
540 char2swfcharid = (U16*)malloc(charnum*2);
541 swfcharid2char = (U16*)malloc(charnum*2);
544 memset(used,0,charnum*sizeof(char));
546 this->swfid = ++currentswfid;
559 int ret = T1_ReencodeFont(id, map);
563 int ret = T1_ReencodeFont(id, map);
565 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
571 char* name = T1_GetCharName(id, s);
573 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
574 this->width[outlinepos] = T1_GetCharWidth(id, s);
575 this->charname[outlinepos] = strdup(name);
583 /* free all tables, write out definefont tags */
589 if(storeallcharacters)
592 for(t=0;t<this->charnum;t++)
594 if(this->charname[t])
595 getSWFCharID(this->charname[t], -1);
599 ptr = (int*)malloc(swfcharpos*sizeof(int));
601 for(t=0;t<charnum;t++)
602 if(used[t]) usednum++;
604 if(usednum && !drawonlyshapes)
606 logf("<verbose> Font %s has %d used characters",fontid, usednum);
607 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
608 swf_SetU16(ftag, this->swfid);
609 int initpos = swf_GetDataSize(ftag);
616 for(t=0;t<swfcharpos;t++)
618 ptr[t] = swf_GetDataSize(ftag);
619 swf_SetU16(ftag, 0x1234);
621 for(t=0;t<swfcharpos;t++)
623 *(U16*)&ftag->data[ptr[t]] = swf_GetDataSize(ftag)-initpos;
626 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
630 swf_ShapeSetStyle(ftag,&s,0,1,0);
634 drawpath(ftag, outline[swfcharid2char[t]],&m);
637 swf_ShapeSetEnd(ftag);
639 ftag = swf_InsertTag(ftag,ST_DEFINEFONTINFO);
640 swf_SetU16(ftag, this->swfid);
642 swf_SetU8(ftag, strlen(this->fontid));
643 swf_SetBlock(ftag, (U8*)this->fontid, strlen(this->fontid));
647 swf_SetU8(ftag, 0); //flags
648 for(t=0;t<swfcharpos;t++)
651 char * name = this->charname[this->swfcharid2char[t]];
653 if(standardEncodingNames[s] &&
654 !strcmp(name,standardEncodingNames[s]))
657 swf_SetU8(ftag, (U8)s);
663 for(t=0;t<charnum;t++)
665 for(t=0;t<standardtablesize;t++)
666 if(standardtable[t]) {
667 free(standardtable[t]);
673 free(swfcharid2char);
674 free(char2swfcharid);
677 T1_OUTLINE*SWFFont::getOutline(char*name)
680 for(t=0;t<this->charnum;t++) {
681 if(!strcmp(this->charname[t],name)) {
684 swfcharid2char[swfcharpos] = t;
685 char2swfcharid[t] = swfcharpos;
695 int SWFFont::getSWFCharID(char*name, int charnr)
698 for(t=0;t<this->charnum;t++) {
699 if(!strcmp(this->charname[t],name)) {
702 swfcharid2char[swfcharpos] = t;
703 char2swfcharid[t] = swfcharpos++;
706 return char2swfcharid[t];
709 if(this->standardtable && charnr>=0 && charnr < this->standardtablesize) {
710 return getSWFCharID(this->standardtable[charnr], -1);
712 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
716 char*SWFFont::getName()
727 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
728 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
730 fontlist_t*last=0,*iterator;
731 if(obj->font && !strcmp(obj->font->fontid,fontid))
736 if(!strcmp(iterator->font->fontid,fontid))
739 iterator = iterator->next;
743 obj->font = iterator->font;
748 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
751 SWFFont*font = new SWFFont(fontid, t1id, filename);
752 iterator = new fontlist_t;
753 iterator->font = font;
757 last->next = iterator;
763 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
765 fontlist_t *iterator = fontlist;
767 if(!strcmp(iterator->font->fontid,fontid))
769 iterator = iterator->next;
774 /* set's the matrix which is to be applied to characters drawn by
775 swfoutput_drawchar() */
776 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
777 double m21,double m22)
779 if(obj->fontm11 == m11 &&
780 obj->fontm12 == m12 &&
781 obj->fontm21 == m21 &&
792 /* draws a character at x,y. */
793 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, int charnr)
796 m.m11 = obj->fontm11;
797 m.m12 = obj->fontm12;
798 m.m21 = obj->fontm21;
799 m.m22 = obj->fontm22;
802 drawchar(obj, obj->font, character, charnr, &m);
805 /* initialize the swf writer */
806 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
811 memset(obj, 0, sizeof(struct swfoutput));
812 filename = _filename;
816 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
820 memset(&swf,0x00,sizeof(SWF));
823 swf.frameRate = 0x0040; // 1 frame per 4 seconds
824 swf.movieSize.xmax = 20*sizex;
825 swf.movieSize.ymax = 20*sizey;
827 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
832 swf_SetRGB(tag,&rgb);
833 if(flag_protected) // good practice! /r
834 tag = swf_InsertTag(tag, ST_PROTECT);
839 void swfoutput_setprotected() //write PROTECT tag
844 void startshape(struct swfoutput*obj)
852 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
854 swf_ShapeNew(&shape);
855 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
856 rgb.r = obj->fillrgb.r;
857 rgb.g = obj->fillrgb.g;
858 rgb.b = obj->fillrgb.b;
859 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
861 shapeid = ++currentswfid;
862 swf_SetU16(tag,shapeid); // ID
871 swf_SetShapeStyles(tag,shape);
872 swf_ShapeCountBits(shape,NULL,NULL);
873 swf_SetShapeBits(tag,shape);
875 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
880 void starttext(struct swfoutput*obj)
886 tag = swf_InsertTag(tag,ST_DEFINETEXT);
887 textid = ++currentswfid;
888 swf_SetU16(tag, textid);
904 swf_SetMatrix(tag,&m);
912 swf_ShapeSetEnd(tag);
913 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
914 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
924 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
925 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
929 void endpage(struct swfoutput*obj)
936 swfoutput_endclip(obj);
937 tag = swf_InsertTag(tag,ST_SHOWFRAME);
940 void swfoutput_newpage(struct swfoutput*obj)
944 for(depth--;depth>=startdepth;depth--) {
945 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
946 swf_SetU16(tag,depth);
953 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
954 up, complete the swf, and write it out. */
955 void swfoutput_destroy(struct swfoutput* obj)
958 fontlist_t *tmp,*iterator = fontlist;
960 delete iterator->font;
963 iterator = iterator->next;
971 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
976 logf("<fatal> Could not create \"%s\". ", filename);
980 tag = swf_InsertTag(tag,ST_END);
982 if FAILED(swf_WriteSWF(fi,&swf))
983 logf("<error> WriteSWF() failed.\n");
986 logf("<notice> SWF written\n");
989 void swfoutput_setdrawmode(swfoutput* obj, int mode)
992 if(mode == DRAWMODE_FILL)
994 else if(mode == DRAWMODE_EOFILL)
996 else if(mode == DRAWMODE_STROKE)
998 else if(mode == DRAWMODE_CLIP)
1000 else if(mode == DRAWMODE_EOCLIP)
1004 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1006 if(obj->fillrgb.r == r &&
1007 obj->fillrgb.g == g &&
1008 obj->fillrgb.b == b &&
1009 obj->fillrgb.a == a) return;
1019 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
1021 if(obj->strokergb.r == r &&
1022 obj->strokergb.g == g &&
1023 obj->strokergb.b == b &&
1024 obj->strokergb.a == a) return;
1028 obj->strokergb.r = r;
1029 obj->strokergb.g = g;
1030 obj->strokergb.b = b;
1031 obj->strokergb.a = a;
1034 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
1036 if(obj->linewidth == (u16)(linewidth*20))
1041 obj->linewidth = (u16)(linewidth*20);
1045 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
1054 logf("<warning> Too many clip levels.");
1059 int olddrawmode = drawmode;
1060 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
1061 swfoutput_drawpath(obj, outline, m);
1062 swf_ShapeSetEnd(tag);
1063 swfoutput_setdrawmode(obj, olddrawmode);
1065 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1066 cliptags[clippos] = tag;
1067 clipshapes[clippos] = shapeid;
1068 clipdepths[clippos] = depth++;
1073 void swfoutput_endclip(swfoutput*obj)
1081 logf("<error> Invalid end of clipping region");
1085 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1088 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1090 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1099 actions = swf_ActionStart();
1101 action_GetUrl(url, "_parent");
1103 action_GetUrl(url, "_this");
1107 drawlink(obj, actions, points);
1109 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1118 actions = swf_ActionStart();
1119 action_GotoFrame(page);
1123 drawlink(obj, actions, points);
1126 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1132 struct plotxy p1,p2,p3,p4;
1136 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1138 int buttonid = ++currentswfid;
1141 if(points[t].x>xmax) xmax=points[t].x;
1142 if(points[t].y>ymax) ymax=points[t].y;
1143 if(points[t].x<xmin) xmin=points[t].x;
1144 if(points[t].y<ymin) ymin=points[t].y;
1146 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1147 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1150 myshapeid = ++currentswfid;
1151 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1152 swf_ShapeNew(&shape);
1153 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1154 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1155 swf_SetU16(tag, myshapeid);
1156 r.xmin = (int)(xmin*20);
1157 r.ymin = (int)(ymin*20);
1158 r.xmax = (int)(xmax*20);
1159 r.ymax = (int)(ymax*20);
1160 swf_SetRect(tag,&r);
1161 swf_SetShapeStyles(tag,shape);
1162 swf_ShapeCountBits(shape,NULL,NULL);
1163 swf_SetShapeBits(tag,shape);
1164 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1165 swflastx = swflasty = 0;
1171 swf_ShapeSetEnd(tag);
1174 myshapeid2 = ++currentswfid;
1175 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1176 swf_ShapeNew(&shape);
1177 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1179 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1180 swf_SetU16(tag, myshapeid2);
1181 r.xmin = (int)(xmin*20);
1182 r.ymin = (int)(ymin*20);
1183 r.xmax = (int)(xmax*20);
1184 r.ymax = (int)(ymax*20);
1185 swf_SetRect(tag,&r);
1186 swf_SetShapeStyles(tag,shape);
1187 swf_ShapeCountBits(shape,NULL,NULL);
1188 swf_SetShapeBits(tag,shape);
1189 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1190 swflastx = swflasty = 0;
1196 swf_ShapeSetEnd(tag);
1198 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1199 swf_SetU16(tag,buttonid); //id
1200 swf_ButtonSetFlags(tag, 0); //menu=no
1201 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1202 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1203 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1204 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1206 swf_ActionSet(tag,actions);
1209 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1210 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1213 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1214 double x1,double y1,
1215 double x2,double y2,
1216 double x3,double y3,
1217 double x4,double y4)
1223 struct plotxy p1,p2,p3,p4;
1225 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1226 if(x2>xmax) xmax=x2;
1227 if(y2>ymax) ymax=y2;
1228 if(x2<xmin) xmin=x2;
1229 if(y2<ymin) ymin=y2;
1230 if(x3>xmax) xmax=x3;
1231 if(y3>ymax) ymax=y3;
1232 if(x3<xmin) xmin=x3;
1233 if(y3<ymin) ymin=y3;
1234 if(x4>xmax) xmax=x4;
1235 if(y4>ymax) ymax=y4;
1236 if(x4<xmin) xmin=x4;
1237 if(y4<ymin) ymin=y4;
1248 m.sx = (int)(65536*20*(x4-x1))/sizex;
1249 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1250 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1251 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1253 m.tx = (int)(x1*20);
1254 m.ty = (int)(y1*20);
1257 myshapeid = ++currentswfid;
1258 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1259 swf_ShapeNew(&shape);
1260 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1261 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1262 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1263 swf_SetU16(tag, myshapeid);
1264 r.xmin = (int)(xmin*20);
1265 r.ymin = (int)(ymin*20);
1266 r.xmax = (int)(xmax*20);
1267 r.ymax = (int)(ymax*20);
1268 swf_SetRect(tag,&r);
1269 swf_SetShapeStyles(tag,shape);
1270 swf_ShapeCountBits(shape,NULL,NULL);
1271 swf_SetShapeBits(tag,shape);
1272 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1273 swflastx = swflasty = 0;
1280 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1281 ShapeSetLine (tag, shape, (int)(x1*20);
1282 ShapeSetLine (tag, shape, x*20,0);
1283 ShapeSetLine (tag, shape, 0,-y*20);
1284 ShapeSetLine (tag, shape, -x*20,0);*/
1285 swf_ShapeSetEnd(tag);
1288 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1289 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1292 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1293 double x1,double y1,
1294 double x2,double y2,
1295 double x3,double y3,
1296 double x4,double y4)
1304 int bitid = ++currentswfid;
1306 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1307 swf_SetU16(tag, bitid);
1308 if(swf_SetJPEGBits(tag, filename, jpegquality)<0) {
1314 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1318 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1319 double x1,double y1,
1320 double x2,double y2,
1321 double x3,double y3,
1322 double x4,double y4)
1330 int bitid = ++currentswfid;
1332 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1333 swf_SetU16(tag, bitid);
1334 if(swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT)<0) {
1340 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1344 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1345 double x1,double y1,
1346 double x2,double y2,
1347 double x3,double y3,
1348 double x4,double y4)
1356 int bitid = ++currentswfid;
1358 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1359 swf_SetU16(tag, bitid);
1360 if(swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256)<0) {
1366 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1370 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1371 double x1,double y1,
1372 double x2,double y2,
1373 double x3,double y3,
1374 double x4,double y4)
1382 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);