]> granicus.if.org Git - graphviz/commitdiff
improved egg and distorted ellipse shapes by passing FP to renderers
authorellson <devnull@localhost>
Thu, 16 Mar 2006 16:52:38 +0000 (16:52 +0000)
committerellson <devnull@localhost>
Thu, 16 Mar 2006 16:52:38 +0000 (16:52 +0000)
lib/common/shapes.c
lib/gvc/gvcproc.h
lib/gvc/gvrender.c

index 4224bf6cc7f4750092032a09baaf376163ee0712..a510ce467d99974d8704acb35cb1f5b6488bb588 100644 (file)
@@ -1197,6 +1197,7 @@ static void poly_gencode(GVJ_t * job, node_t * n)
     int i, j, peripheries, sides, style;
     pointf P, *vertices;
     static point *A;
+    static pointf *AF;
     static int A_size;
     bool filled;
     char *color;
@@ -1208,6 +1209,7 @@ static void poly_gencode(GVJ_t * job, node_t * n)
     if (A_size < sides) {
        A_size = sides + 5;
        A = ALLOC(A_size, A, point);
+       AF = ALLOC(A_size, AF, pointf);
     }
 
     ND_label(n)->p = ND_coord_i(n);
@@ -1297,6 +1299,12 @@ static void poly_gencode(GVJ_t * job, node_t * n)
     for (j = 0; j < peripheries; j++) {
        for (i = 0; i < sides; i++) {
            P = vertices[i + j * sides];
+           AF[i].x = P.x * xsize / 16.;
+           AF[i].y = P.y * ysize / 16.;
+           if (sides > 2) {
+               AF[i].x += ND_coord_i(n).x;
+               AF[i].y += ND_coord_i(n).y;
+           }
 /* simple rounding produces random results around .5 
  * this trick should clip off the random part. 
  * (note xsize/ysize prescaled by 16.0 above) */
@@ -1308,14 +1316,17 @@ static void poly_gencode(GVJ_t * job, node_t * n)
            }
        }
        if (sides <= 2) {
-           gvrender_ellipse(job, ND_coord_i(n), A[0].x, A[0].y, filled);
+           pointf PF;
+
+           P2PF(ND_coord_i(n), PF);
+           gvrender_ellipsef(job, PF, AF[0].x, AF[0].y, filled);
            if (style & DIAGONALS) {
                Mcircle_hack(job, n);
            }
        } else if (style & (ROUNDED | DIAGONALS)) {
            node_round_corners(job, n, A, sides, style);
        } else {
-           gvrender_polygon(job, A, sides, filled);
+           gvrender_polygonf(job, AF, sides, filled);
        }
        /* fill innermost periphery only */
        filled = FALSE;
index 8f44bbd49713e57c035193bb0d7216d97145a973..2c07f2c92e9e0a458d8160148c9f9a7b16a5adac 100644 (file)
@@ -107,10 +107,10 @@ extern "C" {
     extern void gvrender_set_pencolor(GVJ_t * job, char *name);
     extern void gvrender_set_fillcolor(GVJ_t * job, char *name);
     extern void gvrender_set_style(GVJ_t * job, char **s);
-    extern void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry,
-                                int filled);
-    extern void gvrender_polygon(GVJ_t * job, point * A, int n,
-                                int filled);
+    extern void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry, int filled);
+    extern void gvrender_ellipsef(GVJ_t * job, pointf p, double rx, double ry, int filled);
+    extern void gvrender_polygon(GVJ_t * job, point * A, int n, int filled);
+    extern void gvrender_polygonf(GVJ_t * job, pointf * AF, int n, int filled);
     extern void gvrender_beziercurve(GVJ_t * job, pointf * AF, int n,
                                     int arrow_at_start, int arrow_at_end, int);
     extern void gvrender_polyline(GVJ_t * job, point * A, int n);
index 4bf7a7155d9ea26920efa479eaa59829a85de296..91daac29bcc6862e49778e47bb664553a33b0725 100644 (file)
@@ -778,6 +778,39 @@ void gvrender_set_style(GVJ_t * job, char **s)
 #endif
 }
 
+void gvrender_ellipsef(GVJ_t * job, pointf pf, double rx, double ry, int filled)
+{
+    gvrender_engine_t *gvre = job->render.engine;
+
+    if (gvre && gvre->ellipse) {
+       if (job->style->pen != PEN_NONE) {
+           pointf af[2];
+
+           /* center */
+           af[0] = pf;
+           /* corner */
+           af[1].x = pf.x + rx;
+           af[1].y = pf.y + ry;
+           /* scale */
+           af[0] = gvrender_ptf(job, af[0]);
+           af[1] = gvrender_ptf(job, af[1]);
+           gvre->ellipse(job, af, filled);
+       }
+    }
+#ifndef DISABLE_CODEGENS
+    else {
+       codegen_t *cg = job->codegen;
+
+       if (cg && cg->ellipse) {
+           point p;
+
+           PF2P(pf, p);
+           cg->ellipse(p, ROUND(rx), ROUND(ry), filled);
+       }
+    }
+#endif
+}
+
 void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry, int filled)
 {
     gvrender_engine_t *gvre = job->render.engine;
@@ -810,6 +843,38 @@ void gvrender_ellipse(GVJ_t * job, point p, int rx, int ry, int filled)
 #endif
 }
 
+void gvrender_polygonf(GVJ_t * job, pointf * af, int n, int filled)
+{
+    int i;
+    gvrender_engine_t *gvre = job->render.engine;
+
+    if (gvre && gvre->polygon) {
+       if (job->style->pen != PEN_NONE) {
+           if (sizeAF < n) {
+               sizeAF = n+10;
+               AF = grealloc(AF, sizeAF * sizeof(pointf));
+           }
+           for (i = 0; i < n; i++)
+               AF[i] = gvrender_ptf(job, af[i]);
+           gvre->polygon(job, AF, n, filled);
+       }
+    }
+#ifndef DISABLE_CODEGENS
+    else {
+       codegen_t *cg = job->codegen;
+
+       if (sizeA < n) {
+           sizeA = n+10;
+           A = grealloc(A, sizeA * sizeof(point));
+       }
+       for (i = 0; i < n; i++)
+           PF2P(af[i], A[i]);
+       if (cg && cg->polygon)
+           cg->polygon(A, n, filled);
+    }
+#endif
+}
+
 void gvrender_polygon(GVJ_t * job, point * A, int n, int filled)
 {
     gvrender_engine_t *gvre = job->render.engine;