added chapter seperation.
[swftools.git] / lib / modules / swfdump.c
1 /* swfdump.c
2
3    Dump / debug functions
4    
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23
24 void swf_DumpHeader(FILE * f,SWF * swf)
25 { if (!f) f = stderr;
26   fprintf(f,"File size\t%u\n",swf->fileSize);
27   fprintf(f,"Movie width\t%u\n",(swf->movieSize.xmax - swf->movieSize.xmin)/20);
28   fprintf(f,"Movie height\t%u\n",(swf->movieSize.ymax - swf->movieSize.ymin)/20);
29   fprintf(f,"Frame rate\t%u.%u\n",swf->frameRate>>8,swf->frameRate&0xff);
30   fprintf(f,"Frame count\t%u\n",swf->frameCount);
31 }
32
33 void swf_DumpMatrix(FILE * f,MATRIX * m)
34 { if (!f) f = stderr;
35   fprintf(f,"[%08x][%08x]\n",m->sx,m->r1);
36   fprintf(f,"[%08x][%08x]\n",m->r0,m->sy);
37   fprintf(f," %08x, %08x\n",m->tx,m->ty);
38 }
39
40 void swf_DumpTag(FILE * f,TAG * t)
41 { int i;
42   if (!f) f = stderr;
43   for (i=0;i<t->len;i++)
44   { if (!(i&15)) fprintf(f,"\n");
45     fprintf(f,"%02x ",t->data[i]);
46   }
47   fprintf(f,"\n");
48 }
49
50 void swf_DumpSWF(FILE * f, SWF*swf)
51 {
52     TAG* tag = swf->firstTag;
53     fprintf(f, "vvvvvvvvvvvvvvvvvvvvv\n");
54     while(tag) {
55         printf("%8d %s\n", tag->len, swf_TagGetName(tag));
56         tag = tag->next;
57     }
58     fprintf(f, "^^^^^^^^^^^^^^^^^^^^^\n");
59 }
60
61 void swf_DumpFont(SWFFONT * font)
62 {
63     printf("ID: %d\n", font->id);
64     printf("Version: %d\n", font->version);
65     printf("name: %s\n", font->name);
66     printf("characters: %d\n", font->numchars);
67     printf("biggest mapped ascii value: %d\n", font->maxascii);
68     printf("layout: %s\n", font->layout?"yes":"no");
69     if(font->layout)
70     {
71         printf(" ascent:%d\n", font->layout->ascent);
72         printf(" descent:%d\n", font->layout->descent);
73         printf(" leading:%d\n", font->layout->leading);
74         printf(" bounds: (not shown)\n");
75         printf(" kerning records:%d\n", font->layout->kerningcount);
76         printf(" kerning records: (not shown)\n");
77     }
78     printf("style: %d\n", font->style);
79     printf("encoding: %d\n", font->encoding);
80     printf("language: %d\n", font->language);
81 }
82
83 void swf_DumpShape(SHAPE2*shape2)
84 {
85     SHAPELINE*l = shape2->lines;
86     while(l) {
87         if(l->type == moveTo) {
88             //printf("fill %d/%d line %d\n", l->fillstyle0, l->fillstyle1, l->linestyle);
89             printf("moveTo %.2f,%.2f\n", l->x/20.0, l->y/20.0);
90         }
91         if(l->type == lineTo) {
92             //printf("fill %d/%d line %d\n", l->fillstyle0,  l->fillstyle1, l->linestyle);
93             printf("lineTo %.2f,%.2f\n", l->x/20.0, l->y/20.0);
94         }
95         if(l->type == splineTo) {
96             //printf("fill %d/%d line %d\n", l->fillstyle0, l->fillstyle1, l->linestyle);
97             printf("splineTo %.2f,%.2f %.2f,%.2f\n", l->sx/20.0, l->sy/20.0, l->x/20.0, l->y/20.0);
98         }
99         l = l->next;
100     }
101 }
102
103 char* swf_TagGetName(TAG*tag)
104 {
105     switch(tag->id)
106     {
107         case ST_END:
108             return "END";
109         case ST_SHOWFRAME:
110             return "SHOWFRAME";
111         case ST_DEFINESHAPE:
112             return "DEFINESHAPE";
113         case ST_FREECHARACTER:
114             return "FREECHARACTER";
115         case ST_PLACEOBJECT:
116             return "PLACEOBJECT";
117         case ST_REMOVEOBJECT:
118             return "REMOVEOBJECT";
119         case ST_DEFINEBITS:
120             return "DEFINEBITS";
121         case ST_DEFINEBUTTON:
122             return "DEFINEBUTTON";
123         case ST_JPEGTABLES:
124             return "JPEGTABLES";
125         case ST_SETBACKGROUNDCOLOR:
126             return "SETBACKGROUNDCOLOR";
127         case ST_DEFINEFONT:
128             return "DEFINEFONT";
129         case ST_DEFINETEXT:
130             return "DEFINETEXT";
131         case ST_DEFINEEDITTEXT:
132             return "DEFINEEDITTEXT";
133         case ST_DOACTION:
134             return "DOACTION";
135         case ST_DEFINEFONTINFO:
136             return "DEFINEFONTINFO";
137         case ST_DEFINESOUND:
138             return "DEFINESOUND";
139         case ST_STARTSOUND:
140             return "STARTSOUND";
141         case ST_DEFINEBUTTONSOUND:
142             return "DEFINEBUTTONSOUND";
143         case ST_SOUNDSTREAMHEAD:
144             return "SOUNDSTREAMHEAD";
145         case ST_SOUNDSTREAMBLOCK:
146             return "SOUNDSTREAMBLOCK";
147         case ST_DEFINEBITSLOSSLESS:
148             return "DEFINEBITSLOSSLESS";
149         case ST_DEFINEBITSJPEG2:
150             return "DEFINEBITSJPEG2";
151         case ST_DEFINESHAPE2:
152             return "DEFINESHAPE2";
153         case ST_DEFINEBUTTONCXFORM:
154             return "DEFINEBUTTONCXFORM";
155         case ST_PROTECT:
156             return "PROTECT";
157         case ST_PLACEOBJECT2:
158             return "PLACEOBJECT2";
159         case ST_REMOVEOBJECT2:
160             return "REMOVEOBJECT2";
161         case ST_DEFINESHAPE3:
162             return "DEFINESHAPE3";
163         case ST_DEFINETEXT2:
164             return "DEFINETEXT2";
165         case ST_DEFINEBUTTON2:
166             return "DEFINEBUTTON2";
167         case ST_DEFINEBITSJPEG3:
168             return "DEFINEBITSJPEG3";
169         case ST_DEFINEBITSLOSSLESS2:
170             return "DEFINEBITSLOSSLESS2";
171         case ST_DEFINESPRITE:
172             return "DEFINESPRITE";
173         case ST_NAMECHARACTER:
174             return "NAMECHARACTER";
175         case ST_SERIALNUMBER:
176             return "SERIALNUMBER";
177         case ST_GENERATORTEXT:
178             return "GENERATORTEXT";
179         case ST_FRAMELABEL:
180             return "FRAMELABEL";
181         case ST_SOUNDSTREAMHEAD2:
182             return "SOUNDSTREAMHEAD2";
183         case ST_DEFINEMORPHSHAPE:
184             return "DEFINEMORPHSHAPE";
185         case ST_DEFINEFONT2:
186             return "DEFINEFONT2";
187         case ST_TEMPLATECOMMAND:
188             return "TEMPLATECOMMAND";
189         case ST_GENERATOR3:
190             return "GENERATOR3";
191         case ST_EXTERNALFONT:
192             return "EXTERNALFONT";
193         case ST_EXPORTASSETS:
194             return "EXPORTASSETS";
195         case ST_IMPORTASSETS:
196             return "IMPORTASSETS";
197         case ST_ENABLEDEBUGGER:
198             return "ENABLEDEBUGGER";
199         case ST_DOINITACTION:
200             return "DOINITACTION";
201         case ST_DEFINEMOVIE:
202             return "DEFINEMOVIE";
203         case ST_DEFINEVIDEOSTREAM:
204             return "DEFINEVIDEOSTREAM";
205         case ST_VIDEOFRAME:
206             return "VIDEOFRAME";
207         case ST_DEFINEFONTINFO2:
208             return "DEFINEFONTINFO2";
209         case ST_FREEALL:
210             return "FREEALL";
211         case ST_MX4:
212             return "MX4";
213         case ST_SCRIPTLIMITS:
214             return "SCRIPTLIMITS";
215         case ST_SETTABINDEX:
216             return "SETTABINDEX";
217         
218         case ST_REFLEX:
219             return "REFLEX";
220         case ST_GLYPHNAMES:
221             return "GLYPHNAMES";
222     }
223     return 0;
224 }