added PlaceObject parser.
[swftools.git] / src / swfbbox.c
index fcb11d0..95ff67a 100644 (file)
@@ -35,14 +35,17 @@ static int optimize = 0;
 static int swifty = 0;
 static int verbose = 0;
 static int showbbox = 1;
+static int showorigbbox = 0;
 static int expand = 1;
 
 static struct options_t options[] = {
 {"h", "help"},
+{"b", "bbox"},
+{"B", "newbbox"},
+{"e", "expand"},
 {"O", "optimize"},
 {"S", "swifty"},
 {"o", "output"},
-{"e", "expand"},
 {"v", "verbose"},
 {"V", "version"},
 {0,0}
@@ -54,20 +57,33 @@ int args_callback_option(char*name,char*val)
         printf("swfbbox - part of %s %s\n", PACKAGE, VERSION);
         exit(0);
     } 
+    else if(!strcmp(name, "b")) {
+       showorigbbox = 1;
+       if(showbbox == 1) showbbox = 0;
+       return 0;
+    } 
+    else if(!strcmp(name, "B")) {
+       showbbox = 2;
+       return 0;
+    } 
     else if(!strcmp(name, "O")) {
        optimize = 1;
-       showbbox = 0;
+       if(showbbox == 1) showbbox = 0;
        return 0;
     } 
     else if(!strcmp(name, "S")) {
        swifty = 1;
-       showbbox = 0;
+       if(showbbox == 1) showbbox = 0;
        return 0;
     } 
     else if(!strcmp(name, "v")) {
        verbose ++;
        return 0;
     } 
+    else if(!strcmp(name, "q")) {
+       verbose --;
+       return 0;
+    } 
     else if(!strcmp(name, "e")) {
        expand = 1;
        return 0;
@@ -90,13 +106,15 @@ int args_callback_longoption(char*name,char*val)
 void args_callback_usage(char *name)
 {
     printf("\n");
-    printf("Usage: %s [-OSe] file.swf\n", name);
+    printf("Usage: %s [-OS] file.swf\n", name);
     printf("\n");
     printf("-h , --help                    Print help and exit\n");
+    printf("-b , --bbox                    Show movie bounding box (default)\n");
+    printf("-B , --newbbox                 Show recalculated (optimized/expanded) bounding box\n");
+    printf("-e , --expand                  Write out a new file using the recalculated bounding box\n");
+    printf("-O , --optimize                Recalculate bounding boxes\n");
     printf("-S , --swifty                  Print out transformed bounding boxes\n");
-    printf("-O , --optimize                Recalculate bounding boxes and write new file\n");
-    printf("-e , --expand                  Recalculate main bounding box and write new file\n");
-    printf("-o , --output <filename>       Set output filename to <filename> (for -O/-e)\n");
+    printf("-o , --output <filename>       Set output filename to <filename> (for -O)\n");
     printf("-v , --verbose                 Be more verbose\n");
     printf("-V , --version                 Print program version and exit\n");
     printf("\n");
@@ -171,10 +189,10 @@ MATRIX getmatrix(TAG*tag)
 static int fontnum = -1;
 static SWFFONT**fonts;
 static SWF*c_swf;
-static void fontcallback1(U16 id,U8 * name)
+static void fontcallback1(void*self, U16 id,U8 * name)
 { fontnum++;
 }
-static void fontcallback2(U16 id,U8 * name)
+static void fontcallback2(void*self, U16 id,U8 * name)
 { 
     fonts[fontnum] = 0;
     swf_FontExtract(c_swf,id,&fonts[fontnum]);
@@ -224,8 +242,8 @@ static void textcallback(void*self, int*chars, int*xpos, int nr, int fontid, int
        SRECT newglyphbbox, glyphbbox = font->layout->bounds[chars[t]];
        MATRIX m = bounds->m;
        
-       if(ch < font->numchars && font->glyph2ascii) {
-           ch = font->glyph2ascii[ch];
+       if(chars[t] < font->numchars && font->glyph2ascii) {
+           ch = font->glyph2ascii[chars[t]];
        }
 
        m.sx = (m.sx * fontsize) / 1024;
@@ -278,11 +296,11 @@ static void swf_OptimizeBoundingBoxes(SWF*swf)
                if(verbose) printf("Extracting fonts...\n");
                c_swf = swf;
                fontnum = 0;
-               swf_FontEnumerate(swf,&fontcallback1);
+               swf_FontEnumerate(swf,&fontcallback1,0);
                fonts = (SWFFONT**)malloc(fontnum*sizeof(SWFFONT*));
                memset(fonts, 0, fontnum*sizeof(SWFFONT*));
                fontnum = 0;
-               swf_FontEnumerate(swf,&fontcallback2);
+               swf_FontEnumerate(swf,&fontcallback2,0);
            }
 
            memset(&bounds, 0, sizeof(bounds));
@@ -406,6 +424,7 @@ int main (int argc,char ** argv)
     TAG*tag;
     SWF swf;
     int fi;
+    SRECT oldMovieSize;
     SRECT newMovieSize;
     memset(bboxes, 0, sizeof(bboxes));
     memset(depth2name, 0, sizeof(depth2name));
@@ -467,6 +486,7 @@ int main (int argc,char ** argv)
        showSwiftyOutput(&swf);
     }
 
+    oldMovieSize = swf.movieSize;
     newMovieSize = getSWFBBox(&swf);
 
     if(optimize || expand) {
@@ -484,13 +504,25 @@ int main (int argc,char ** argv)
     }
     
     if(showbbox) {
-       printf("Real Movie Size: %.2fx%.2f (:%.2f:%.2f)\n", 
+       if(verbose>=0)
+           printf("Real Movie Size: ");
+       printf("%.2f x %.2f :%.2f :%.2f\n", 
                (newMovieSize.xmax-newMovieSize.xmin)/20.0,
                (newMovieSize.ymax-newMovieSize.ymin)/20.0,
                (newMovieSize.xmin)/20.0,
                (newMovieSize.ymin)/20.0
                );
     }
+    if(showorigbbox) {
+       if(verbose>=0)
+           printf("Original Movie Size: ");
+       printf("%.2f x %.2f :%.2f :%.2f\n", 
+               (oldMovieSize.xmax-oldMovieSize.xmin)/20.0,
+               (oldMovieSize.ymax-oldMovieSize.ymin)/20.0,
+               (oldMovieSize.xmin)/20.0,
+               (oldMovieSize.ymin)/20.0
+               );
+    }
 
     swf_FreeTags(&swf);
     return 0;