fixed merge conflict
[swftools.git] / lib / filters / remove_font_transforms.c
index 91afb2c..4b671f7 100644 (file)
@@ -178,16 +178,8 @@ static void glyph_transform(gfxglyph_t*g, mymatrix_t*mm)
     m.ty = 0;
     if(m.m00>0)
        g->advance *= m.m00;
-    if(!mm->alpha) {
-       /* for OCR: remove the outlines of characters that are only
-          ever displayed with alpha=0 */
-       g->line = (gfxline_t*)rfx_calloc(sizeof(gfxline_t));
-       g->line->type = gfx_moveTo;
-       g->line->x = g->advance;
-    } else {
-       g->line = gfxline_clone(g->line);
-       gfxline_transform(g->line, &m);
-    }
+    g->line = gfxline_clone(g->line);
+    gfxline_transform(g->line, &m);
 }
 
 static gfxresult_t* pass1_finish(gfxfilter_t*f, gfxdevice_t*out)
@@ -212,7 +204,7 @@ static gfxresult_t* pass1_finish(gfxfilter_t*f, gfxdevice_t*out)
            if(fd->used[t]) {
                font->glyphs[count] = fd->orig->glyphs[t];
                glyph_transform(&font->glyphs[count], &fd->matrix);
-               fd->used[t] = count;
+               fd->used[t] = count + 1;
                count++;
            }
        }
@@ -235,11 +227,47 @@ static gfxresult_t* pass1_finish(gfxfilter_t*f, gfxdevice_t*out)
        font->descent = -total.ymin;
 
        for(t=0;t<count;t++) {
+           gfxglyph_t*g = &font->glyphs[t];
            gfxline_t*line = font->glyphs[t].line;
-           while(line) {
-               line->x += fd->dx;
-               line->sx += fd->dx;
-               line = line->next;
+
+           if(fd->matrix.alpha) {
+               while(line) {
+                   line->x += fd->dx;
+                   line->sx += fd->dx;
+                   line = line->next;
+               }
+           } else {
+               gfxline_free(g->line);
+               /* for OCR: remove the outlines of characters that are only
+                  ever displayed with alpha=0 */
+               g->line = (gfxline_t*)rfx_calloc(sizeof(gfxline_t));
+               g->line->type = gfx_moveTo;
+               g->line->x = g->advance;
+           }
+       }
+
+       if(fd->matrix.m00>0) {
+           /* subset kerning table */
+           count = 0;
+           for(t=0;t<fd->orig->kerning_size;t++) {
+               int char1 = fd->used[fd->orig->kerning[t].c1]-1;
+               int char2 = fd->used[fd->orig->kerning[t].c2]-1;
+               if(char1>=0 && char2>=0) {
+                   count++;
+               }
+           }
+           font->kerning = malloc(sizeof(font->kerning[0])*count);
+           font->kerning_size = count;
+           count = 0;
+           for(t=0;t<fd->orig->kerning_size;t++) {
+               int char1 = fd->used[fd->orig->kerning[t].c1]-1;
+               int char2 = fd->used[fd->orig->kerning[t].c2]-1;
+               if(char1>=0 && char2>=0) {
+                   font->kerning[count].c1 = char1;
+                   font->kerning[count].c2 = char2;
+                   font->kerning[count].advance = fd->orig->kerning[t].advance * fd->matrix.m00;
+                   count++;
+               }
            }
        }
        gfxfont_fix_unicode(font);
@@ -277,7 +305,20 @@ static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_
     if(!m.alpha) 
        color.a = 255;
 
-    out->drawchar(out, d->font, d->used[glyphnr], &color, &scalematrix);
+    out->drawchar(out, d->font, d->used[glyphnr]-1, &color, &scalematrix);
+}
+
+static gfxresult_t* pass2_finish(gfxfilter_t*f, gfxdevice_t*out)
+{
+    internal_t*i = (internal_t*)f->internal;
+    DICT_ITERATE_DATA(i->matrices, transformedfont_t*, fd) {
+       if(fd->used) {
+           free(fd->used);fd->used=0;
+       }
+       free(fd);
+    }
+    dict_destroy(i->matrices);i->matrices=0;
+    return out->finish(out);
 }
 
 void gfxtwopassfilter_remove_font_transforms_init(gfxtwopassfilter_t*f)
@@ -295,6 +336,7 @@ void gfxtwopassfilter_remove_font_transforms_init(gfxtwopassfilter_t*f)
     f->pass2.name = "remove font transforms pass 2";
     f->pass2.addfont = pass2_addfont;
     f->pass2.drawchar = pass2_drawchar;
+    f->pass2.finish = pass2_finish;
     f->pass2.internal = i;
 
     i->matrices = dict_new2(&mymatrix_type);