]> granicus.if.org Git - graphviz/commitdiff
-Tsvg usershape loading through loadimage plugin mechanism for extensibility
authorellson <devnull@localhost>
Sat, 17 Jun 2006 18:43:52 +0000 (18:43 +0000)
committerellson <devnull@localhost>
Sat, 17 Jun 2006 18:43:52 +0000 (18:43 +0000)
plugin/core/gvloadimage_core.c [new file with mode: 0644]
plugin/core/gvplugin_core.c
plugin/core/gvrender_core_svg.c

diff --git a/plugin/core/gvloadimage_core.c b/plugin/core/gvloadimage_core.c
new file mode 100644 (file)
index 0000000..92a8e72
--- /dev/null
@@ -0,0 +1,72 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2004 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "gvplugin_loadimage.h"
+
+extern void svggen_fputs(GVJ_t * job, char *s);
+extern void svggen_printf(GVJ_t * job, const char *format, ...);
+
+typedef enum {
+    FORMAT_PNG_SVG, FORMAT_GIF_SVG, FORMAT_JPEG_SVG,
+    FORMAT_PS_PS,
+} format_type;
+
+static void core_loadimage_svg(GVJ_t * job, usershape_t *us, boxf b, bool filled)
+{
+    if (us->name) {
+        svggen_fputs(job, "<image xlink:href=\"");
+        svggen_fputs(job, us->name);
+        if (job->rotation) {
+            svggen_printf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"",
+                b.UR.y - b.LL.y, b.UR.x - b.LL.x, b.LL.x, b.UR.y);
+            svggen_printf (job, " transform=\"rotate(%d %g %g)\"",
+                job->rotation, b.LL.x, b.UR.y);
+        }
+        else {
+            svggen_printf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"",
+                b.UR.x - b.LL.x, b.UR.y - b.LL.y, b.LL.x, b.LL.y);
+        }
+        svggen_fputs(job, "/>\n");
+    }
+}
+
+static void core_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, bool filled)
+{
+    if (us->name) {
+    }
+}
+
+static gvloadimage_engine_t engine_svg = {
+    core_loadimage_svg
+};
+
+static gvloadimage_engine_t engine_ps = {
+    core_loadimage_ps
+};
+
+gvplugin_installed_t gvloadimage_core_types[] = {
+    {FORMAT_PNG_SVG, "png2svg", 1, &engine_svg, NULL},
+    {FORMAT_GIF_SVG, "gif2svg", 1, &engine_svg, NULL},
+    {FORMAT_JPEG_SVG, "jpeg2svg", 1, &engine_svg, NULL},
+    {FORMAT_PS_PS, "ps2ps", 1, &engine_ps, NULL},
+    {0, NULL, 0, NULL, NULL}
+};
index 505bf6e4e501f6bc3065049b5c192d82f1689837..3958c593b5a3fa3e136bc359f38bbf782c7d325b 100644 (file)
 extern gvplugin_installed_t gvrender_core_ps_types;
 extern gvplugin_installed_t gvrender_core_svg_types;
 extern gvplugin_installed_t gvrender_core_map_types;
+extern gvplugin_installed_t gvloadimage_core_types;
 
 static gvplugin_api_t apis[] = {
     {API_render, &gvrender_core_ps_types},
     {API_render, &gvrender_core_svg_types},
     {API_render, &gvrender_core_map_types},
+    {API_loadimage, &gvloadimage_core_types},
     {(api_t)0, 0},
 };
 
index ae0048e580d43fbc8a702e31ae69fc34b2edfca6..063c1d4c61541d70d091240fae72e32a1a737d65 100644 (file)
@@ -44,7 +44,7 @@ static char *sdarray = "5,2";
 /* SVG dot array */
 static char *sdotarray = "1,5";
 
-static void svggen_fputs(GVJ_t * job, char *s)
+void svggen_fputs(GVJ_t * job, char *s)
 {
     int len;
 
@@ -68,7 +68,7 @@ static void svggen_fputs(GVJ_t * job, char *s)
  * input coming from users. Also, if vsnprintf is available, the
  * code should check for return values to use it safely.
  */
-static void svggen_printf(GVJ_t * job, const char *format, ...)
+void svggen_printf(GVJ_t * job, const char *format, ...)
 {
     char buf[BUFSIZ];
     va_list argp;
@@ -479,40 +479,6 @@ static void svggen_polyline(GVJ_t * job, pointf * A, int n)
     svggen_fputs(job, "\"/>\n");
 }
 
-static void
-svggen_usershape(GVJ_t * job, usershape_t *us, boxf b, bool filled)
-{
-    if (job->style->pen == PEN_NONE) {
-       /* its invisible, don't draw */
-       return;
-    }
-    if (! us->f) {
-        pointf A[4];
-        A[0] = b.LL;
-        A[2] = b.UR;
-        A[1].x = b.LL.x;
-        A[1].y = b.UR.y;
-        A[3].x = b.UR.x;
-        A[3].y = b.LL.y;
-        svggen_polygon(job, A, 4, filled);
-        return;
-    }
-
-    svggen_fputs(job, "<image xlink:href=\"");
-    svggen_fputs(job, us->name);
-    if (job->rotation) {
-        svggen_printf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"",
-                b.UR.y - b.LL.y, b.UR.x - b.LL.x, b.LL.x, b.UR.y);
-       svggen_printf (job, " transform=\"rotate(%d %g %g)\"",
-               job->rotation, b.LL.x, b.UR.y);
-    }
-    else {
-        svggen_printf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"",
-                b.UR.x - b.LL.x, b.UR.y - b.LL.y, b.LL.x, b.LL.y);
-    }
-    svggen_fputs(job, "/>\n");
-}
-
 /* color names from http://www.w3.org/TR/SVG/types.html */
 /* NB.  List must be LANG_C sorted */
 static char *svggen_knowncolors[] = {
@@ -586,7 +552,7 @@ gvrender_engine_t svggen_engine = {
     svggen_bezier,
     svggen_polyline,
     svggen_comment,
-    svggen_usershape
+    0                          /* svggen_usershape */ /* usershapes provided by gvloadimage */
 };
 
 gvrender_features_t svggen_features = {
@@ -598,7 +564,7 @@ gvrender_features_t svggen_features = {
     sizeof(svggen_knowncolors) / sizeof(char *),       /* sizeof knowncolors */
     RGBA_BYTE,                 /* color_type */
     NULL,                       /* device */
-    NULL,                       /* gvloadimage target for usershapes */
+    "svg",                      /* gvloadimage target for usershapes */
 };
 
 gvplugin_installed_t gvrender_core_svg_types[] = {