]> granicus.if.org Git - graphviz/commitdiff
"ps2ps" imageloader
authorellson <devnull@localhost>
Sat, 17 Jun 2006 19:47:15 +0000 (19:47 +0000)
committerellson <devnull@localhost>
Sat, 17 Jun 2006 19:47:15 +0000 (19:47 +0000)
remove usershape entrypoint to renderer now that all renderers use loadimage

lib/common/psgen.c
lib/common/render.h
lib/common/types.h
lib/gvc/gvplugin_render.h
lib/gvc/gvrender.c
plugin/core/gvloadimage_core.c
plugin/core/gvrender_core_map.c
plugin/core/gvrender_core_ps.c
plugin/core/gvrender_core_svg.c
plugin/gd/gvrender_gd.c
plugin/pango/gvrender_pango.c

index 55c1b9c3f3d03c872ac64fa58c3ceec62f1ff000..ed8bef83af0631347544748e0b6665364d6b0442 100644 (file)
@@ -35,7 +35,7 @@
 #include <sys/stat.h>
 
 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);
 
index 5bcb7aaf00cc9ba18c9a03b5fc00dfa552a790c3..ec6772d8d040b864e1a2acc4a7d7efb71235ae36 100644 (file)
@@ -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);
index a154147041b6365c5191dde8fd184569bdc1209b..43b0e84b94d7a8c27233f02c3f23b562c8bcd375 100644 (file)
@@ -21,6 +21,7 @@
 #include <assert.h>
 #include <signal.h>
 
+#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
index 1e7c43d89ec41f40e5dfe635bbec27a5921587e6..b126995d866a98ae8447d6467b8629568f2d856e 100644 (file)
@@ -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
index cc9fda19c6b2ad3a565b8833d3ab2942e0defbbb..ce5550d38991475f34b380dcd4642cb50d5e921e 100644 (file)
@@ -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
index 92a8e72c9ec4c02f734c89ccde8c7b52e5ccb432..b85b5246dadd294d6c59ec04cb598ef4caf87fea 100644 (file)
 
 #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");
     }
 }
 
index c012e7372d7eb3434a92ab3448865a0573b94bf2..c206298b9feef6c5a0b5cf6b10748e662a50002e 100644 (file)
@@ -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 = {
index 6b233b7841ab65dd3ff1a3bf838581201ff15381..9d9d60e98b1009eb1b7803723c0f4334bc767fee 100644 (file)
@@ -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 = {
index 063c1d4c61541d70d091240fae72e32a1a737d65..9ebc88db613a83b6eb3d4ca91a85d3f69c1b7a6f 100644 (file)
@@ -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 = {
index 5ba37f7d4731b927e51ae05e1f3dfd886a039154..c0a9867789564a2e9253b54664bfda6bbf2a62d1 100644 (file)
@@ -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 = {
index 6b4abb8ef884ab243cc9dfb4b97aa02b4933f53d..597a331e8664db490976289f6656508499e60dcb 100644 (file)
@@ -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 = {