]> granicus.if.org Git - graphviz/commitdiff
Factor out writing of id and combine with writing class;
authorEmden Gansner <emdenrg@google.com>
Fri, 10 Jun 2016 20:07:40 +0000 (16:07 -0400)
committerEmden Gansner <emdenrg@google.com>
Fri, 10 Jun 2016 20:07:40 +0000 (16:07 -0400)
put quote ending class value in svg_print_id_class.

plugin/core/gvrender_core_svg.c

index 6e23584bb497f1a00d7fc56b44dda1cc72f86178..a2e34532a5e535779988a459053bd827bd168ad4 100644 (file)
@@ -80,15 +80,20 @@ static void svg_bzptarray(GVJ_t * job, pointf * A, int n)
 #endif
 }
 
-static void svg_print_class(GVJ_t * job, char* kind, void* obj)
+static void svg_print_id_class(GVJ_t * job, char* id, char* idx, char* kind, void* obj)
 {
     char* str;
 
+    gvputs(job, "<g id=\"");
+    gvputs(job, xml_string(id));
+    if (idx)
+       gvprintf (job, "_%s", xml_string(idx));
     gvprintf(job, "\" class=\"%s", kind);
     if ((str = agget(obj, "class")) && *str) {
        gvputs(job, " ");
        gvputs(job, xml_string(str));
     }
+    gvputs(job, "\"");
 }
 
 static void svg_print_color(GVJ_t * job, gvcolor_t color)
@@ -221,10 +226,8 @@ static void svg_begin_layer(GVJ_t * job, char *layername, int layerNum,
 {
     obj_state_t *obj = job->obj;
 
-    gvputs(job, "<g id=\"");
-    gvputs(job, xml_string(layername));
-    svg_print_class(job, "layer", obj->u.g);
-    gvputs(job, "\">\n");
+    svg_print_id_class(job, layername, NULL, "layer", obj->u.g);
+    gvputs(job, ">\n");
 }
 
 static void svg_end_layer(GVJ_t * job)
@@ -242,11 +245,9 @@ static void svg_begin_page(GVJ_t * job)
 
     /* its really just a page of the graph, but its still a graph,
      * and it is the entire graph if we're not currently paging */
-    gvputs(job, "<g id=\"");
-    gvputs(job, xml_string(obj->id));
-    svg_print_class(job, "graph", obj->u.g);
+    svg_print_id_class(job, obj->id, NULL, "graph", obj->u.g);
     gvprintf(job,
-            "\" transform=\"scale(%g %g) rotate(%d) translate(%g %g)\">\n",
+            " transform=\"scale(%g %g) rotate(%d) translate(%g %g)\">\n",
             job->scale.x, job->scale.y, -job->rotation,
             job->translation.x, -job->translation.y);
     /* default style */
@@ -266,10 +267,8 @@ static void svg_begin_cluster(GVJ_t * job)
 {
     obj_state_t *obj = job->obj;
 
-    gvputs(job, "<g id=\"");
-    gvputs(job, xml_string(obj->id));
-    svg_print_class(job, "cluster", obj->u.sg);
-    gvputs(job, "\">\n");
+    svg_print_id_class(job, obj->id, NULL, "cluster", obj->u.sg);
+    gvputs(job, ">\n");
     gvputs(job, "<title>");
     gvputs(job, xml_string(agnameof(obj->u.g)));
     gvputs(job, "</title>\n");
@@ -283,13 +282,14 @@ static void svg_end_cluster(GVJ_t * job)
 static void svg_begin_node(GVJ_t * job)
 {
     obj_state_t *obj = job->obj;
+    char* idx;
 
-    gvputs(job, "<g id=\"");
-    gvputs(job, xml_string(obj->id));
     if (job->layerNum > 1)
-       gvprintf (job, "_%s", xml_string(job->gvc->layerIDs[job->layerNum]));
-    svg_print_class(job, "node", obj->u.n);
-    gvputs(job, "\">\n");
+       idx = job->gvc->layerIDs[job->layerNum];
+    else
+       idx = NULL;
+    svg_print_id_class(job, obj->id, idx, "node", obj->u.n);
+    gvputs(job, ">\n");
     gvputs(job, "<title>");
     gvputs(job, xml_string(agnameof(obj->u.n)));
     gvputs(job, "</title>\n");
@@ -305,10 +305,8 @@ static void svg_begin_edge(GVJ_t * job)
     obj_state_t *obj = job->obj;
     char *ename;
 
-    gvputs(job, "<g id=\"");
-    gvputs(job, xml_string(obj->id));
-    svg_print_class(job, "edge", obj->u.e);
-    gvputs(job, "\">\n");
+    svg_print_id_class(job, obj->id, NULL, "edge", obj->u.e);
+    gvputs(job, ">\n");
 
     gvputs(job, "<title>");
     ename = strdup_and_subst_obj("\\E", (void *) (obj->u.e));