From: ellson Date: Fri, 15 Apr 2005 17:49:39 +0000 (+0000) Subject: generate comments outside of renderers, consistently. X-Git-Tag: LAST_LIBGRAPH~32^2~7646 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15454e55779da9561d0d4fd62f01ebe4f9561621;p=graphviz generate comments outside of renderers, consistently. renderers now just do appropriate escaping and comment wrapping enable comments in SVG --- diff --git a/lib/common/diagen.c b/lib/common/diagen.c index 6d015c12c..5154bf83f 100644 --- a/lib/common/diagen.c +++ b/lib/common/diagen.c @@ -220,15 +220,12 @@ static void dia_grstylefill(context_t * cp, int filled) } } -static void dia_comment(void *obj, attrsym_t * sym) +static void dia_comment(char *str) { - char *str = late_string(obj, sym, ""); - if (str[0]) { - dia_fputs(" sequences in str */ - dia_fputs(str); - dia_fputs(" -->\n"); - } + dia_fputs(" sequences in str */ + dia_fputs(str); + dia_fputs(" -->\n"); } static void @@ -282,7 +279,6 @@ static void dia_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) Offset.y = GD_drawing(g)->margin.y * SCALE; if (onetime) { init_dia(); - dia_comment(g, agfindattr(g, "comment")); onetime = FALSE; } dia_fputs @@ -961,7 +957,7 @@ codegen_t DIA_CodeGen = { dia_ellipse, dia_polygon, dia_bezier, dia_polyline, 1, /* bezier_has_arrows */ - 0, /* dia_comment */ + dia_comment, 0, /* dia_textsize */ dia_user_shape, 0 /* dia_usershapesize */ diff --git a/lib/common/emit.c b/lib/common/emit.c index 5ff5d3ddf..6caff05f2 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -583,16 +583,17 @@ static void emit_node(GVC_t * gvc, node_t * n) if (ND_shape(n) == NULL) return; -#if 0 -fprintf(stderr,"node_in_layer %s node_in_pageBox %s state %s\n", - node_in_layer(gvc, n->graph, n)?"true":"false", - node_in_pageBox(gvc, n)?"true":"false", - (ND_state(n) != gvc->pageNum)?"true":"false"); -#endif if (node_in_layer(gvc, n->graph, n) && node_in_pageBox(gvc, n) && (ND_state(n) != gvc->pageNum)) { + + gvrender_comment(gvc, n->name); + + s = late_string(n, N_comment, ""); + if (s[0]) + gvrender_comment(gvc, s); + gvrender_begin_node(gvc, n); if (((s = agget(n, "href")) && s[0]) || ((s = agget(n, "URL")) && s[0])) { @@ -900,15 +901,23 @@ static void emit_edge(GVC_t * gvc, edge_t * e) char *s, *url = NULL, *label = NULL, *tooltip = NULL, *target = NULL; textlabel_t *lab = NULL; -#if 0 -fprintf(stderr,"edge_in_layer %s edge_in_pageBox %s\n", - edge_in_layer(gvc, e->head->graph, e)?"true":"false", - edge_in_pageBox(gvc, e)?"true":"false"); -#endif - if (! edge_in_pageBox(gvc, e) || ! edge_in_layer(gvc, e->head->graph, e)) return; + s = malloc(strlen(e->tail->name) + 2 + strlen(e->head->name) + 1); + strcpy(s,e->tail->name); + if (AG_IS_DIRECTED(e->tail->graph)) + strcat(s,"->"); + else + strcat(s,"--"); + strcat(s,e->head->name); + gvrender_comment(gvc, s); + free(s); + + s = late_string(e, E_comment, ""); + if (s[0]) + gvrender_comment(gvc, s); + gvrender_begin_edge(gvc, e); if (((s = agget(e, "href")) && s[0]) || ((s = agget(e, "URL")) && s[0])) { @@ -1112,6 +1121,10 @@ void emit_graph(GVC_t * gvc, graph_t * g) if (gvc->pageNum == 0) gvrender_begin_job(gvc); + + s = late_string(g, agfindattr(g, "comment"), ""); + gvrender_comment(gvc, s); + gvrender_begin_graph(gvc, g); if (flags & EMIT_COLORS) { gvrender_set_fillcolor(gvc, DEFAULT_FILL); diff --git a/lib/common/figgen.c b/lib/common/figgen.c index 2307d4e5c..114030e97 100644 --- a/lib/common/figgen.c +++ b/lib/common/figgen.c @@ -161,12 +161,9 @@ static void figptarray(point * A, int n, int close) fprintf(Output_file, "\n"); } -static void fig_comment(void *obj, attrsym_t * sym) +static void fig_comment(char *str) { - char *str; - str = late_string(obj, sym, ""); - if (str[0]) - fprintf(Output_file, "# %s\n", str); + fprintf(Output_file, "# %s\n", str); } static void @@ -206,7 +203,6 @@ static void fig_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) PB.UR.y); #endif init_fig(); - fig_comment(g, agfindattr(g, "comment")); onetime = FALSE; } } @@ -226,19 +222,6 @@ fig_begin_page(graph_t * g, point page, double scale, int rot, */ } -static void fig_begin_node(node_t * n) -{ - fprintf(Output_file, "# %s\n", n->name); - fig_comment(n, N_comment); -} - - -static void fig_begin_edge(edge_t * e) -{ - fprintf(Output_file, "# %s -> %s\n", e->tail->name, e->head->name); - fig_comment(e, E_comment); -} - static void fig_begin_context(void) { assert(SP + 1 < MAXNEST); @@ -621,12 +604,12 @@ codegen_t FIG_CodeGen = { fig_begin_job, fig_end_job, fig_begin_graph, 0, /* fig_end_graph */ fig_begin_page, 0, /* fig_end_page */ - 0 /* fig_begin_layer */ , 0 /* fig_end_layer */ , - 0, /* fig_begin_cluster */ 0, /* fig_end_cluster */ + 0, /* fig_begin_layer */ 0, /* fig_end_layer */ + 0, /* fig_begin_cluster */ 0, /* fig_end_cluster */ 0, /* fig_begin_nodes */ 0, /* fig_end_nodes */ 0, /* fig_begin_edges */ 0, /* fig_end_edges */ - fig_begin_node, 0, /* fig_end_node */ - fig_begin_edge, 0, /* fig_end_edge */ + 0, /* fig_begin_node */ 0, /* fig_end_node */ + 0, /* fig_begin_edge */ 0, /* fig_end_edge */ fig_begin_context, fig_end_context, 0, /* fig_begin_anchor */ 0, /* fig_end_anchor */ fig_set_font, fig_textline, @@ -634,7 +617,7 @@ codegen_t FIG_CodeGen = { fig_ellipse, fig_polygon, fig_bezier, fig_polyline, 0, /* bezier_has_arrows */ - 0, /* fig_comment */ + fig_comment, 0, /* fig_textsize */ fig_user_shape, 0 /* fig_usershapesize */ diff --git a/lib/common/mifgen.c b/lib/common/mifgen.c index 2dd21dbe8..d40e71a09 100644 --- a/lib/common/mifgen.c +++ b/lib/common/mifgen.c @@ -144,12 +144,9 @@ static void mif_style(context_t * cp) cp->pen, cp->fill, cp->penwidth); } -static void mif_comment(void *obj, attrsym_t * sym) +static void mif_comment(char *str) { - char *str; - str = late_string(obj, sym, ""); - if (str[0]) - fprintf(Output_file, "# %s\n", str); + fprintf(Output_file, "# %s\n", str); } static void @@ -323,7 +320,6 @@ static void mif_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) fprintf(Output_file, "\n", PB.LL.x, PB.UR.y, PB.UR.x - PB.LL.x, PB.UR.y - PB.LL.y); init_mif(); - mif_comment(g, agfindattr(g, "comment")); onetime = FALSE; } } @@ -344,18 +340,6 @@ mif_begin_page(graph_t * g, point page, double scale, int rot, 14 * Scale); } -static void mif_begin_node(node_t * n) -{ - fprintf(Output_file, "# %s\n", n->name); - mif_comment(n, N_comment); -} - -static void mif_begin_edge(edge_t * e) -{ - fprintf(Output_file, "# %s -> %s\n", e->tail->name, e->head->name); - mif_comment(e, E_comment); -} - static void mif_begin_context(void) { assert(SP + 1 < MAXNEST); @@ -580,11 +564,11 @@ codegen_t MIF_CodeGen = { mif_begin_graph, 0, /* mif_end_graph */ mif_begin_page, 0, /* mif_end_page */ 0, /* mif_begin_layer */ 0, /* mif_end_layer */ - 0, /* mif_begin_cluster */ 0, /* mif_end_cluster */ + 0, /* mif_begin_cluster */ 0, /* mif_end_cluster */ 0, /* mif_begin_nodes */ 0, /* mif_end_nodes */ 0, /* mif_begin_edges */ 0, /* mif_end_edges */ - mif_begin_node, 0, /* mif_end_node */ - mif_begin_edge, 0, /* mif_end_edge */ + 0, /* mif_begin_node */ 0, /* mif_end_node */ + 0, /* mif_begin_edge */ 0, /* mif_end_edge */ mif_begin_context, mif_end_context, 0, /* mif_begin_anchor */ 0, /* mif_end_anchor */ mif_set_font, mif_textline, @@ -592,7 +576,7 @@ codegen_t MIF_CodeGen = { mif_ellipse, mif_polygon, mif_bezier, mif_polyline, 0, /* bezier_has_arrows */ - 0, /* mif_comment */ + mif_comment, 0, /* mif_textsize */ mif_user_shape, 0 /* mif_usershapesize */ diff --git a/lib/common/mpgen.c b/lib/common/mpgen.c index 07fb363d4..003596dfd 100644 --- a/lib/common/mpgen.c +++ b/lib/common/mpgen.c @@ -75,12 +75,9 @@ static void mp_end_job(void) fprintf(Output_file, "%% \n"); } -static void mp_comment(void *obj, attrsym_t * sym) +static void mp_comment(char *str) { - char *str; - str = late_string(obj, sym, ""); - if (str[0]) - fprintf(Output_file, "%% %s\n", str); + fprintf(Output_file, "%% %s\n", str); } static void mp_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) @@ -89,7 +86,6 @@ static void mp_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) if (onetime) { fprintf(Output_file, "%% BoundingBox: %d %d %d %d\n", bb.LL.x, bb.LL.y, bb.UR.x + 1, bb.UR.y + 1); - mp_comment(g, agfindattr(g, "comment")); /* cat_libfile(Output_file,U_lib,mp_lib); */ onetime = FALSE; } @@ -104,19 +100,6 @@ mp_begin_page(graph_t * g, point page, double scale, int rot, point offset) S[SP].size = 0.0; } -static void mp_begin_node(node_t * n) -{ - fprintf(Output_file, "%% GV node: \n%% %s\n", n->name); - mp_comment(n, N_comment); -} - -static void mp_begin_edge(edge_t * e) -{ - fprintf(Output_file, "%% GV edge: \n%% %s -> %s\n", e->tail->name, - e->head->name); - mp_comment(e, E_comment); -} - static void mp_begin_context(void) { if (SP == STACKSIZE - 1) @@ -283,8 +266,8 @@ codegen_t MP_CodeGen = { 0, /* mp_begin_cluster */ 0, /* mp_end_cluster */ 0, /* mp_begin_nodes */ 0, /* mp_end_nodes */ 0, /* mp_begin_edges */ 0, /* mp_end_edges */ - mp_begin_node, 0, /* mp_end_node */ - mp_begin_edge, 0, /* mp_end_edge */ + 0, /* mp_begin_node */ 0, /* mp_end_node */ + 0, /* mp_begin_edge */ 0, /* mp_end_edge */ mp_begin_context, mp_end_context, 0, /* mp_begin_anchor */ 0, /* mp_end_anchor */ mp_set_font, mp_textline, diff --git a/lib/common/picgen.c b/lib/common/picgen.c index ef8f38e82..816c42002 100644 --- a/lib/common/picgen.c +++ b/lib/common/picgen.c @@ -591,13 +591,9 @@ static void pic_bezier(point * A, int n, int arrow_at_start, fprintf(Output_file, "move to P%d; line attrs%d to P%d then to P%d\n", i, SP, i + 1, i + 2); /* use line, as splines can't be dotted or dashed */ } -static void pic_comment(void *obj, attrsym_t * sym) +static void pic_comment(char *str) { - char *str; - - str = late_string(obj, sym, ""); - if (str[0]) - fprintf(Output_file, "'\\\" %s\n", str); + fprintf(Output_file, "'\\\" %s\n", str); } codegen_t PIC_CodeGen = { diff --git a/lib/common/psgen.c b/lib/common/psgen.c index 018ed2160..82454f868 100644 --- a/lib/common/psgen.c +++ b/lib/common/psgen.c @@ -90,12 +90,9 @@ static void ps_end_job(void) fprintf(Output_file, "%%%%EOF\n"); } -static void ps_comment(void *obj, attrsym_t * sym) +static void ps_comment(char *str) { - char *str; - str = late_string(obj, sym, ""); - if (str[0]) - fprintf(Output_file, "%% %s\n", str); + fprintf(Output_file, "%% %s\n", str); } static void ps_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) @@ -110,7 +107,6 @@ static void ps_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) if (Show_boxes == NULL) fprintf(Output_file, "%%%%BoundingBox: %d %d %d %d\n", 0, 0, sz.x, sz.y); - ps_comment(g, agfindattr(g, "comment")); fprintf(Output_file, "%%%%EndComments\nsave\n"); cat_libfile(Output_file, U_lib, ps_txt); epsf_define(Output_file); @@ -218,8 +214,6 @@ static void ps_begin_cluster(graph_t * g) static void ps_begin_node(node_t * n) { Curnode = n; - fprintf(Output_file, "\n%%\t%s\n", n->name); - ps_comment(n, N_comment); /* Embed information for Distiller to generate hyperlinked PDF */ map_begin_node(n); @@ -227,9 +221,6 @@ static void ps_begin_node(node_t * n) static void ps_begin_edge(edge_t * e) { - fprintf(Output_file, "\n%%\t%s -> %s\n", e->tail->name, e->head->name); - ps_comment(e, E_comment); - /* Embed information for Distiller, so it can generate hyperactive PDF */ map_begin_edge(e); } diff --git a/lib/common/svggen.c b/lib/common/svggen.c index 0eef63272..e6e1aa9ff 100644 --- a/lib/common/svggen.c +++ b/lib/common/svggen.c @@ -346,14 +346,11 @@ static void svg_grstyle(context_t * cp, int filled) svg_fputs("\""); } -static void svg_comment(void *obj, attrsym_t * sym) +static void svg_comment(char *str) { - char *str = late_string(obj, sym, ""); - if (str[0]) { - svg_fputs("\n"); - } + svg_fputs("\n"); } static void @@ -446,7 +443,6 @@ static void svg_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) PB.UR.y); #endif init_svg(); - svg_comment(g, agfindattr(g, "comment")); onetime = FALSE; } if (dpi < 1.0) @@ -553,10 +549,6 @@ static void svg_end_cluster(void) static void svg_begin_node(node_t * n) { Curnode = n; -#if 0 - svg_printf("\n", n->name); - svg_comment(n, N_comment); -#endif svg_printf("", op[Obj], n->id); svg_fputs(""); svg_fputs(xml_string(n->name)); @@ -926,7 +918,7 @@ codegen_t SVG_CodeGen = { svg_ellipse, svg_polygon, svg_bezier, svg_polyline, 0, /* bezier_has_arrows */ - 0, /* svg_comment */ + svg_comment, 0, /* svg_textsize */ svg_user_shape, 0 /* svg_usershape_size */ diff --git a/lib/common/types.h b/lib/common/types.h index f522d363a..e3082d10d 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -237,7 +237,7 @@ extern "C" { int arrow_at_end); void (*polyline) (point * A, int n); boolean bezier_has_arrows; - void (*comment) (void *obj, attrsym_t * sym); + void (*comment) (char *str); void (*textsize) (void); /* not used */ void (*user_shape) (char *name, point * A, int sides, int filled); void (*usershapesize) (void); /* not used */ diff --git a/lib/common/vtxgen.c b/lib/common/vtxgen.c index 5c159deda..11ddae70c 100644 --- a/lib/common/vtxgen.c +++ b/lib/common/vtxgen.c @@ -201,12 +201,9 @@ static void vtx_font(context_t * cp) */ } -static void vtx_comment(void *obj, attrsym_t * sym) +static void vtx_comment(char *str) { - char *str; - str = late_string(obj, sym, ""); - if (str[0]) - fprintf(Output_file, "; %s\n", str); + fprintf(Output_file, "; %s\n", str); } static void @@ -246,7 +243,6 @@ static void vtx_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) /* PB = bb; */ if (onetime) { init_vtx(); - vtx_comment(g, agfindattr(g, "comment")); onetime = FALSE; } } diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index a5a479fd3..c803556da 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -106,7 +106,7 @@ extern "C" { extern void gvrender_beziercurve(GVC_t * gvc, pointf * AF, int n, int arrow_at_start, int arrow_at_end); extern void gvrender_polyline(GVC_t * gvc, point * A, int n); - extern void gvrender_comment(GVC_t * gvc, void *obj, attrsym_t * sym); + extern void gvrender_comment(GVC_t * gvc, char *str); extern void gvrender_user_shape(GVC_t * gvc, char *name, point * A, int sides, int filled); diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index 3f91b8cba..f8e429d53 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -302,7 +302,7 @@ void gvconfig(GVC_t * gvc) else { config_text[sz] = '\0'; /* make input into a null terminated string */ gvconfig_plugin_install_from_config(gvc, config_text); - /* NB. config_text not freed becasue we retain char* into it */ + /* NB. config_text not freed because we retain char* into it */ } } } diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index d783f4c5b..bf9922eb5 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -920,21 +920,23 @@ void gvrender_polyline(GVC_t * gvc, point * A, int n) #endif } -void gvrender_comment(GVC_t * gvc, void *obj, attrsym_t * sym) +void gvrender_comment(GVC_t * gvc, char *str) { gvrender_job_t *job = gvc->job; gvrender_engine_t *gvre = job->render_engine; + if (!str || !str[0]) + return; + if (gvre && gvre->comment) { - if (sym) - gvre->comment(job, agxget(obj, sym->index)); + gvre->comment(job, str); } #ifndef DISABLE_CODEGENS else { codegen_t *cg = job->codegen; if (cg && cg->comment) - cg->comment(obj, sym); + cg->comment(str); } #endif }