From: ellson Date: Tue, 18 Oct 2005 21:09:49 +0000 (+0000) Subject: Fix bug 796; allow style=rounded for clusters X-Git-Tag: LAST_LIBGRAPH~32^2~7083 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=236daa531a35dda16e7708a9b6de66c58cca21a0;p=graphviz Fix bug 796; allow style=rounded for clusters --- diff --git a/lib/common/const.h b/lib/common/const.h index 6afa6711c..118943885 100644 --- a/lib/common/const.h +++ b/lib/common/const.h @@ -232,6 +232,13 @@ #define CHAR_LATIN1 1 #define CHAR_BIG5 2 +/* style flags */ +#define FILLED (1 << 0) +#define ROUNDED (1 << 1) +#define DIAGONALS (1 << 2) +#define AUXLABELS (1 << 3) +#define INVISIBLE (1 << 4) + /* user-specified node position: ND_pinned */ #define P_SET 1 /* position supplied by user */ #define P_FIX 2 /* position fixed during topological layout */ diff --git a/lib/common/emit.c b/lib/common/emit.c index 8d9473357..bc260abe4 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1363,7 +1363,7 @@ void emit_jobs_eof(GVC_t * gvc) void emit_clusters(GVJ_t * job, Agraph_t * g, int flags) { - int i, c, filled; + int i, c, istyle, filled; graph_t *sg; point A[4]; char *color, *fillcolor, *pencolor, *str, **style; @@ -1393,13 +1393,17 @@ void emit_clusters(GVJ_t * job, Agraph_t * g, int flags) } gvrender_begin_context(job); filled = FALSE; + istyle = 0; xdemitState = EMIT_DRAW; if (((str = agget(sg, "style")) != 0) && str[0]) { gvrender_set_style(job, (style = parse_style(str))); for (i = 0; style[i]; i++) if (strcmp(style[i], "filled") == 0) { filled = TRUE; - break; + istyle |= FILLED; + } + else if (strcmp(style[i], "rounded") == 0) { + istyle |= ROUNDED; } } fillcolor = pencolor = 0; @@ -1436,22 +1440,31 @@ void emit_clusters(GVJ_t * job, Agraph_t * g, int flags) if (((color = agget(sg, "fillcolor")) != 0) && color[0]) fillcolor = color; } - if (pencolor) - gvrender_set_pencolor(job, pencolor); - if (fillcolor) - gvrender_set_fillcolor(job, fillcolor); A[0] = GD_bb(sg).LL; A[2] = GD_bb(sg).UR; A[1].x = A[2].x; A[1].y = A[0].y; A[3].x = A[0].x; A[3].y = A[2].y; - if (late_int(sg, G_peripheries, 1, 0)) { - gvrender_polygon(job, A, 4, filled); - } else if (filled) { - if (fillcolor && fillcolor != pencolor) - gvrender_set_pencolor(job, fillcolor); - gvrender_polygon(job, A, 4, filled); + if (istyle & ROUNDED) { + if (!pencolor) pencolor = DEFAULT_COLOR; + if (!fillcolor) fillcolor = DEFAULT_FILL; + if (late_int(sg, G_peripheries, 1, 0) || filled) + round_corners(job, fillcolor, pencolor, A, 4, istyle); + } + else { + if (pencolor) + gvrender_set_pencolor(job, pencolor); + if (fillcolor) + gvrender_set_fillcolor(job, fillcolor); + if (late_int(sg, G_peripheries, 1, 0)) { + gvrender_polygon(job, A, 4, filled); + } + else if (filled) { + if (fillcolor && fillcolor != pencolor) + gvrender_set_pencolor(job, fillcolor); + gvrender_polygon(job, A, 4, filled); + } } xdemitState = EMIT_DRAW; if (GD_label(sg)) diff --git a/lib/common/render.h b/lib/common/render.h index 8d1d0c1a0..35a220571 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -149,6 +149,7 @@ extern "C" { extern void place_portlabel(edge_t * e, bool head_p); extern char *ps_string(char *s, int); extern int rank(graph_t * g, int balance, int maxiter); + extern void round_corners(GVJ_t*, char*, char*, point*, int, int); extern void routesplinesinit(void); extern point *routesplines(path *, int *); extern void routesplinesterm(void); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 508b55f5f..ac9f535c5 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -22,11 +22,6 @@ extern codegen_t VRML_CodeGen; #endif -#define FILLED (1 << 0) -#define ROUNDED (1 << 1) -#define DIAGONALS (1 << 2) -#define AUXLABELS (1 << 3) -#define INVISIBLE (1 << 4) #define RBCONST 12 #define RBCURVE .5 @@ -232,6 +227,18 @@ void pencolor(GVJ_t * job, node_t * n) gvrender_set_pencolor(job, DEFAULT_COLOR); } +static +char* findPen(node_t * n) +{ + char *color; + + color = late_nnstring(n, N_color, ""); + if (color[0]) + return color; + else + return DEFAULT_COLOR; +} + static char *findFill(node_t * n) { @@ -337,8 +344,8 @@ static point interpolate(double t, point p0, point p1) return rv; } -static void round_corners(GVJ_t * job, node_t * n, point * A, int sides, - int style) +void round_corners(GVJ_t * job, char* fillc, char* penc, point * A, + int sides, int style) { point *B, C[2], p0, p1; pointf BF[4]; @@ -378,7 +385,6 @@ static void round_corners(GVJ_t * job, node_t * n, point * A, int sides, if (mode == ROUNDED) { if (style & FILLED) { int j = 0; - char* fillc = findFill(n); point* pts = N_GNEW(2*sides,point); gvrender_begin_context(job); gvrender_set_pencolor (job, fillc); @@ -396,7 +402,7 @@ static void round_corners(GVJ_t * job, node_t * n, point * A, int sides, } gvrender_end_context(job); } - pencolor(job, n); + gvrender_set_pencolor(job, penc); for (seg = 0; seg < sides; seg++) { gvrender_polyline(job, B + 4 * seg + 1, 2); @@ -406,9 +412,9 @@ static void round_corners(GVJ_t * job, node_t * n, point * A, int sides, gvrender_beziercurve(job, BF, 4, FALSE, FALSE, FALSE); } } else { /* diagonals are weird. rewrite someday. */ - pencolor(job, n); + gvrender_set_pencolor(job, penc); if (style & FILLED) - gvrender_set_fillcolor(job, findFill(n)); /* emit fill color */ + gvrender_set_fillcolor(job, fillc); /* emit fill color */ gvrender_polygon(job, A, sides, style & FILLED); for (seg = 0; seg < sides; seg++) { #ifdef NOTDEF @@ -424,6 +430,12 @@ static void round_corners(GVJ_t * job, node_t * n, point * A, int sides, free(B); } +static void +node_round_corners(GVJ_t * job, node_t* n, point * A, int sides, int style) +{ + round_corners(job, findFill(n), findPen(n), A, sides, style); +} + /*=============================poly start=========================*/ /* userSize; @@ -1303,7 +1315,7 @@ static void poly_gencode(GVJ_t * job, node_t * n) Mcircle_hack(job, n); } } else if (style & (ROUNDED | DIAGONALS)) { - round_corners(job, n, A, sides, style); + node_round_corners(job, n, A, sides, style); } else { gvrender_polygon(job, A, sides, filled); } @@ -1872,7 +1884,7 @@ static void record_gencode(GVJ_t * job, node_t * n) if (streq(ND_shape(n)->name, "Mrecord")) style |= ROUNDED; if (style & (ROUNDED | DIAGONALS)) - round_corners(job, n, A, 4, ROUNDED); + node_round_corners(job, n, A, 4, ROUNDED); else gvrender_polygon(job, A, 4, style & FILLED); xdemitState = EMIT_LABEL;