font transforms: keep unit transforms the same
[swftools.git] / lib / filters / remove_font_transforms.c
index 4a23cfd..c92816c 100644 (file)
@@ -99,7 +99,7 @@ void matrix_convert(gfxmatrix_t*in, const char*id, mymatrix_t*out, gfxmatrix_t*s
 {
     double l1 = sqrt(in->m00 * in->m00 + in->m01 * in->m01);
     double l2 = sqrt(in->m10 * in->m10 + in->m11 * in->m11);
-    double l = l1+l2;
+    double l = (l1+l2)/2.0;
     if(l < 1e-10) {
        memset(out, 0, sizeof(*out));
        return;
@@ -129,7 +129,7 @@ typedef struct _transformedfont {
     gfxfont_t*font;
     mymatrix_t matrix;
     int*used;
-    double dx,dy;
+    double dx;
 } transformedfont_t;
 
 static transformedfont_t* transformedfont_new(gfxfont_t*orig, mymatrix_t*m)
@@ -210,15 +210,15 @@ static gfxresult_t* pass1_finish(gfxfilter_t*f, gfxdevice_t*out)
            average_xmax /= count;
 
        fd->dx = -total.xmin;
-       fd->dy = 0;
+
+       font->ascent = total.ymax;
+       font->descent = total.ymin;
 
        for(t=0;t<count;t++) {
            gfxline_t*line = font->glyphs[t].line;
            while(line) {
                line->x += fd->dx;
-               line->y += fd->dy;
                line->sx += fd->dx;
-               line->sy += fd->dy;
                line = line->next;
            }
        }
@@ -248,8 +248,7 @@ static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_
     gfxmatrix_t scalematrix;
     matrix_convert(matrix, font->id, &m, &scalematrix);
     transformedfont_t*d = dict_lookup(i->matrices, &m);
-    scalematrix.tx -= d->dx;
-    scalematrix.ty -= d->dy;
+    scalematrix.tx -= d->dx*scalematrix.m00;
     out->drawchar(out, d->font, d->used[glyphnr], color, &scalematrix);
 }