pdf2swf: fixed polygon rendering of closed strokes
authorMatthias Kramm <kramm@quiss.org>
Sun, 12 Apr 2009 22:17:20 +0000 (00:17 +0200)
committerMatthias Kramm <kramm@quiss.org>
Sun, 12 Apr 2009 22:17:20 +0000 (00:17 +0200)
lib/gfxpoly.c
lib/pdf/GFXOutputDev.cc

index 65a65b7..a408618 100644 (file)
@@ -384,11 +384,13 @@ static ArtVpath* gfxline_to_ArtVpath(gfxline_t*line, char fill)
 
     pos = 0;
     l2 = line;
 
     pos = 0;
     l2 = line;
+    int lastmove=-1;
     while(l2) {
        if(l2->type == gfx_moveTo) {
            vec[pos].code = ART_MOVETO_OPEN;
            vec[pos].x = l2->x;
            vec[pos].y = l2->y;
     while(l2) {
        if(l2->type == gfx_moveTo) {
            vec[pos].code = ART_MOVETO_OPEN;
            vec[pos].x = l2->x;
            vec[pos].y = l2->y;
+            lastmove=pos;
            pos++; 
            assert(pos<=len);
        } else if(l2->type == gfx_lineTo) {
            pos++; 
            assert(pos<=len);
        } else if(l2->type == gfx_lineTo) {
@@ -413,6 +415,16 @@ static ArtVpath* gfxline_to_ArtVpath(gfxline_t*line, char fill)
        }
        x = l2->x;
        y = l2->y;
        }
        x = l2->x;
        y = l2->y;
+       
+        /* let closed line segments start w/ MOVETO instead of MOVETO_OPEN */
+        if(lastmove>=0 && l2->type!=gfx_moveTo && (!l2->next || l2->next->type == gfx_moveTo)) {
+            if(vec[lastmove].x == l2->x &&
+               vec[lastmove].y == l2->y) {
+                assert(vec[lastmove].code == ART_MOVETO_OPEN);
+                vec[lastmove].code = ART_MOVETO;
+            }
+        }
+
        l2 = l2->next;
     }
     vec[pos++].code = ART_END;
        l2 = l2->next;
     }
     vec[pos++].code = ART_END;
index 7bd0860..b0d1169 100644 (file)
@@ -791,6 +791,31 @@ void dump_outline(gfxline_t*line)
     }
 }
 
     }
 }
 
+void gfxPath_dump(GfxPath*path)
+{
+    int num = path->getNumSubpaths();
+    int t;
+    int cpos=0;
+    for(t = 0; t < num; t++) {
+       GfxSubpath *subpath = path->getSubpath(t);
+       int subnum = subpath->getNumPoints();
+        int s; 
+        for(s=0;s<subnum;s++) {
+          double x=subpath->getX(s);
+           double y=subpath->getY(s);
+          if(s==0 && !subpath->getCurve(s)) {
+                printf("M %f %f\n", x, y);
+           } else if(s==0 && subpath->getCurve(s)) {
+                printf("E %f %f\n", x, y);
+          } else if(subpath->getCurve(s)) {
+                printf("C %f %f\n", x, y);
+          } else {
+                printf("T %f %f\n", x, y);
+          }
+       }
+    }
+}
+
 gfxline_t* GFXOutputDev::gfxPath_to_gfxline(GfxState*state, GfxPath*path, int closed, int user_movex, int user_movey)
 {
     int num = path->getNumSubpaths();
 gfxline_t* GFXOutputDev::gfxPath_to_gfxline(GfxState*state, GfxPath*path, int closed, int user_movex, int user_movey)
 {
     int num = path->getNumSubpaths();