#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);
#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) */
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);
#include <assert.h>
#include <signal.h>
+#include "cdt.h"
#include "geom.h"
#include "pathplan.h"
#include "color.h"
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
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
{
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;
{
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;
{
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;
{
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;
{
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;
{
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;
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;
{
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;
{
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;
{
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;
{
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;
{
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;
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;
{
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;
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;
{
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;
{
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;
{
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;
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 {
{
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 */
{
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 {
{
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 {
{
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 {
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 {
}
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
#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, ...);
}
}
+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");
}
}
0, /* mapgen_bezier */
0, /* mapgen_polyline */
0, /* mapgen_comment */
- 0 /* mapgen_usershape */
};
static gvrender_features_t mapgen_features_poly = {
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,
psgen_bezier,
psgen_polyline,
psgen_comment,
- 0, /* psgen_usershape */
};
static gvrender_features_t psgen_features = {
svggen_bezier,
svggen_polyline,
svggen_comment,
- 0 /* svggen_usershape */ /* usershapes provided by gvloadimage */
};
gvrender_features_t svggen_features = {
gdgen_bezier,
gdgen_polyline,
0, /* gdgen_comment */
- 0 /* gdgen_usershape */ /* provided by gvloadimage */
};
static gvrender_features_t gdgen_features_tc = {
cairogen_bezier,
cairogen_polyline,
0, /* cairogen_comment */
- 0 /* cairogen_usershape */ /* provided by gvloadimage */
};
static gvrender_features_t cairogen_features = {