fixed text selection with --flatten
[swftools.git] / lib / devices / polyops.c
index e6dd671..70fd99b 100644 (file)
@@ -305,6 +305,9 @@ void polyops_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcol
     if(i->clip && i->clip->poly) {
        gfxbbox_t bbox = gfxline_getbbox(glyph);
        gfxpoly_t*dummybox = gfxpoly_createbox(bbox.xmin,bbox.ymin,bbox.xmax,bbox.ymax, DEFAULT_GRID);
+       gfxline_t*dummybox2 = gfxline_from_gfxpoly(dummybox);
+       bbox = gfxline_getbbox(dummybox2);
+       gfxline_free(dummybox2);
 
         char ok=0;
        gfxline_t*gfxline = handle_poly(dev, dummybox, &ok);
@@ -312,9 +315,8 @@ void polyops_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcol
            gfxbbox_t bbox2 = gfxline_getbbox(gfxline);
            double w = bbox2.xmax - bbox2.xmin;
            double h = bbox2.ymax - bbox2.ymin;
-           if(w < 0.001 || h < 0.001) /* character was clipped completely */ {
-           } else if(fabs((bbox.xmax - bbox.xmin) - w) > 0.05 ||
-                     fabs((bbox.ymax - bbox.ymin) - h) > 0.05) {
+           if(fabs((bbox.xmax - bbox.xmin) - w) > DEFAULT_GRID*2 ||
+              fabs((bbox.ymax - bbox.ymin) - h) > DEFAULT_GRID*2) {
                /* notable change in character size: character was clipped 
                   TODO: how to deal with diagonal cuts?
                 */
@@ -325,6 +327,7 @@ void polyops_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcol
        } else {
            if(i->out) i->out->drawchar(i->out, font, glyphnr, color, matrix);
        }
+       gfxline_free(gfxline);
     } else {
        if(i->out) i->out->drawchar(i->out, font, glyphnr, color, matrix);
     }
@@ -351,7 +354,6 @@ gfxresult_t* polyops_finish(struct _gfxdevice*dev)
     dbg("polyops_finish");
     internal_t*i = (internal_t*)dev->internal;
 
-
     if(i->polyunion) {
        gfxpoly_destroy(i->polyunion);i->polyunion=0;
     } else {
@@ -359,8 +361,10 @@ gfxresult_t* polyops_finish(struct _gfxdevice*dev)
             msg("<notice> --flatten success rate: %.1f%% (%d failed polygons)", i->good_polygons*100.0 / (i->good_polygons + i->bad_polygons), i->bad_polygons);
         }
     }
-    if(i->out) {
-       return i->out->finish(i->out);
+    gfxdevice_t*out = i->out;
+    free(i);memset(dev, 0, sizeof(gfxdevice_t));
+    if(out) {
+       return out->finish(out);
     } else {
        return 0;
     }