From: ellson Date: Mon, 11 Jul 2005 22:57:33 +0000 (+0000) Subject: migrating usershape code to gvc/gvusershape.c X-Git-Tag: LAST_LIBGRAPH~32^2~7470 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=799ab591cdbc587285b88e3e8127397947d76e1f;p=graphviz migrating usershape code to gvc/gvusershape.c --- diff --git a/lib/common/gdusershape.c b/lib/common/gdusershape.c index ac02fb6d6..ff34d3858 100644 --- a/lib/common/gdusershape.c +++ b/lib/common/gdusershape.c @@ -138,8 +138,3 @@ point gd_image_size(graph_t * g, char *shapeimagefile) rv.x = rv.y = -1; return rv; } - -point gd_user_shape_size(node_t * n, char *shapeimagefile) -{ - return (gd_image_size(n->graph, shapeimagefile)); -} diff --git a/lib/common/psusershape.c b/lib/common/psusershape.c index 89a6ccb3c..610b1a0eb 100644 --- a/lib/common/psusershape.c +++ b/lib/common/psusershape.c @@ -214,11 +214,6 @@ point ps_image_size(graph_t * g, char *shapeimagefile) return rv; } -point ps_user_shape_size(node_t * n, char *shapeimagefile) -{ - return (ps_image_size(n->graph, shapeimagefile)); -} - void ps_freeusershapes(void) { if (EPSF_contents) { diff --git a/lib/common/renderprocs.h b/lib/common/renderprocs.h index 4b5f704a6..290858c1b 100644 --- a/lib/common/renderprocs.h +++ b/lib/common/renderprocs.h @@ -105,14 +105,6 @@ extern "C" { extern char *gd_alternate_fontlist(char *font); extern char *gd_textsize(textline_t * textline, char *fontname, double fontsz, char **fontpath); - extern point gd_user_shape_size(node_t * n, char *shapeimagefile); - extern point ps_user_shape_size(node_t * n, char *shapeimagefile); - extern point svg_user_shape_size(node_t * n, char *shapeimagefile); - extern point quartz_user_shape_size(node_t * n, char *shapeimagefile); - extern point gd_image_size(graph_t * n, char *shapeimagefile); - extern point ps_image_size(graph_t * n, char *shapeimagefile); - extern point svg_image_size(graph_t * n, char *shapeimagefile); - extern point quartz_image_size(graph_t * n, char *shapeimagefile); extern void getdouble(graph_t * g, char *name, double *result); extern splines *getsplinepoints(edge_t * e); extern void global_def(char *, @@ -184,7 +176,6 @@ extern "C" { extern void updateBB(graph_t * g, textlabel_t * lp); extern void use_library(char *); extern char *username(void); - extern point user_shape_size(node_t * n, char *shapefile); extern char* utf8ToLatin1 (char* ins); extern void write_attributed_dot(graph_t *g, FILE *f); extern void write_canonical_dot(graph_t *g, FILE *f); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 05e2317f5..76676679e 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -575,7 +575,7 @@ static void poly_init(node_t * n) point imagesize; char *sfile = agget(n, "shapefile"); - imagesize = user_shape_size(n, sfile); + imagesize = image_size(n->graph, sfile); if ((imagesize.x == -1) && (imagesize.y == -1)) { agerr(AGERR, "No or improper shapefile=\"%s\" for node \"%s\"\n", diff --git a/lib/common/svgusershape.c b/lib/common/svgusershape.c index a8f9b414a..fb4579a76 100644 --- a/lib/common/svgusershape.c +++ b/lib/common/svgusershape.c @@ -23,11 +23,3 @@ point svg_image_size(graph_t * g, char *shapeimagefile) rv.x = rv.y = 0; return rv; } - -point svg_user_shape_size(node_t * n, char *shapeimagefile) -{ - point rv; - - rv.x = rv.y = 0; - return rv; -} diff --git a/lib/common/utils.c b/lib/common/utils.c index 04f65a452..58457e5f1 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -1143,135 +1143,6 @@ box flip_rec_box(box b, point p) return rv; } -/* - * This routine extracts the usershape size from known filetypes, - * it does not check that the output renderer knows how to render - * this file type - * Returns the size required for the shape in points; - * returns (-1,-1) on error; - * returns (0,0) to indicate "don't care". For example, in - * postscript, a node can have a user-defined shape but no shapefile. - */ -point user_shape_size(node_t * n, char *shapefile) -{ - char *suffix; - point rv; - - /* no shape file, no shape size */ - if (!shapefile) { - rv.x = rv.y = -1; - return rv; - } - if (*shapefile == '\0') { - rv.x = rv.y = 0; - return rv; /* no shapefile; probably postscript custom */ - } - if (!strncasecmp(shapefile, "http://", 7)) { - rv.x = rv.y = 0; - return rv; /* punt on obvious web addresses */ - } - - suffix = strrchr(shapefile, '.'); - if (!suffix) - suffix = shapefile; - else - suffix++; - if (!strcasecmp(suffix, "wbmp") -#ifdef HAVE_GD_GIF - || !strcasecmp(suffix, "gif") -#endif -#ifdef HAVE_GD_JPEG - || !strcasecmp(suffix, "jpeg") || !strcasecmp(suffix, "jpg") -#endif -#ifdef HAVE_GD_PNG - || !strcasecmp(suffix, "png") -#endif -#ifdef HAVE_GD_XPM - || !strcasecmp(suffix, "xbm") -/* FIXME - is "xpm" also supported by gd for input ? */ -#endif - ) { - rv = gd_user_shape_size(n, shapefile); - } else -#ifdef QUARTZ_RENDER - if (Output_lang == QPDF || Output_lang == QEPDF || - (Output_lang >= QBM_FIRST && Output_lang <= QBM_LAST)) - return quartz_user_shape_size(n, shapefile); - else -#endif - if (!strcasecmp(suffix, "ps") || !strncasecmp(suffix, "eps", 3) || - !strcasecmp(suffix, "epi")) { - rv = ps_user_shape_size(n, shapefile); - } else if (!strcasecmp(suffix, "svg")) { - rv = svg_user_shape_size(n, shapefile); - } else { - agerr(AGERR, "shapefile \"%s\" suffix not recognized\n", - shapefile); - rv.x = rv.y = 0; - } - return rv; -} - -point image_size(graph_t * g, char *shapefile) -{ - char *suffix; - point rv; - - /* no shape file, no shape size */ - if (!shapefile) { - rv.x = rv.y = -1; - return rv; - } - if (*shapefile == '\0') { - rv.x = rv.y = 0; - return rv; /* no shapefile; probably postscript custom */ - } - if (!strncasecmp(shapefile, "http://", 7)) { - rv.x = rv.y = 0; - return rv; /* punt on obvious web addresses */ - } - - suffix = strrchr(shapefile, '.'); - if (!suffix) - suffix = shapefile; - else - suffix++; - if (!strcasecmp(suffix, "wbmp") -#ifdef HAVE_GD_GIF - || !strcasecmp(suffix, "gif") -#endif -#ifdef HAVE_GD_JPEG - || !strcasecmp(suffix, "jpeg") || !strcasecmp(suffix, "jpg") -#endif -#ifdef HAVE_GD_PNG - || !strcasecmp(suffix, "png") -#endif -#ifdef HAVE_GD_XPM - || !strcasecmp(suffix, "xbm") -/* FIXME - is "xpm" also supported by gd for input ? */ -#endif - ) { - rv = gd_image_size(g, shapefile); - } else -#ifdef QUARTZ_RENDER - if (Output_lang == QPDF || Output_lang == QEPDF || - (Output_lang >= QBM_FIRST && Output_lang <= QBM_LAST)) - return quartz_image_size(g, shapefile); - else -#endif - - if (!strcasecmp(suffix, "ps")) { - rv = ps_image_size(g, shapefile); - } else if (!strcasecmp(suffix, "svg")) { - rv = svg_image_size(g, shapefile); - } else { - agerr(AGERR, "shapefile \"%s\" suffix not recognized\n", - shapefile); - rv.x = rv.y = -1; - } - return rv; -} - /* addLabelBB: */ static box addLabelBB(box bb, textlabel_t * lp) diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index fe04f051e..9a703bfba 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -68,8 +68,8 @@ extern "C" { extern int gvusershape_select(GVC_t * gvc, char *name); extern void * gvusershape_getshape(GVC_t * gvc, char *usershape); - extern void gvusershape_freeeshapes(GVC_t * gvc); - extern point gvusershape_imagesize(GVC_t * gvc, char *usershape); + extern void gvusershape_freeshapes(GVC_t * gvc); + extern point gvusershape_size(GVC_t * gvc, char *usershape); /* device */ diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index 064658163..33a4d675b 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -22,15 +22,35 @@ #include "config.h" #endif +#ifdef HAVE_STRINGS_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifndef HAVE_STRCASECMP + extern int strcasecmp(const char *s1, const char *s2); +#endif +#ifndef HAVE_STRNCASECMP + extern int strncasecmp(const char *s1, const char *s2, unsigned int n); +#endif + #include #include "const.h" #include "types.h" #include "macros.h" +#include "cdt.h" +#include "graph.h" #include "gvplugin_usershape.h" #include "gvc.h" +extern point gd_image_size(graph_t * g, char *shapeimagefile); +extern point ps_image_size(graph_t * g, char *shapeimagefile); +extern point svg_image_size(graph_t * g, char *shapeimagefile); +extern point quartz_image_size(graph_t * g, char *shapeimagefile); + int gvusershape_select(GVC_t * gvc, char *usershape) { gvplugin_available_t *plugin; @@ -44,3 +64,73 @@ int gvusershape_select(GVC_t * gvc, char *usershape) } return NO_SUPPORT; } + +/* + * This routine extracts the usershape size from known filetypes, + * it does not check that the output renderer knows how to render + * this file type + * Returns the size required for the shape in points; + * returns (-1,-1) on error; + * returns (0,0) to indicate "don't care". For example, in + * postscript, a node can have a user-defined shape but no shapefile. + */ +point image_size(graph_t * g, char *shapefile) +{ + char *suffix; + point rv; + + /* no shape file, no shape size */ + if (!shapefile) { + rv.x = rv.y = -1; + return rv; + } + if (*shapefile == '\0') { + rv.x = rv.y = 0; + return rv; /* no shapefile; probably postscript custom */ + } + if (!strncasecmp(shapefile, "http://", 7)) { + rv.x = rv.y = 0; + return rv; /* punt on obvious web addresses */ + } + + suffix = strrchr(shapefile, '.'); + if (!suffix) + suffix = shapefile; + else + suffix++; + if (!strcasecmp(suffix, "wbmp") +#ifdef HAVE_GD_GIF + || !strcasecmp(suffix, "gif") +#endif +#ifdef HAVE_GD_JPEG + || !strcasecmp(suffix, "jpeg") || !strcasecmp(suffix, "jpg") +#endif +#ifdef HAVE_GD_PNG + || !strcasecmp(suffix, "png") +#endif +#ifdef HAVE_GD_XPM + || !strcasecmp(suffix, "xbm") +/* FIXME - is "xpm" also supported by gd for input ? */ +#endif + ) { + rv = gd_image_size(g, shapefile); + } else +#ifdef QUARTZ_RENDER + if (Output_lang == QPDF || Output_lang == QEPDF || + (Output_lang >= QBM_FIRST && Output_lang <= QBM_LAST)) + return quartz_image_size(g, shapefile); + else +#endif + + if (!strcasecmp(suffix, "ps")) { + rv = ps_image_size(g, shapefile); + } else if (!strcasecmp(suffix, "svg")) { + rv = svg_image_size(g, shapefile); + } else { + agerr(AGERR, "shapefile \"%s\" suffix not recognized\n", + shapefile); + rv.x = rv.y = -1; + } + return rv; +} +