From: ellson Date: Sat, 17 Jun 2006 19:47:15 +0000 (+0000) Subject: "ps2ps" imageloader X-Git-Tag: LAST_LIBGRAPH~32^2~6420 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1744157e80ed9b7fff78e4cfa14653274e08e795;p=graphviz "ps2ps" imageloader remove usershape entrypoint to renderer now that all renderers use loadimage --- diff --git a/lib/common/psgen.c b/lib/common/psgen.c index 55c1b9c3f..ed8bef83a 100644 --- a/lib/common/psgen.c +++ b/lib/common/psgen.c @@ -35,7 +35,7 @@ #include extern void epsf_define(FILE * of); -void epsf_emit_body(ps_image_t *img, FILE *of); +extern void epsf_emit_body(ps_image_t *img, FILE *of); extern void ps_freeusershapes(void); extern ps_image_t *ps_usershape_to_image(char *shapeimagefile); diff --git a/lib/common/render.h b/lib/common/render.h index 5bcb7aaf0..ec6772d8d 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -48,8 +48,8 @@ extern "C" { #include "memory.h" #include "colorprocs.h" /* must collow color.h (in types.h) */ #include "geomprocs.h" /* must follow geom.h (in types.h) */ -#include "graph.h" /* must follow types.h */ #include "agxbuf.h" +#include "graph.h" /* must follow types.h */ #include "utils.h" /* must follow types.h and agxbuf.h */ #include "gvplugin.h" /* must follow gvcext.h (in types.h) */ #include "gvcjob.h" /* must follow gvcext.h (in types.h) */ @@ -61,16 +61,6 @@ extern "C" { point offset; } epsf_t; - typedef struct { - Dtlink_t link; - char *name; - int macro_id; - point size; - point origin; - char *contents; - int must_inline; - } ps_image_t; - typedef void (*nodesizefn_t) (Agnode_t *, bool); extern void add_box(path *, box); diff --git a/lib/common/types.h b/lib/common/types.h index a15414704..43b0e84b9 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -21,6 +21,7 @@ #include #include +#include "cdt.h" #include "geom.h" #include "pathplan.h" #include "color.h" @@ -591,6 +592,16 @@ extern "C" { int flags; } gvlayout_features_t; + typedef struct { + Dtlink_t link; + char *name; + int macro_id; + point size; + point origin; + char *contents; + int must_inline; + } ps_image_t; + #ifdef __cplusplus } #endif diff --git a/lib/gvc/gvplugin_render.h b/lib/gvc/gvplugin_render.h index 1e7c43d89..b126995d8 100644 --- a/lib/gvc/gvplugin_render.h +++ b/lib/gvc/gvplugin_render.h @@ -56,7 +56,6 @@ extern "C" { int arrow_at_start, int arrow_at_end, int); void (*polyline) (GVJ_t * job, pointf * A, int n); void (*comment) (GVJ_t * job, char *comment); - void (*usershape) (GVJ_t * job, usershape_t *us, boxf b, bool filled); }; #ifdef __cplusplus diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index cc9fda19c..ce5550d38 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -276,8 +276,10 @@ void gvrender_end_job(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_job) - gvre->end_job(job); + if (gvre) { + if (gvre->end_job) + gvre->end_job(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -448,8 +450,10 @@ void gvrender_end_graph(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_graph) - gvre->end_graph(job); + if (gvre) { + if (gvre->end_graph) + gvre->end_graph(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -465,9 +469,10 @@ void gvrender_begin_page(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->begin_page) - gvre->begin_page(job); - + if (gvre) { + if (gvre->begin_page) + gvre->begin_page(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -485,8 +490,10 @@ void gvrender_end_page(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_page) - gvre->end_page(job); + if (gvre) { + if (gvre->end_page) + gvre->end_page(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -501,8 +508,10 @@ void gvrender_begin_layer(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->begin_layer) - gvre->begin_layer(job, job->gvc->layerIDs[job->layerNum], job->layerNum, job->numLayers); + if (gvre) { + if (gvre->begin_layer) + gvre->begin_layer(job, job->gvc->layerIDs[job->layerNum], job->layerNum, job->numLayers); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -517,8 +526,10 @@ void gvrender_end_layer(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_layer) - gvre->end_layer(job); + if (gvre) { + if (gvre->end_layer) + gvre->end_layer(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -586,8 +597,10 @@ void gvrender_begin_cluster(GVJ_t * job, graph_t * sg) obj->url_map_n = nump; } - if (gvre && gvre->begin_cluster) - gvre->begin_cluster(job); + if (gvre) { + if (gvre->begin_cluster) + gvre->begin_cluster(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -603,8 +616,10 @@ void gvrender_end_cluster(GVJ_t * job, graph_t *g) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_cluster) - gvre->end_cluster(job); + if (gvre) { + if (gvre->end_cluster) + gvre->end_cluster(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -621,8 +636,10 @@ void gvrender_begin_nodes(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->begin_nodes) - gvre->begin_nodes(job); + if (gvre) { + if (gvre->begin_nodes) + gvre->begin_nodes(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -637,8 +654,10 @@ void gvrender_end_nodes(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_nodes) - gvre->end_nodes(job); + if (gvre) { + if (gvre->end_nodes) + gvre->end_nodes(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -653,8 +672,10 @@ void gvrender_begin_edges(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->begin_edges) - gvre->begin_edges(job); + if (gvre) { + if (gvre->begin_edges) + gvre->begin_edges(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -669,8 +690,10 @@ void gvrender_end_edges(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_edges) - gvre->end_edges(job); + if (gvre) { + if (gvre->end_edges) + gvre->end_edges(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -872,8 +895,10 @@ void gvrender_begin_node(GVJ_t * job, node_t * n) obj->url_map_n = nump; } - if (gvre && gvre->begin_node) - gvre->begin_node(job); + if (gvre) { + if (gvre->begin_node) + gvre->begin_node(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -889,8 +914,10 @@ void gvrender_end_node(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_node) - gvre->end_node(job); + if (gvre) { + if (gvre->end_node) + gvre->end_node(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -1285,8 +1312,10 @@ void gvrender_begin_edge(GVJ_t * job, edge_t * e) obj->url_bsplinemap_p = pbs; } - if (gvre && gvre->begin_edge) - gvre->begin_edge(job); + if (gvre) { + if (gvre->begin_edge) + gvre->begin_edge(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -1302,8 +1331,10 @@ void gvrender_end_edge(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_edge) - gvre->end_edge(job); + if (gvre) { + if (gvre->end_edge) + gvre->end_edge(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -1362,8 +1393,10 @@ void gvrender_begin_anchor(GVJ_t * job, char *href, char *tooltip, { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->begin_anchor) - gvre->begin_anchor(job, href, tooltip, target); + if (gvre) { + if (gvre->begin_anchor) + gvre->begin_anchor(job, href, tooltip, target); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -1378,8 +1411,10 @@ void gvrender_end_anchor(GVJ_t * job) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->end_anchor) - gvre->end_anchor(job); + if (gvre) { + if (gvre->end_anchor) + gvre->end_anchor(job); + } #ifdef WITH_CODEGENS else { codegen_t *cg = job->codegen; @@ -1418,10 +1453,9 @@ void gvrender_textpara(GVJ_t * job, pointf p, textpara_t * para) PF = p; else PF = gvrender_ptf(job, p); - if (gvre && gvre->textpara) { - if (job->style->pen != PEN_NONE) { + if (gvre) { + if (gvre->textpara && job->style->pen != PEN_NONE) gvre->textpara(job, PF, para); - } } #ifdef WITH_CODEGENS else { @@ -1525,8 +1559,8 @@ void gvrender_ellipse(GVJ_t * job, pointf pf, double rx, double ry, bool filled) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->ellipse) { - if (job->style->pen != PEN_NONE) { + if (gvre) { + if (gvre->ellipse && job->style->pen != PEN_NONE) { pointf af[2]; /* center */ @@ -1558,8 +1592,8 @@ void gvrender_polygon(GVJ_t * job, pointf * af, int n, bool filled) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->polygon) { - if (job->style->pen != PEN_NONE) { + if (gvre) { + if (gvre->polygon && job->style->pen != PEN_NONE) { if (job->flags & GVRENDER_DOES_TRANSFORM) gvre->polygon(job, af, n, filled); else { @@ -1608,8 +1642,8 @@ void gvrender_beziercurve(GVJ_t * job, pointf * af, int n, { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->beziercurve) { - if (job->style->pen != PEN_NONE) { + if (gvre) { + if (gvre->beziercurve && job->style->pen != PEN_NONE) { if (job->flags & GVRENDER_DOES_TRANSFORM) gvre->beziercurve(job, af, n, arrow_at_start, arrow_at_end,filled); else { @@ -1643,8 +1677,8 @@ void gvrender_polyline(GVJ_t * job, pointf * af, int n) { gvrender_engine_t *gvre = job->render.engine; - if (gvre && gvre->polyline) { - if (job->style->pen != PEN_NONE) { + if (gvre) { + if (gvre->polyline && job->style->pen != PEN_NONE) { if (job->flags & GVRENDER_DOES_TRANSFORM) gvre->polyline(job, af, n); else { @@ -1681,8 +1715,9 @@ void gvrender_comment(GVJ_t * job, char *str) if (!str || !str[0]) return; - if (gvre && gvre->comment) { - gvre->comment(job, str); + if (gvre) { + if (gvre->comment) + gvre->comment(job, str); } #ifdef WITH_CODEGENS else { @@ -1750,9 +1785,7 @@ void gvrender_usershape(GVJ_t * job, char *name, pointf * a, int n, bool filled) } if (gvre) { - if (gvre->usershape) - gvre->usershape(job, us, b, filled); - else if (job->render.features->loadimage_target) + if (job->render.features->loadimage_target) gvloadimage(job, us, b, filled, job->render.features->loadimage_target); } #ifdef WITH_CODEGENS diff --git a/plugin/core/gvloadimage_core.c b/plugin/core/gvloadimage_core.c index 92a8e72c9..b85b5246d 100644 --- a/plugin/core/gvloadimage_core.c +++ b/plugin/core/gvloadimage_core.c @@ -22,6 +22,12 @@ #include "gvplugin_loadimage.h" +/* for ps_image_t */ +#include "types.h" + +/* for ND_coord_i */ +#include "graph.h" + extern void svggen_fputs(GVJ_t * job, char *s); extern void svggen_printf(GVJ_t * job, const char *format, ...); @@ -49,9 +55,58 @@ static void core_loadimage_svg(GVJ_t * job, usershape_t *us, boxf b, bool filled } } +static void ps_freeimage(void *data) +{ + free (data); +} + +extern void epsf_emit_body(ps_image_t *img, FILE *of); +extern ps_image_t *ps_usershape_to_image(char *shapeimagefile); + +/* usershape described by a postscript function */ static void core_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, bool filled) { - if (us->name) { + obj_state_t *obj = job->obj; + ps_image_t *img = NULL; + point offset; + + if (us->data) { + if (us->datafree == ps_freeimage) { + img = (ps_image_t *)(us->data); /* use cached data */ + } + else { + us->datafree(us->data); /* free incompatible cache data */ + us->data = NULL; + } + } + + if (!img) { /* read file into cache */ + fseek(us->f, 0, SEEK_SET); + switch (us->type) { + case FT_PS: + case FT_EPS: + img = ps_usershape_to_image(us->name); + break; + default: + break; + } + if (img) { + us->data = (void*)img; + us->datafree = ps_freeimage; + } + } + + if (img) { + offset.x = -(img->origin.x) - (img->size.x) / 2; + offset.y = -(img->origin.y) - (img->size.y) / 2; + fprintf(job->output_file, "gsave %d %d translate newpath\n", + ND_coord_i(obj->n).x + offset.x, + ND_coord_i(obj->n).y + offset.y); + if (img->must_inline) + epsf_emit_body(img, job->output_file); + else + fprintf(job->output_file, "user_shape_%d\n", img->macro_id); + fprintf(job->output_file, "grestore\n"); } } diff --git a/plugin/core/gvrender_core_map.c b/plugin/core/gvrender_core_map.c index c012e7372..c206298b9 100644 --- a/plugin/core/gvrender_core_map.c +++ b/plugin/core/gvrender_core_map.c @@ -167,7 +167,6 @@ static gvrender_engine_t mapgen_engine = { 0, /* mapgen_bezier */ 0, /* mapgen_polyline */ 0, /* mapgen_comment */ - 0 /* mapgen_usershape */ }; static gvrender_features_t mapgen_features_poly = { diff --git a/plugin/core/gvrender_core_ps.c b/plugin/core/gvrender_core_ps.c index 6b233b784..9d9d60e98 100644 --- a/plugin/core/gvrender_core_ps.c +++ b/plugin/core/gvrender_core_ps.c @@ -444,95 +444,6 @@ static void psgen_comment(GVJ_t * job, char *str) fprintf(job->output_file, "%% %s\n", str); } -#if 0 -static void ps_freeimage_ps (void *data) -{ -// free (data); -} - -/* ps_usershape: - * Images for postscript are complicated by the old epsf shape, as - * well as user-defined shapes using postscript code. - * If the name is custom, we look for the image stored in the - * current node's shapefile attribute. - * Else we see if name is a user-defined postscript function - * Else we assume name is the name of the image. This occurs when - * the image is part of an html label. - */ -static void -psgen_usershape(GVJ_t * job, usershape_t *us, boxf b, bool filled) -{ - int j; - ps_image_t *ps_img = NULL; - point offset; - - if (!us->f) { - if (find_user_shape(us->name)) { - if (filled) { - ps_begin_context(); - ps_set_color(S[SP].fillcolor); - fprintf(job->output_file, "[ "); - for (j = 0; j < n; j++) - fprintf(job->output_file, "%d %d ", A[j].x, A[j].y); - fprintf(job->output_file, "%d %d ", A[0].x, A[0].y); - fprintf(job->output_file, "] %d true %s\n", n, us->name); - ps_end_context(); - } - fprintf(job->output_file, "[ "); - for (j = 0; j < n; j++) - fprintf(job->output_file, "%d %d ", A[j].x, A[j].y); - fprintf(job->output_file, "%d %d ", A[0].x, A[0].y); - fprintf(job->output_file, "] %d false %s\n", n, us->name); - } - else { /* name not find by find_ser_shape */ } - return; - } - - if (us->data) { - if (us->datafree == ps_freeimage_ps) { - ps_img = (ps_image_t *)(us->data); /* use cached data */ - } - else { - us->datafree(us->data); /* free incompatible cache data */ - us->data = NULL; - } - } - - if (!ps_img) { /* read file into cache */ - fseek(us->f, 0, SEEK_SET); - switch (us->type) { - case FT_PS: - case FT_EPS: - ps_img = ps_usershape_to_image(us->name); - break; - default: - break; - } - if (ps_img) { - us->data = (void*)ps_img; - us->datafree = ps_freeimage_ps; - } - } - if (ps_img) { - ps_begin_context(); - offset.x = -ps_img->origin.x - (ps_img->size.x) / 2; - offset.y = -ps_img->origin.y - (ps_img->size.y) / 2; - fprintf(job->output_file, "%d %d translate newpath\n", - ND_coord_i(Curnode).x + offset.x, - ND_coord_i(Curnode).y + offset.y); - if (ps_img->must_inline) - epsf_emit_body(ps_img, job->output_file); - else - fprintf(job->output_file, "user_shape_%d\n", ps_img->macro_id); - ps_end_context(); - return; - } - - /* some other type of image */ - job->common->errorfn("usershape %s is not supported in PostScript output\n", us->name); -} -#endif - static gvrender_engine_t psgen_engine = { psgen_begin_job, psgen_end_job, @@ -561,7 +472,6 @@ static gvrender_engine_t psgen_engine = { psgen_bezier, psgen_polyline, psgen_comment, - 0, /* psgen_usershape */ }; static gvrender_features_t psgen_features = { diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index 063c1d4c6..9ebc88db6 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -552,7 +552,6 @@ gvrender_engine_t svggen_engine = { svggen_bezier, svggen_polyline, svggen_comment, - 0 /* svggen_usershape */ /* usershapes provided by gvloadimage */ }; gvrender_features_t svggen_features = { diff --git a/plugin/gd/gvrender_gd.c b/plugin/gd/gvrender_gd.c index 5ba37f7d4..c0a986778 100644 --- a/plugin/gd/gvrender_gd.c +++ b/plugin/gd/gvrender_gd.c @@ -702,7 +702,6 @@ static gvrender_engine_t gdgen_engine = { gdgen_bezier, gdgen_polyline, 0, /* gdgen_comment */ - 0 /* gdgen_usershape */ /* provided by gvloadimage */ }; static gvrender_features_t gdgen_features_tc = { diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index 6b4abb8ef..597a331e8 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -406,7 +406,6 @@ static gvrender_engine_t cairogen_engine = { cairogen_bezier, cairogen_polyline, 0, /* cairogen_comment */ - 0 /* cairogen_usershape */ /* provided by gvloadimage */ }; static gvrender_features_t cairogen_features = {