From bc06e160f4b49f81bc041d938711e3bf86d8b18a Mon Sep 17 00:00:00 2001 From: ellson Date: Sat, 10 Jun 2006 15:04:26 +0000 Subject: [PATCH] change render plugin api to keep some state in job->common --- lib/common/svggen.c | 8 --- lib/gvc/gvcjob.h | 1 - lib/gvc/gvcommon.h | 13 +++++ lib/gvc/gvplugin_render.h | 9 ++- lib/gvc/gvrender.c | 39 ++++++------- plugin/core/gvrender_core_ps.c | 8 +-- plugin/core/gvrender_core_svg.c | 100 +++++++++++--------------------- plugin/gd/gvrender_gd.c | 2 +- plugin/pango/gvrender_pango.c | 2 +- 9 files changed, 75 insertions(+), 107 deletions(-) diff --git a/lib/common/svggen.c b/lib/common/svggen.c index 22514b6b4..6b150fdc3 100644 --- a/lib/common/svggen.c +++ b/lib/common/svggen.c @@ -911,14 +911,6 @@ static void svg_usershape(usershape_t *us, boxf b, point *A, int n, bool filled) svg_polygon(A, n, filled); return; } -/* - p = ND_coord_i(Curnode); - p.x -= ND_lw_i(Curnode); - p.y += ND_ht_i(Curnode) / 2; - p = svgpt(p); - sz.x = ROUND((ND_lw_i(Curnode) + ND_rw_i(Curnode))); - sz.y = ROUND(ND_ht_i(Curnode)); -*/ svg_fputs("name); diff --git a/lib/gvc/gvcjob.h b/lib/gvc/gvcjob.h index bbc28d556..2f565d8cf 100644 --- a/lib/gvc/gvcjob.h +++ b/lib/gvc/gvcjob.h @@ -146,7 +146,6 @@ extern "C" { gvstyle_t *style; /* active style from gvc->styles[] */ char **rawstyle; - char *objname; /* "graph", "node", or "edge" */ int flags; /* emit_graph flags */ diff --git a/lib/gvc/gvcommon.h b/lib/gvc/gvcommon.h index d4640d496..676e41cdc 100644 --- a/lib/gvc/gvcommon.h +++ b/lib/gvc/gvcommon.h @@ -33,6 +33,19 @@ extern "C" { /* rendering state */ int viewNum; /* current view - 1 based count of views, all pages in all layers */ + char *objtype; /* "graph", "cluster", "node", or "edge" */ + char *graph_name; + char *cluster_name; + unsigned long cluster_id; + char *node_name; + unsigned long node_id; + char *edge_tailname; + unsigned long edge_tailid; + char *edge_headname; + unsigned long edge_headid; + unsigned long edge_id; + bool edge_directed; + } GVCOMMON_t; #ifdef __cplusplus diff --git a/lib/gvc/gvplugin_render.h b/lib/gvc/gvplugin_render.h index a30a6fab1..5acac7a14 100644 --- a/lib/gvc/gvplugin_render.h +++ b/lib/gvc/gvplugin_render.h @@ -30,23 +30,22 @@ extern "C" { struct gvrender_engine_s { void (*begin_job) (GVJ_t * job); void (*end_job) (GVJ_t * job); - void (*begin_graph) (GVJ_t * job, char *graphname); + void (*begin_graph) (GVJ_t * job); void (*end_graph) (GVJ_t * job); void (*begin_layer) (GVJ_t * job, char *layername, int layerNum, int numLayers); void (*end_layer) (GVJ_t * job); void (*begin_page) (GVJ_t * job); void (*end_page) (GVJ_t * job); - void (*begin_cluster) (GVJ_t * job, char *clustername, long id); + void (*begin_cluster) (GVJ_t * job); void (*end_cluster) (GVJ_t * job); void (*begin_nodes) (GVJ_t * job); void (*end_nodes) (GVJ_t * job); void (*begin_edges) (GVJ_t * job); void (*end_edges) (GVJ_t * job); - void (*begin_node) (GVJ_t * job, char *nodename, long id); + void (*begin_node) (GVJ_t * job); void (*end_node) (GVJ_t * job); - void (*begin_edge) (GVJ_t * job, char *tailname, bool directed, - char *headname, long id); + void (*begin_edge) (GVJ_t * job); void (*end_edge) (GVJ_t * job); void (*begin_anchor) (GVJ_t * job, char *href, char *tooltip, char *target); diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 418cdfd46..104e78c6b 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -246,7 +246,8 @@ void gvrender_begin_graph(GVJ_t * job, graph_t * g) sy = job->height / (job->zoom * 2.); gvc->sg = g; /* current subgraph/cluster */ - job->objname = "graph"; + job->common->objtype = "graph"; + job->common->graph_name = g->name; job->compscale.x = job->zoom * job->dpi.x / POINTS_PER_INCH; job->compscale.y = job->zoom * job->dpi.y / POINTS_PER_INCH; job->compscale.y *= (job->flags & GVRENDER_Y_GOES_DOWN) ? -1. : 1.; @@ -269,7 +270,7 @@ void gvrender_begin_graph(GVJ_t * job, graph_t * g) if (gvre) { /* render specific init */ if (gvre->begin_graph) - gvre->begin_graph(job, gvc->graphname); + gvre->begin_graph(job); /* background color */ if (((str = agget(g, "bgcolor")) != 0) && str[0]) { @@ -295,16 +296,6 @@ void gvrender_begin_graph(GVJ_t * job, graph_t * g) else { codegen_t *cg = job->codegen; -#if 0 -fprintf(stderr,"boundingBox = %d,%d %d,%d\n", - job->boundingBox.LL.x, - job->boundingBox.LL.y, - job->boundingBox.UR.x, - job->boundingBox.UR.y); -fprintf(stderr,"pb = %d,%d %d,%d\n", - gvc->pb.x, gvc->pb.y); -#endif - if (cg && cg->begin_graph) cg->begin_graph(gvc, g, job->boundingBox, gvc->pb); } @@ -404,9 +395,11 @@ void gvrender_begin_cluster(GVJ_t * job, graph_t * sg) #ifdef WITH_CODEGENS Obj = CLST; #endif - job->objname = "graph"; + job->common->objtype = "cluster"; + job->common->cluster_name = sg->name; + job->common->cluster_id = sg->meta_node->id; if (gvre && gvre->begin_cluster) - gvre->begin_cluster(job, sg->name, sg->meta_node->id); + gvre->begin_cluster(job); #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -506,10 +499,12 @@ void gvrender_begin_node(GVJ_t * job, node_t * n) #ifdef WITH_CODEGENS Obj = NODE; #endif - job->objname = "node"; + job->common->objtype = "node"; + job->common->node_name = n->name; + job->common->node_id = n->id; job->gvc->n = n; /* set current node */ if (gvre && gvre->begin_node) - gvre->begin_node(job, n->name, n->id); + gvre->begin_node(job); #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -545,12 +540,16 @@ void gvrender_begin_edge(GVJ_t * job, edge_t * e) #ifdef WITH_CODEGENS Obj = EDGE; #endif - job->objname = "edge"; + job->common->objtype = "edge"; + job->common->edge_tailname = e->tail->name; + job->common->edge_tailid = e->tail->id; + job->common->edge_headname = e->head->name; + job->common->edge_headid = e->head->id; + job->common->edge_directed = e->tail->graph->root->kind & AGFLAG_DIRECTED; + job->common->edge_id = e->id; job->gvc->e = e; /* set current edge */ if (gvre && gvre->begin_edge) - gvre->begin_edge(job, e->tail->name, - e->tail->graph->root->kind & AGFLAG_DIRECTED, - e->head->name, e->id); + gvre->begin_edge(job); #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; diff --git a/plugin/core/gvrender_core_ps.c b/plugin/core/gvrender_core_ps.c index 491cbde51..7f64c5e31 100644 --- a/plugin/core/gvrender_core_ps.c +++ b/plugin/core/gvrender_core_ps.c @@ -82,12 +82,12 @@ static void psgen_end_job(GVJ_t * job) fprintf(job->output_file, "%%%%EOF\n"); } -static void psgen_begin_graph(GVJ_t * job, char *graphname) +static void psgen_begin_graph(GVJ_t * job) { setupLatin1 = FALSE; if (job->common->viewNum == 0) { - fprintf(job->output_file, "%%%%Title: %s\n", graphname); + fprintf(job->output_file, "%%%%Title: %s\n", job->common->graphname); fprintf(job->output_file, "%%%%Pages: (atend)\n"); if (job->common->show_boxes == NULL) fprintf(job->output_file, "%%%%BoundingBox: (atend)\n"); @@ -217,7 +217,7 @@ static void psgen_begin_cluster(GVJ_t * job, char *clustername, long id) #endif } -static void psgen_begin_node(GVJ_t * job, char *nodename, long id) +static void psgen_begin_node(GVJ_t * job) { #if 0 /* Embed information for Distiller to generate hyperlinked PDF */ @@ -226,7 +226,7 @@ static void psgen_begin_node(GVJ_t * job, char *nodename, long id) } static void -psgen_begin_edge(GVJ_t * job, char *tailname, bool directed, +psgen_begin_edge(GVJ_t * job) char *headname, long id) { #if 0 diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index cebfd62f9..b967b586a 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -42,8 +42,6 @@ typedef enum { FORMAT_SVG, FORMAT_SVGZ, } format_type; extern char *xml_string(char *str); -static char *GraphName; - /* SVG dash array */ static char *sdarray = "5,2"; /* SVG dot array */ @@ -246,14 +244,12 @@ static void svggen_begin_job(GVJ_t * job) svggen_fputs(job, " -->\n"); } -static void svggen_begin_graph(GVJ_t * job, char *graphname) +static void svggen_begin_graph(GVJ_t * job) { - GraphName = graphname; - svggen_fputs(job, "\n", job->pagesArraySize.x * job->pagesArraySize.y); @@ -271,9 +267,6 @@ static void svggen_begin_graph(GVJ_t * job, char *graphname) svggen_printf(job, " viewBox = \"%g %g %d %d\"\n", job->margin.x, job->margin.y, job->width, job->height); -// svggen_printf(job, " viewBox = \"%g %g %g %g\"\n", -// job->margin.x, job->margin.y, -// job->width + job->margin.x, job->height + job->margin.y); /* namespace of svg */ svggen_fputs(job, " xmlns=\"http://www.w3.org/2000/svg\""); /* namespace of xlink */ @@ -322,9 +315,9 @@ static void svggen_begin_page(GVJ_t * job) svggen_fputs(job, " style=\"font-family:"); svggen_fputs(job, job->style->fontfam); svggen_printf(job, ";font-size:%.2f;\">\n", job->style->fontsz); - if (GraphName[0]) { + if (job->common->graph_name[0]) { svggen_fputs(job, ""); - svggen_fputs(job, xml_string(GraphName)); + svggen_fputs(job, xml_string(job->common->graph_name)); svggen_fputs(job, "\n"); } } @@ -334,11 +327,11 @@ static void svggen_end_page(GVJ_t * job) svggen_fputs(job, "\n"); } -static void svggen_begin_cluster(GVJ_t * job, char *clustername, long id) +static void svggen_begin_cluster(GVJ_t * job) { - svggen_printf(job, "", id); + svggen_printf(job, "", job->common->cluster_id); svggen_fputs(job, ""); - svggen_fputs(job, xml_string(clustername)); + svggen_fputs(job, xml_string(job->common->cluster_name)); svggen_fputs(job, "\n"); } @@ -347,11 +340,11 @@ static void svggen_end_cluster(GVJ_t * job) svggen_fputs(job, "\n"); } -static void svggen_begin_node(GVJ_t * job, char *nodename, long id) +static void svggen_begin_node(GVJ_t * job) { - svggen_printf(job, "", id); + svggen_printf(job, "", job->common->node_id); svggen_fputs(job, ""); - svggen_fputs(job, xml_string(nodename)); + svggen_fputs(job, xml_string(job->common->node_name)); svggen_fputs(job, "\n"); } @@ -361,22 +354,21 @@ static void svggen_end_node(GVJ_t * job) } static void -svggen_begin_edge(GVJ_t * job, char *tailname, bool directed, - char *headname, long id) +svggen_begin_edge(GVJ_t * job) { char *edgeop; - svggen_printf(job, "", id); - if (directed) + svggen_printf(job, "", job->common->edge_id); + if (job->common->edge_directed) edgeop = "->"; else edgeop = "--"; svggen_fputs(job, ""); - svggen_fputs(job, xml_string(tailname)); + svggen_fputs(job, xml_string(job->common->edge_tailname)); svggen_fputs(job, edgeop); /* can't do this in single svggen_printf because * xml_string's buffer gets reused. */ - svggen_fputs(job, xml_string(headname)); + svggen_fputs(job, xml_string(job->common->edge_headname)); svggen_fputs(job, "\n"); } @@ -480,61 +472,35 @@ static void svggen_polyline(GVJ_t * job, pointf * A, int n) svggen_fputs(job, "\"/>\n"); } -#if 0 static void -svggen_user_shape(GVJ_t * job, char *name, pointf * A, int n, int filled) +svggen_usershape(GVJ_t * job, usershape_t *us, boxf b, pointf * A, int n, int filled) { - int i; - point p; - pointf pf; - point sz; - char *imagefile; - int minx, miny; - if (job->style->pen == PEN_NONE) { /* its invisible, don't draw */ return; } - imagefile = agget(gvc->n, "shapefile"); - if (imagefile == 0) { - svggen_polygon(gvc, A, n, filled); - return; + if (! us->f) { + svggen_polygon(job, A, n, filled); + return; } - pf.x = ND_coord_i(gvc->n).x - ND_lw_i(gvc->n); - pf.y = ND_coord_i(gvc->n).y + ND_ht_i(gvc->n) / 2; - p = svgpt(gvc, pf); - sz.x = ROUND((ND_lw_i(gvc->n) + ND_rw_i(gvc->n))); - sz.y = ROUND(ND_ht_i(gvc->n)); - - svggen_fputs(job, "n->name); - svggen_fputs(job, "\">\nname); + svggen_fputs(job, "\">\n\n\nn->name); + svggen_fputs(job, us->name); + svggen_printf + (job, "\" width=\"%gpx\" height=\"%fpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%f\" clip-path=\"url(#clipPath.", + b.UR.x - b.LL.x, b.UR.y - b.LL.y, b.LL.x, b.LL.y); + svggen_fputs(job, us->name); svggen_fputs(job, ")\"/>\n"); } -#endif /* color names from http://www.w3.org/TR/SVG/types.html */ /* NB. List must be LANG_C sorted */ diff --git a/plugin/gd/gvrender_gd.c b/plugin/gd/gvrender_gd.c index bb602e386..d06c54f4f 100644 --- a/plugin/gd/gvrender_gd.c +++ b/plugin/gd/gvrender_gd.c @@ -101,7 +101,7 @@ static void gdgen_resolve_color(GVJ_t * job, gvcolor_t * color) static int white, black, transparent, basecolor; -static void gdgen_begin_graph(GVJ_t * job, char *graphname) +static void gdgen_begin_graph(GVJ_t * job) { char *bgcolor_str = NULL, *truecolor_str = NULL; bool truecolor_p = FALSE; /* try to use cheaper paletted mode */ diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index 27bc9800e..e63faf05e 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -127,7 +127,7 @@ reader (void *closure, unsigned char *data, unsigned int length) return CAIRO_STATUS_READ_ERROR; } -static void cairogen_begin_graph(GVJ_t * job, char *graphname) +static void cairogen_begin_graph(GVJ_t * job) { cairo_t *cr; cairo_surface_t *surface; -- 2.40.0