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"
32 int ignoredraworder=0;
35 static int flag_protected = 0;
37 typedef unsigned char u8;
38 typedef unsigned short int u16;
39 typedef unsigned long int u32;
42 static char* filename = 0;
45 static int currentswfid = 0;
47 static int startdepth = 1;
50 static int shapeid = -1;
51 static int textid = -1;
53 static int drawmode = -1;
54 static char storefont = 0;
55 static int fillstyleid;
56 static int linestyleid;
57 static int swflastx=0;
58 static int swflasty=0;
59 static int lastwasfill = 0;
71 void startshape(struct swfoutput* obj);
72 void starttext(struct swfoutput* obj);
76 // matrix multiplication. changes p0
77 void transform (plotxy*p0,struct swfmatrix*m)
80 x = m->m11*p0->x+m->m12*p0->y;
81 y = m->m21*p0->x+m->m22*p0->y;
86 // write a move-to command into the swf
87 void moveto(TAG*tag, plotxy p0)
89 int rx = (int)(p0.x*20);
90 int ry = (int)(p0.y*20);
91 if(rx!=swflastx || ry!=swflasty) {
92 swf_ShapeSetMove (tag, shape, rx,ry);
98 // write a line-to command into the swf
99 void lineto(TAG*tag, plotxy p0)
101 int rx = ((int)(p0.x*20)-swflastx);
102 int ry = ((int)(p0.y*20)-swflasty);
103 /* we can't skip this for rx=0,ry=0, those
105 swf_ShapeSetLine (tag, shape, rx,ry);
110 // write a spline-to command into the swf
111 void splineto(TAG*tag, plotxy control,plotxy end)
113 int cx = ((int)(control.x*20)-swflastx);
114 int cy = ((int)(control.y*20)-swflasty);
117 int ex = ((int)(end.x*20)-swflastx);
118 int ey = ((int)(end.y*20)-swflasty);
121 swf_ShapeSetCurve(tag, shape, cx,cy,ex,ey);
124 /* write a line, given two points and the transformation
126 void line(TAG*tag, plotxy p0, plotxy p1, struct swfmatrix*m)
134 /* write a cubic (!) spline. This involves calling the approximate()
135 function out of spline.cc to convert it to a quadratic spline. */
136 void spline(TAG*tag,plotxy p0,plotxy p1,plotxy p2,plotxy p3,struct swfmatrix*m)
139 struct qspline q[16];
147 num = approximate(p0,p1,p2,p3,q);
149 moveto(tag,q[t].start);
150 splineto(tag,q[t].control, q[t].end);
154 /* draw a T1 outline. These are generated by pdf2swf and by t1lib.
155 (representing characters) */
156 void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m)
158 if(tag->id != ST_DEFINEFONT &&
159 tag->id != ST_DEFINESHAPE &&
160 tag->id != ST_DEFINESHAPE2 &&
161 tag->id != ST_DEFINESHAPE3)
163 logf("<error> internal error: drawpath needs a shape tag, not %d\n",tag->id);
169 double lastx=0,lasty=0;
170 double firstx=0,firsty=0;
175 x += (outline->dest.x/(float)0xffff);
176 y += (outline->dest.y/(float)0xffff);
177 if(outline->type == T1_PATHTYPE_MOVE)
179 if(((int)(lastx*20) != (int)(firstx*20) ||
180 (int)(lasty*20) != (int)(firsty*20)) &&
189 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
190 line(tag, p0, p1, m);
196 else if(outline->type == T1_PATHTYPE_LINE)
204 if(log) printf("line: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
207 else if(outline->type == T1_PATHTYPE_BEZIER)
213 T1_BEZIERSEGMENT*o2 = (T1_BEZIERSEGMENT*)outline;
216 p1.x=o2->C.x/(float)0xffff+lastx;
217 p1.y=o2->C.y/(float)0xffff+lasty;
218 p2.x=o2->B.x/(float)0xffff+lastx;
219 p2.y=o2->B.y/(float)0xffff+lasty;
222 if(log) printf("spline: %f,%f -> %f,%f\n",p3.x,p3.y,p0.x,p0.y);
223 spline(tag,p0,p1,p2,p3,m);
226 logf("<error> drawpath: unknown outline type:%d\n", outline->type);
230 outline = outline->link;
232 if(((int)(lastx*20) != (int)(firstx*20) ||
233 (int)(lasty*20) != (int)(firsty*20)) &&
242 if(log) printf("fix: %f,%f -> %f,%f\n",p0.x,p0.y,p1.x,p1.y);
243 line(tag, p0, p1, m);
247 int colorcompare(RGBA*a,RGBA*b)
259 static const int CHARDATAMAX = 1024;
267 } chardata[CHARDATAMAX];
270 void putcharacters(TAG*tag)
275 color.r = chardata[0].color.r^255;
284 int charadvance[128];
287 int glyphbits=1; //TODO: can this be zero?
290 if(tag->id != ST_DEFINETEXT &&
291 tag->id != ST_DEFINETEXT2) {
292 logf("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
296 logf("<warning> putcharacters called with zero characters");
299 for(pass = 0; pass < 2; pass++)
309 advancebits++; // add sign bit
310 swf_SetU8(tag, glyphbits);
311 swf_SetU8(tag, advancebits);
314 for(t=0;t<=chardatapos;t++)
316 if(lastfontid != chardata[t].fontid ||
317 lastx!=chardata[t].x ||
318 lasty!=chardata[t].y ||
319 !colorcompare(&color, &chardata[t].color) ||
321 lastsize != chardata[t].size ||
324 if(charstorepos && pass==0)
327 for(s=0;s<charstorepos;s++)
329 while(charids[s]>=(1<<glyphbits))
331 while(charadvance[s]>=(1<<advancebits))
335 if(charstorepos && pass==1)
337 tag->writeBit = 0; // Q&D
338 swf_SetBits(tag, 0, 1); // GLYPH Record
339 swf_SetBits(tag, charstorepos, 7); // number of glyphs
341 for(s=0;s<charstorepos;s++)
343 swf_SetBits(tag, charids[s], glyphbits);
344 swf_SetBits(tag, charadvance[s], advancebits);
349 if(pass == 1 && t<chardatapos)
355 if(lastx != chardata[t].x ||
356 lasty != chardata[t].y)
361 if(!colorcompare(&color, &chardata[t].color))
363 color = chardata[t].color;
366 font.id = chardata[t].fontid;
367 if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
370 tag->writeBit = 0; // Q&D
371 swf_TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
374 lastfontid = chardata[t].fontid;
375 lastx = chardata[t].x;
376 lasty = chardata[t].y;
377 lastsize = chardata[t].size;
384 int nextt = t==chardatapos-1?t:t+1;
385 int rel = chardata[nextt].x-chardata[t].x;
386 if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
388 lastx=chardata[nextt].x;
394 charids[charstorepos] = chardata[t].charid;
395 charadvance[charstorepos] = advance;
402 void putcharacter(struct swfoutput*obj, int fontid, int charid,
403 int x,int y, int size)
405 if(chardatapos == CHARDATAMAX)
410 chardata[chardatapos].fontid = fontid;
411 chardata[chardatapos].charid = charid;
412 chardata[chardatapos].x = x;
413 chardata[chardatapos].y = y;
414 chardata[chardatapos].color = obj->fillrgb;
415 chardata[chardatapos].size = size;
420 /* process a character. */
421 void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m)
424 if(m->m12!=0 || m->m21!=0)
429 if(usefonts && ! drawonlyshapes)
431 int charid = font->getSWFCharID(character);
436 putcharacter(obj, font->swfid, charid,(int)(m->m13*20),(int)(m->m23*20),
437 (int)(m->m11*20/2+0.5)); //where does the /2 come from?
441 T1_OUTLINE*outline = font->getOutline(character);
442 char* charname = character;
445 logf("<warning> Didn't find %s in current charset (%s)",
446 character,font->getName());
462 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
467 drawpath(tag, outline, &m2);
472 /* draw a curved polygon. */
473 void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline,
481 if(lastwasfill && !fill)
483 swf_ShapeSetStyle(tag,shape,linestyleid,0x8000,0);
486 if(!lastwasfill && fill)
488 swf_ShapeSetStyle(tag,shape,0x8000,fillstyleid,0);
492 drawpath(tag, outline,m);
495 /* SWFFont: copy all t1 font outlines to a local
497 SWFFont::SWFFont(char*name, int id, char*filename)
499 if(!T1_GetFontName(id))
502 this->name = strdup(T1_GetFontFileName(id));
503 this->fontid = strdup(name);
506 char**a= T1_GetAllCharNames(id);
507 int t=0, outlinepos=0;
515 logf("<verbose> Font %s(%d): Storing %d outlines.\n", name, id, t);
517 outline = (T1_OUTLINE**)malloc(t*sizeof(T1_OUTLINE*));
518 charname = (char**)malloc(t*sizeof(char*));
519 used = (char*)malloc(t*sizeof(char));
520 char2swfcharid = (U16*)malloc(t*2);
521 swfcharid2char = (U16*)malloc(t*2);
524 memset(used,0,t*sizeof(char));
526 this->swfid = ++currentswfid;
540 int ret = T1_ReencodeFont(id, map);
544 int ret = T1_ReencodeFont(id, map);
546 fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret);
552 this->outline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0));
553 this->charname[outlinepos] = strdup(T1_GetCharName(id, s));
561 /* free all tables, write out definefont tags */
565 int*ptr = (int*)malloc(swfcharpos*sizeof(int));
567 for(t=0;t<charnum;t++)
568 if(used[t]) usednum++;
570 if(usednum && !drawonlyshapes)
572 logf("<verbose> Font %s has %d used characters",fontid, usednum);
573 TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT);
574 swf_SetU16(ftag, this->swfid);
575 int initpos = swf_GetDataSize(ftag);
581 for(t=0;t<swfcharpos;t++)
583 ptr[t] = swf_GetDataSize(ftag);
584 swf_SetU16(ftag, 0x1234);
586 for(t=0;t<swfcharpos;t++)
588 *(U16*)&ftag->data[ptr[t]] = swf_GetDataSize(ftag)-initpos;
591 swf_SetU8(ftag,0x10); //0 fill bits, 0 linestyle bits
595 swf_ShapeSetStyle(ftag,&s,0,1,0);
599 drawpath(ftag, outline[swfcharid2char[t]],&m);
602 swf_ShapeSetEnd(ftag);
608 for(t=0;t<charnum;t++)
612 free(swfcharid2char);
613 free(char2swfcharid);
616 T1_OUTLINE*SWFFont::getOutline(char*name)
619 for(t=0;t<this->charnum;t++) {
620 if(!strcmp(this->charname[t],name)) {
623 swfcharid2char[swfcharpos] = t;
624 char2swfcharid[t] = swfcharpos;
634 int SWFFont::getSWFCharID(char*name)
637 for(t=0;t<this->charnum;t++) {
638 if(!strcmp(this->charname[t],name)) {
641 swfcharid2char[swfcharpos] = t;
642 char2swfcharid[t] = swfcharpos++;
645 return char2swfcharid[t];
648 logf("<warning> Didn't find character '%s' in font '%s'", name, this->name);
652 char*SWFFont::getName()
663 /* set's the t1 font index of the font to use for swfoutput_drawchar(). */
664 void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename)
666 fontlist_t*last=0,*iterator;
667 if(obj->font && !strcmp(obj->font->fontid,fontid))
672 if(!strcmp(iterator->font->fontid,fontid))
675 iterator = iterator->next;
679 obj->font = iterator->font;
684 logf("<error> internal error: t1id:%d, fontid:%s\n", t1id,fontid);
687 SWFFont*font = new SWFFont(fontid, t1id, filename);
688 iterator = new fontlist_t;
689 iterator->font = font;
693 last->next = iterator;
699 int swfoutput_queryfont(struct swfoutput*obj, char*fontid)
701 fontlist_t *iterator = fontlist;
703 if(!strcmp(iterator->font->fontid,fontid))
705 iterator = iterator->next;
710 /* set's the matrix which is to be applied to characters drawn by
711 swfoutput_drawchar() */
712 void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12,
713 double m21,double m22)
715 if(obj->fontm11 == m11 &&
716 obj->fontm12 == m12 &&
717 obj->fontm21 == m21 &&
728 /* draws a character at x,y. */
729 void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character)
732 m.m11 = obj->fontm11;
733 m.m12 = obj->fontm12;
734 m.m21 = obj->fontm21;
735 m.m22 = obj->fontm22;
738 drawchar(obj, obj->font, character, &m);
741 /* initialize the swf writer */
742 void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey)
747 memset(obj, 0, sizeof(struct swfoutput));
748 filename = _filename;
752 logf("<verbose> initializing swf output for size %d*%d\n", sizex,sizey);
756 memset(&swf,0x00,sizeof(SWF));
759 swf.frameRate = 0x0040; // 1 frame per 4 seconds
760 swf.movieSize.xmax = 20*sizex;
761 swf.movieSize.ymax = 20*sizey;
763 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
768 swf_SetRGB(tag,&rgb);
769 if(flag_protected) // good practice! /r
770 tag = swf_InsertTag(tag, ST_PROTECT);
775 void swfoutput_setprotected() //write PROTECT tag
780 void startshape(struct swfoutput*obj)
788 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
790 swf_ShapeNew(&shape);
791 linestyleid = swf_ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
792 rgb.r = obj->fillrgb.r;
793 rgb.g = obj->fillrgb.g;
794 rgb.b = obj->fillrgb.b;
795 fillstyleid = swf_ShapeAddSolidFillStyle(shape,&obj->fillrgb);
797 shapeid = ++currentswfid;
798 swf_SetU16(tag,shapeid); // ID
807 swf_SetShapeStyles(tag,shape);
808 swf_ShapeCountBits(shape,NULL,NULL);
809 swf_SetShapeBits(tag,shape);
811 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,linestyleid,0,0);
816 void starttext(struct swfoutput*obj)
822 tag = swf_InsertTag(tag,ST_DEFINETEXT);
823 textid = ++currentswfid;
824 swf_SetU16(tag, textid);
840 swf_SetMatrix(tag,&m);
848 swf_ShapeSetEnd(tag);
849 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
850 swf_ObjectPlace(tag,shapeid,/*depth*/depth++,NULL,NULL,NULL);
860 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
861 swf_ObjectPlace(tag,textid,/*depth*/depth++,NULL,NULL,NULL);
865 void endpage(struct swfoutput*obj)
872 swfoutput_endclip(obj);
873 tag = swf_InsertTag(tag,ST_SHOWFRAME);
876 void swfoutput_newpage(struct swfoutput*obj)
880 for(depth--;depth>=startdepth;depth--) {
881 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
882 swf_SetU16(tag,depth);
889 /* "destroy" like in (oo-terminology) "destructor". Perform cleaning
890 up, complete the swf, and write it out. */
891 void swfoutput_destroy(struct swfoutput* obj)
894 fontlist_t *tmp,*iterator = fontlist;
896 delete iterator->font;
899 iterator = iterator->next;
907 fi = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0777);
912 logf("<fatal> Could not create \"%s\". ", filename);
916 tag = swf_InsertTag(tag,ST_END);
918 if FAILED(swf_WriteSWF(fi,&swf))
919 logf("<error> WriteSWF() failed.\n");
922 logf("<notice> SWF written\n");
925 void swfoutput_setdrawmode(swfoutput* obj, int mode)
928 if(mode == DRAWMODE_FILL)
930 else if(mode == DRAWMODE_EOFILL)
932 else if(mode == DRAWMODE_STROKE)
934 else if(mode == DRAWMODE_CLIP)
936 else if(mode == DRAWMODE_EOCLIP)
940 void swfoutput_setfillcolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
942 if(obj->fillrgb.r == r &&
943 obj->fillrgb.g == g &&
944 obj->fillrgb.b == b &&
945 obj->fillrgb.a == a) return;
955 void swfoutput_setstrokecolor(swfoutput* obj, u8 r, u8 g, u8 b, u8 a)
957 if(obj->strokergb.r == r &&
958 obj->strokergb.g == g &&
959 obj->strokergb.b == b &&
960 obj->strokergb.a == a) return;
964 obj->strokergb.r = r;
965 obj->strokergb.g = g;
966 obj->strokergb.b = b;
967 obj->strokergb.a = a;
970 void swfoutput_setlinewidth(struct swfoutput*obj, double linewidth)
972 if(obj->linewidth == (u16)(linewidth*20))
977 obj->linewidth = (u16)(linewidth*20);
981 void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m)
990 logf("<warning> Too many clip levels.");
995 int olddrawmode = drawmode;
996 swfoutput_setdrawmode(obj, DRAWMODE_CLIP);
997 swfoutput_drawpath(obj, outline, m);
998 swf_ShapeSetEnd(tag);
999 swfoutput_setdrawmode(obj, olddrawmode);
1001 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1002 cliptags[clippos] = tag;
1003 clipshapes[clippos] = shapeid;
1004 clipdepths[clippos] = depth++;
1009 void swfoutput_endclip(swfoutput*obj)
1017 logf("<error> Invalid end of clipping region");
1021 swf_ObjectPlaceClip(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
1024 void drawlink(struct swfoutput*obj, ActionTAG*, swfcoord*points);
1026 void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points)
1035 actions = swf_ActionStart(tag);
1037 action_GetUrl(url, "_parent");
1039 action_GetUrl(url, "_this");
1043 drawlink(obj, actions, points);
1045 void swfoutput_linktopage(struct swfoutput*obj, int page, swfcoord*points)
1054 actions = swf_ActionStart(tag);
1055 action_GotoFrame(page);
1059 drawlink(obj, actions, points);
1062 void drawlink(struct swfoutput*obj, ActionTAG*actions, swfcoord*points)
1068 struct plotxy p1,p2,p3,p4;
1072 double xmax=xmin=points[0].x,ymax=ymin=points[0].y;
1074 int buttonid = ++currentswfid;
1077 if(points[t].x>xmax) xmax=points[t].x;
1078 if(points[t].y>ymax) ymax=points[t].y;
1079 if(points[t].x<xmin) xmin=points[t].x;
1080 if(points[t].y<ymin) ymin=points[t].y;
1082 p1.x=points[0].x; p1.y=points[0].y; p2.x=points[1].x; p2.y=points[1].y;
1083 p3.x=points[2].x; p3.y=points[2].y; p4.x=points[3].x; p4.y=points[3].y;
1086 myshapeid = ++currentswfid;
1087 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1088 swf_ShapeNew(&shape);
1089 rgb.r = rgb.b = rgb.a = rgb.g = 0;
1090 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1091 swf_SetU16(tag, myshapeid);
1092 r.xmin = (int)(xmin*20);
1093 r.ymin = (int)(ymin*20);
1094 r.xmax = (int)(xmax*20);
1095 r.ymax = (int)(ymax*20);
1096 swf_SetRect(tag,&r);
1097 swf_SetShapeStyles(tag,shape);
1098 swf_ShapeCountBits(shape,NULL,NULL);
1099 swf_SetShapeBits(tag,shape);
1100 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1101 swflastx = swflasty = 0;
1107 swf_ShapeSetEnd(tag);
1110 myshapeid2 = ++currentswfid;
1111 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
1112 swf_ShapeNew(&shape);
1113 rgb.r = rgb.b = rgb.a = rgb.g = 255;
1115 fsid = swf_ShapeAddSolidFillStyle(shape,&rgb);
1116 swf_SetU16(tag, myshapeid2);
1117 r.xmin = (int)(xmin*20);
1118 r.ymin = (int)(ymin*20);
1119 r.xmax = (int)(xmax*20);
1120 r.ymax = (int)(ymax*20);
1121 swf_SetRect(tag,&r);
1122 swf_SetShapeStyles(tag,shape);
1123 swf_ShapeCountBits(shape,NULL,NULL);
1124 swf_SetShapeBits(tag,shape);
1125 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,0,fsid,0);
1126 swflastx = swflasty = 0;
1132 swf_ShapeSetEnd(tag);
1134 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
1135 swf_SetU16(tag,buttonid); //id
1136 swf_ButtonSetFlags(tag, 0); //menu=no
1137 swf_ButtonSetRecord(tag,0x01,myshapeid,depth,0,0);
1138 swf_ButtonSetRecord(tag,0x02,myshapeid2,depth,0,0);
1139 swf_ButtonSetRecord(tag,0x04,myshapeid2,depth,0,0);
1140 swf_ButtonSetRecord(tag,0x08,myshapeid,depth,0,0);
1142 swf_SetActions(tag,actions);
1145 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1146 swf_ObjectPlace(tag, buttonid, depth++,0,0,0);
1149 void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey,
1150 double x1,double y1,
1151 double x2,double y2,
1152 double x3,double y3,
1153 double x4,double y4)
1159 struct plotxy p1,p2,p3,p4;
1161 double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
1162 if(x2>xmax) xmax=x2;
1163 if(y2>ymax) ymax=y2;
1164 if(x2<xmin) xmin=x2;
1165 if(y2<ymin) ymin=y2;
1166 if(x3>xmax) xmax=x3;
1167 if(y3>ymax) ymax=y3;
1168 if(x3<xmin) xmin=x3;
1169 if(y3<ymin) ymin=y3;
1170 if(x4>xmax) xmax=x4;
1171 if(y4>ymax) ymax=y4;
1172 if(x4<xmin) xmin=x4;
1173 if(y4<ymin) ymin=y4;
1184 m.sx = (int)(65536*20*(x4-x1))/sizex;
1185 m.r1 = -(int)(65536*20*(y4-y1))/sizex;
1186 m.r0 = (int)(65536*20*(x1-x2))/sizey;
1187 m.sy = -(int)(65536*20*(y1-y2))/sizey;
1189 m.tx = (int)(x1*20);
1190 m.ty = (int)(y1*20);
1193 myshapeid = ++currentswfid;
1194 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
1195 swf_ShapeNew(&shape);
1196 //lsid = ShapeAddLineStyle(shape,obj->linewidth,&obj->strokergb);
1197 //fsid = ShapeAddSolidFillStyle(shape,&obj->fillrgb);
1198 fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,0);
1199 swf_SetU16(tag, myshapeid);
1200 r.xmin = (int)(xmin*20);
1201 r.ymin = (int)(ymin*20);
1202 r.xmax = (int)(xmax*20);
1203 r.ymax = (int)(ymax*20);
1204 swf_SetRect(tag,&r);
1205 swf_SetShapeStyles(tag,shape);
1206 swf_ShapeCountBits(shape,NULL,NULL);
1207 swf_SetShapeBits(tag,shape);
1208 swf_ShapeSetAll(tag,shape,/*x*/0,/*y*/0,lsid,fsid,0);
1209 swflastx = swflasty = 0;
1216 ShapeMoveTo (tag, shape, (int)(x1*20),(int)(y1*20));
1217 ShapeSetLine (tag, shape, (int)(x1*20);
1218 ShapeSetLine (tag, shape, x*20,0);
1219 ShapeSetLine (tag, shape, 0,-y*20);
1220 ShapeSetLine (tag, shape, -x*20,0);*/
1221 swf_ShapeSetEnd(tag);
1224 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
1225 swf_ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
1228 int swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey,
1229 double x1,double y1,
1230 double x2,double y2,
1231 double x3,double y3,
1232 double x4,double y4)
1239 int bitid = ++currentswfid;
1240 tag = swf_InsertTag(tag,ST_DEFINEBITSJPEG2);
1241 swf_SetU16(tag, bitid);
1242 swf_SetJPEGBits(tag, filename, jpegquality);
1244 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1248 int swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey,
1249 double x1,double y1,
1250 double x2,double y2,
1251 double x3,double y3,
1252 double x4,double y4)
1259 int bitid = ++currentswfid;
1260 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS);
1261 swf_SetU16(tag, bitid);
1262 swf_SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT);
1264 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1268 int swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey,
1269 double x1,double y1,
1270 double x2,double y2,
1271 double x3,double y3,
1272 double x4,double y4)
1279 int bitid = ++currentswfid;
1280 tag = swf_InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
1281 swf_SetU16(tag, bitid);
1282 swf_SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256);
1284 drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
1288 void swfoutput_drawimageagain(struct swfoutput*obj, int id, int sizex,int sizey,
1289 double x1,double y1,
1290 double x2,double y2,
1291 double x3,double y3,
1292 double x4,double y4)
1299 drawimage(obj, id, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);