fixed a bug in the text bounding box calculation.
[swftools.git] / src / swfbbox.c
index bb0322e..b3b8a77 100644 (file)
@@ -34,8 +34,8 @@ static char * outfilename = "output.swf";
 static int optimize = 0;
 static int swifty = 0;
 static int verbose = 0;
-static int showbbox = 1;
-static int showorigbbox = 0;
+static int showbbox = 0;
+static int showorigbbox = 1;
 static int expand = 1;
 
 static struct options_t options[] = {
@@ -189,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]);
@@ -241,18 +241,22 @@ static void textcallback(void*self, int*chars, int*xpos, int nr, int fontid, int
        int ch;
        SRECT newglyphbbox, glyphbbox = font->layout->bounds[chars[t]];
        MATRIX m = bounds->m;
-       
+       SPOINT p;
+
        if(chars[t] < font->numchars && font->glyph2ascii) {
            ch = font->glyph2ascii[chars[t]];
        }
 
+       p.x = x; p.y = y;
+       p = swf_TurnPoint(p, &m);
+
        m.sx = (m.sx * fontsize) / 1024;
        m.sy = (m.sy * fontsize) / 1024;
        m.r0 = (m.r0 * fontsize) / 1024;
        m.r1 = (m.r1 * fontsize) / 1024;
 
-       m.tx += x;
-       m.ty += y;
+       m.tx += p.x;
+       m.ty += p.y;
        newglyphbbox = swf_TurnRect(glyphbbox, &m);
 
        if(ch<32) ch='?';
@@ -296,11 +300,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));