From 05cad6435009955aabcd53a4071db69cc7348b46 Mon Sep 17 00:00:00 2001 From: erg Date: Mon, 25 Apr 2005 23:04:56 +0000 Subject: [PATCH] Add support for filled, rounded nodes. --- lib/common/diagen.c | 2 +- lib/common/emit.c | 6 +++--- lib/common/figgen.c | 2 +- lib/common/gdgen.c | 22 ++++++++++++++++++++-- lib/common/hpglgen.c | 2 +- lib/common/mifgen.c | 2 +- lib/common/mpgen.c | 2 +- lib/common/picgen.c | 2 +- lib/common/psgen.c | 14 +++++++++++++- lib/common/shapes.c | 21 ++++++++++++++++++++- lib/common/svggen.c | 2 +- lib/common/types.h | 2 +- lib/common/vrmlgen.c | 2 +- lib/common/vtxgen.c | 2 +- lib/common/xdgen.c | 7 +++++-- lib/gvc/gvc.h | 2 +- lib/gvc/gvplugin_render.h | 2 +- lib/gvc/gvrender.c | 6 +++--- 18 files changed, 76 insertions(+), 24 deletions(-) diff --git a/lib/common/diagen.c b/lib/common/diagen.c index 5154bf83f..3a2e1a756 100644 --- a/lib/common/diagen.c +++ b/lib/common/diagen.c @@ -698,7 +698,7 @@ int box_connection(node_t * n, pointf p) static void -dia_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +dia_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { int i, conn_h, conn_t; pointf p, firstp = { 0, 0 }, llp = { diff --git a/lib/common/emit.c b/lib/common/emit.c index 6caff05f2..f7d72a0e6 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -830,7 +830,7 @@ void emit_edge_graphics(GVC_t * gvc, edge_t * e) tmplist[j].y += offlist[j].y; } gvrender_beziercurve(gvc, tmplist, tmpspl.list[i].size, - FALSE, FALSE); + FALSE, FALSE, FALSE); } } xdemitState = EMIT_TDRAW; @@ -863,10 +863,10 @@ void emit_edge_graphics(GVC_t * gvc, edge_t * e) P2PF(bz.list[j], bzf.list[j]); if (gvrender_features(gvc) & GVRENDER_DOES_ARROWS) { gvrender_beziercurve(gvc, bzf.list, bz.size, bz.sflag, - bz.eflag); + bz.eflag, FALSE); } else { gvrender_beziercurve(gvc, bzf.list, bz.size, FALSE, - FALSE); + FALSE, FALSE); xdemitState = EMIT_TDRAW; if (bz.sflag) arrow_gen(gvc, bz.sp, bz.list[0], scale, bz.sflag); diff --git a/lib/common/figgen.c b/lib/common/figgen.c index 114030e97..8d0b1a2dc 100644 --- a/lib/common/figgen.c +++ b/lib/common/figgen.c @@ -416,7 +416,7 @@ static void fig_textline(point p, textline_t * line) } static void fig_bezier(point * A, int n, int arrow_at_start, - int arrow_at_end) + int arrow_at_end, int filled) { int object_code = 3; /* always 3 for spline */ int sub_type = 4; /* always 4 for opened X-spline */ diff --git a/lib/common/gdgen.c b/lib/common/gdgen.c index 9708d0819..8dde016bd 100644 --- a/lib/common/gdgen.c +++ b/lib/common/gdgen.c @@ -661,13 +661,14 @@ static void gd_textline(point p, textline_t * line) } static void -gd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +gd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { - pointf p0, p1, V[4]; + pointf p, p0, p1, V[4]; int i, j, step; int style[20]; int pen, width; gdImagePtr brush = NULL; + gdPoint F[4]; if (!im) return; @@ -708,6 +709,16 @@ gd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) width = cstk[SP].penwidth; gdImageSetThickness(im, width); #endif + p.x = A[0].x; + p.y = A[0].y; + p = gdpt(p); + F[0].x = ROUND(p.x); + F[0].y = ROUND(p.y); + p.x = A[n-1].x; + p.y = A[n-1].y; + p = gdpt(p); + F[3].x = ROUND(p.x); + F[3].y = ROUND(p.y); V[3].x = A[0].x; V[3].y = A[0].y; for (i = 0; i + 3 < n; i += 3) { @@ -723,6 +734,13 @@ gd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) NULL)); gdImageLine(im, ROUND(p0.x), ROUND(p0.y), ROUND(p1.x), ROUND(p1.y), pen); + if (filled) { + F[1].x = ROUND(p0.x); + F[1].y = ROUND(p0.y); + F[2].x = ROUND(p1.x); + F[2].y = ROUND(p1.y); + gdImageFilledPolygon(im, F, 4, cstk[SP].fillcolor); + } p0 = p1; } } diff --git a/lib/common/hpglgen.c b/lib/common/hpglgen.c index d29912216..478baadc8 100644 --- a/lib/common/hpglgen.c +++ b/lib/common/hpglgen.c @@ -708,7 +708,7 @@ static void Bzier(double x0, double y0, double x1, double y1, double x2, } static void hpgl_bezier(point * A, int n, int arrow_at_start, - int arrow_at_end) + int arrow_at_end, int filled) { char buffer[32]; int j; diff --git a/lib/common/mifgen.c b/lib/common/mifgen.c index d40e71a09..d76ffc298 100644 --- a/lib/common/mifgen.c +++ b/lib/common/mifgen.c @@ -510,7 +510,7 @@ static void mif_textline(point p, textline_t * line) } static void mif_bezier(point * A, int n, int arrow_at_start, - int arrow_at_end) + int arrow_at_end, int filled) { fprintf(Output_file, " \n"); diff --git a/lib/common/mpgen.c b/lib/common/mpgen.c index 003596dfd..e68e2dba8 100644 --- a/lib/common/mpgen.c +++ b/lib/common/mpgen.c @@ -196,7 +196,7 @@ static void mp_textline(point p, textline_t * line) } static void -mp_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +mp_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { int j; if (arrow_at_start || arrow_at_end) diff --git a/lib/common/picgen.c b/lib/common/picgen.c index 816c42002..a00f74a44 100644 --- a/lib/common/picgen.c +++ b/lib/common/picgen.c @@ -564,7 +564,7 @@ static void pic_user_shape(char *name, point * A, int sides, int filled) } static void pic_bezier(point * A, int n, int arrow_at_start, - int arrow_at_end) + int arrow_at_end, int filled) { pointf V[4], p; int i, j, m, step; diff --git a/lib/common/psgen.c b/lib/common/psgen.c index 5a64c3dd8..cd2c94cd9 100644 --- a/lib/common/psgen.c +++ b/lib/common/psgen.c @@ -378,11 +378,23 @@ static void ps_textline(point p, textline_t * line) } static void -ps_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +ps_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { int j; if (S[SP].invis) return; + if (filled && *S[SP].fillcolor) { + ps_set_color(S[SP].fillcolor); + fprintf(Output_file, Newpath_Moveto, A[0].x, A[0].y); + for (j = 1; j < n; j += 3) + fprintf(Output_file, "%d %d %d %d %d %d curveto\n", + A[j].x, A[j].y, A[j + 1].x, A[j + 1].y, A[j + 2].x, + A[j + 2].y); + fprintf(Output_file, "closepath\n"); + fprintf(Output_file, Fill); + if (*S[SP].pencolor) + ps_set_color(S[SP].pencolor); + } if (*S[SP].pencolor == '\0') return; if (arrow_at_start || arrow_at_end) diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 3e0e1c051..f2836e1e4 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -369,13 +369,32 @@ static void round_corners(GVC_t * gvc, node_t * n, point * A, int sides, B[i++] = B[2]; if (mode == ROUNDED) { + if (style & FILLED) { + int j = 0; + char* fillc = findFill(n); + point* pts = N_GNEW(2*sides,point); + gvrender_set_pencolor (gvc, fillc); + gvrender_set_fillcolor (gvc, fillc); + for (seg = 0; seg < sides; seg++) { + pts[j++] = B[4 * seg + 1]; + pts[j++] = B[4 * seg + 2]; + } + gvrender_polygon(gvc, pts, 2*sides, TRUE); + free (pts); + for (seg = 0; seg < sides; seg++) { + for (i = 0; i < 4; i++) + P2PF(B[4 * seg + 2 + i], BF[i]); + gvrender_beziercurve(gvc, BF, 4, FALSE, FALSE, TRUE); + } + } + pencolor(gvc, n); for (seg = 0; seg < sides; seg++) { gvrender_polyline(gvc, B + 4 * seg + 1, 2); /* convert to floats for gvrender api */ for (i = 0; i < 4; i++) P2PF(B[4 * seg + 2 + i], BF[i]); - gvrender_beziercurve(gvc, BF, 4, FALSE, FALSE); + gvrender_beziercurve(gvc, BF, 4, FALSE, FALSE, FALSE); } } else { /* diagonals are weird. rewrite someday. */ pencolor(gvc, n); diff --git a/lib/common/svggen.c b/lib/common/svggen.c index 41d91863f..d87558c6a 100644 --- a/lib/common/svggen.c +++ b/lib/common/svggen.c @@ -790,7 +790,7 @@ static void svg_ellipse(point p, int rx, int ry, int filled) } static void -svg_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +svg_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { if (cstk[SP].pen == P_NONE) { /* its invisible, don't draw */ diff --git a/lib/common/types.h b/lib/common/types.h index f2d56b397..14eaa0c39 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -234,7 +234,7 @@ extern "C" { void (*ellipse) (point p, int rx, int ry, int filled); void (*polygon) (point * A, int n, int filled); void (*beziercurve) (point * A, int n, int arrow_at_start, - int arrow_at_end); + int arrow_at_end, int filled); void (*polyline) (point * A, int n); boolean bezier_has_arrows; void (*comment) (char *str); diff --git a/lib/common/vrmlgen.c b/lib/common/vrmlgen.c index 215d23147..bdabcc0d4 100644 --- a/lib/common/vrmlgen.c +++ b/lib/common/vrmlgen.c @@ -589,7 +589,7 @@ doSegment (point* A, point p0, double z0, point p1, double z1) } static void -vrml_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +vrml_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { pointf p1, V[4]; int i, j, step; diff --git a/lib/common/vtxgen.c b/lib/common/vtxgen.c index 11ddae70c..4f5811bf4 100644 --- a/lib/common/vtxgen.c +++ b/lib/common/vtxgen.c @@ -529,7 +529,7 @@ static void vtx_textline(point p, textline_t * line) } static void vtx_bezier(point * A, int n, int arrow_at_start, - int arrow_at_end) + int arrow_at_end, int filled) { if (arrow_at_start) { vtx_bzptarray(A, n - 2, 0); diff --git a/lib/common/xdgen.c b/lib/common/xdgen.c index 3dfacb955..68710620a 100644 --- a/lib/common/xdgen.c +++ b/lib/common/xdgen.c @@ -219,9 +219,12 @@ static void xd_polygon(point * A, int n, int filled) } static void -xd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end) +xd_bezier(point * A, int n, int arrow_at_start, int arrow_at_end, int filled) { - xd_points('B', A, n); + if (filled) + xd_points('B', A, n); + else + xd_points('b', A, n); } static void xd_polyline(point * A, int n) diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 19cee5e6f..7af061bf4 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -105,7 +105,7 @@ extern "C" { extern void gvrender_polygon(GVC_t * gvc, point * A, int n, int filled); extern void gvrender_beziercurve(GVC_t * gvc, pointf * AF, int n, - int arrow_at_start, int arrow_at_end); + int arrow_at_start, int arrow_at_end, int); extern void gvrender_polyline(GVC_t * gvc, point * A, int n); extern void gvrender_comment(GVC_t * gvc, char *str); extern void gvrender_user_shape(GVC_t * gvc, char *name, point * A, diff --git a/lib/gvc/gvplugin_render.h b/lib/gvc/gvplugin_render.h index 23e113db0..e2e730245 100644 --- a/lib/gvc/gvplugin_render.h +++ b/lib/gvc/gvplugin_render.h @@ -55,7 +55,7 @@ extern "C" { void (*ellipse) (gvrender_job_t * job, pointf * A, int filled); void (*polygon) (gvrender_job_t * job, pointf * A, int n, int filled); void (*beziercurve) (gvrender_job_t * job, pointf * A, int n, - int arrow_at_start, int arrow_at_end); + int arrow_at_start, int arrow_at_end, int); void (*polyline) (gvrender_job_t * job, pointf * A, int n); void (*comment) (gvrender_job_t * job, char *comment); void (*user_shape) (gvrender_job_t * job, char *name, pointf * A, int sides, diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index bf9922eb5..3421adbff 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -848,7 +848,7 @@ void gvrender_polygon(GVC_t * gvc, point * A, int n, int filled) } void gvrender_beziercurve(GVC_t * gvc, pointf * AF, int n, - int arrow_at_start, int arrow_at_end) + int arrow_at_start, int arrow_at_end, int filled) { gvrender_job_t *job = gvc->job; gvrender_engine_t *gvre = job->render_engine; @@ -865,7 +865,7 @@ void gvrender_beziercurve(GVC_t * gvc, pointf * AF, int n, } for (i = 0; i < n; i++) AF2[i] = gvrender_ptf(job, AF[i]); - gvre->beziercurve(job, AF2, n, arrow_at_start, arrow_at_end); + gvre->beziercurve(job, AF2, n, arrow_at_start, arrow_at_end,filled); } } #ifndef DISABLE_CODEGENS @@ -885,7 +885,7 @@ void gvrender_beziercurve(GVC_t * gvc, pointf * AF, int n, /* end hack */ if (cg && cg->beziercurve) - cg->beziercurve(A, n, arrow_at_start, arrow_at_end); + cg->beziercurve(A, n, arrow_at_start, arrow_at_end, filled); } #endif } -- 2.40.0