]> granicus.if.org Git - graphviz/commitdiff
generate comments outside of renderers, consistently.
authorellson <devnull@localhost>
Fri, 15 Apr 2005 17:49:39 +0000 (17:49 +0000)
committerellson <devnull@localhost>
Fri, 15 Apr 2005 17:49:39 +0000 (17:49 +0000)
   renderers now just do appropriate escaping and comment wrapping
enable comments in SVG

13 files changed:
lib/common/diagen.c
lib/common/emit.c
lib/common/figgen.c
lib/common/mifgen.c
lib/common/mpgen.c
lib/common/picgen.c
lib/common/psgen.c
lib/common/svggen.c
lib/common/types.h
lib/common/vtxgen.c
lib/gvc/gvc.h
lib/gvc/gvconfig.c
lib/gvc/gvrender.c

index 6d015c12ca4f5d268ffacd8c8d9fe9ba9ecf67da..5154bf83f07cc9f20d557451a8e7af5918a67dd0 100644 (file)
@@ -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("<!-- ");
-       /* FIXME - should check for --> sequences in str */
-       dia_fputs(str);
-       dia_fputs(" -->\n");
-    }
+    dia_fputs("<!-- ");
+    /* FIXME - should check for --> 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 */
index 5ff5d3ddf2d2cb02a76de49217220044a4f0830f..6caff05f2763f5561e3c7b2a4947f78bdf07a8a4 100644 (file)
@@ -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);
index 2307d4e5cb492ffd663b77dd781373feafcb973f..114030e97c59268bf936cbd551ae231de15ffdec 100644 (file)
@@ -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 */
index 2dd21dbe8d7fa615bcb51398e5880773ee882968..d40e71a0974071287763a1fc8f435ba056b6590d 100644 (file)
@@ -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, "<BRect %d %d %d %d>\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 */
index 07fb363d4093b4842ec22b55c274957e3611b1e8..003596dfd336ec1354b4caa0a6a74d8582b47753 100644 (file)
@@ -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,
index ef8f38e82afaa3055b362f73175049d9f257f894..816c4200229161eedf9092dd8b6b63cab696fcc2 100644 (file)
@@ -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 = {
index 018ed2160361249cf31a8cc727d79a7892c12875..82454f8683599970248517e56fbeb4a2abcff44b 100644 (file)
@@ -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);
 }
index 0eef632726f7c1e936bab690140f01a89f50e64e..e6e1aa9ff744f6751e71a8771c91aff2704b9543 100644 (file)
@@ -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("<!-- ");
-       svg_fputs(xml_string(str));
-       svg_fputs(" -->\n");
-    }
+    svg_fputs("<!-- ");
+    svg_fputs(xml_string(str));
+    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("<!-- %s -->\n", n->name);
-    svg_comment(n, N_comment);
-#endif
     svg_printf("<g id=\"%s%d\" class=\"node\">", op[Obj], n->id);
     svg_fputs("<title>");
     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 */
index f522d363aece32cdd22769ef60650c092f3dac86..e3082d10d683848fdcf599c14b37fc456f7d29f3 100644 (file)
@@ -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 */
index 5c159deda52607674e7eb74d9cc70829f32e4866..11ddae70c1dd6fdf36172747c542a9712d261888 100644 (file)
@@ -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;
     }
 }
index a5a479fd310c8212263cd4d3c71991f77c807558..c803556daa75e1d850f66a43bf0cb89c9e1b0745 100644 (file)
@@ -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);
 
index 3f91b8cba3dbed6c80be7f6800e596a908095166..f8e429d5340b0c66409c08e8c392c1c356dd64c6 100644 (file)
@@ -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 */
                }
            }
        }
index d783f4c5bf9fb7c9ac08a5ccc34dfee2aaa63060..bf9922eb5e048833697e3c449226a649cf2d6af6 100644 (file)
@@ -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
 }