]> granicus.if.org Git - graphviz/commitdiff
add gvLayout() gvRender() gvCleanup() wrappers and provide new simple.c demo
authorellson <devnull@localhost>
Tue, 19 Jul 2005 17:12:53 +0000 (17:12 +0000)
committerellson <devnull@localhost>
Tue, 19 Jul 2005 17:12:53 +0000 (17:12 +0000)
cmd/dot/dotneato.c
cmd/dot/dotneato.h
dot.demo/Makefile
dot.demo/simple.c [new file with mode: 0644]

index ea1c210fa38ad1daee24844dfe632756bd1da71c..402de0ff4df47c069db177d8da953a13851a21de 100644 (file)
@@ -24,5 +24,85 @@ char *Info[] = {
 
 GVC_t *gvContext(void)
 {
-    return gvNEWcontext(Info, "");
+    GVC_t *gvc;
+
+    aginit();
+    agnodeattr(NULL, "label", NODENAME_ESC);
+    gvc = gvNEWcontext(Info, username());
+    gvconfig(gvc); /* configure for available plugins and codegens */
+    return gvc;
+}
+
+int gvLayout(GVC_t *gvc, graph_t *g, char *engine)
+{
+    char buf[256];
+    Agsym_t *a;
+    int rc;
+
+    g = g->root;
+    if (GD_drawing(g)) {        /* only cleanup once between layouts */
+        gvlayout_cleanup(gvc, g);
+        GD_drawing(g) = NULL;
+    }
+    rc = gvlayout_select(gvc, engine);
+    if (rc == NO_SUPPORT) {
+        fprintf(stderr, "Layout type: \"%s\" not recognized. Use one of:%s\n",
+                engine, gvplugin_list(gvc, API_layout, engine));
+        return -1;
+    }
+
+    gvlayout_layout(gvc, g);
+
+/* set bb attribute for basic layout.
+ * doesn't yet include margins, scaling or page sizes because
+ * those depend on the renderer being used. */
+    if (GD_drawing(g)->landscape)
+        sprintf(buf, "%d %d %d %d",
+                ROUND(GD_bb(g).LL.y), ROUND(GD_bb(g).LL.x),
+                ROUND(GD_bb(g).UR.y), ROUND(GD_bb(g).UR.x));
+    else
+        sprintf(buf, "%d %d %d %d",
+                ROUND(GD_bb(g).LL.x), ROUND(GD_bb(g).LL.y),
+                ROUND(GD_bb(g).UR.x), ROUND(GD_bb(g).UR.y));
+    if (!(a = agfindattr(g, "bb"))) {
+        a = agraphattr(g, "bb", "");
+    }
+    agxset(g, a->index, buf);
+
+    return 0;
+}
+
+int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out)
+{
+    int rc;
+    GVJ_t *job;
+
+    g = g->root;
+
+    /* create a job for the required format */
+    rc = gvrender_output_langname_job(gvc, format);
+    if (rc == NO_SUPPORT) {
+        fprintf(stderr, "Renderer type: \"%s\" not recognized. Use one of:%s\n",
+                format, gvplugin_list(gvc, API_render, format));
+        return -1;
+    }
+
+    job = gvc->job;
+    job->output_lang = gvrender_select(job, job->output_langname);
+    if (!GD_drawing(g) && job->output_lang != CANONICAL_DOT) {
+        fprintf(stderr, "Layout was not done\n");
+        return -1;
+    }
+    job->output_file = out;
+
+    emit_jobs(gvc, g);
+    gvrender_delete_jobs(gvc);
+
+    return 0;
+}
+
+
+void gvCleanup(GVC_t *gvc)
+{
+    gvFREEcontext(gvc);
 }
index df5b1abe43575f0147c178c5d8c6ee0df2705795..c8a344f57950ac6c687379b13d6a67007ee42d2a 100644 (file)
@@ -25,6 +25,9 @@ extern "C" {
 #endif
 
 extern GVC_t *gvContext(void);
+extern int gvLayout(GVC_t *gvc, graph_t *g, char *engine);
+extern int gvRender(GVC_t *gvc, graph_t *g, char *format, FILE *out);
+extern void gvCleanup(GVC_t *gvc);
 
 #ifdef __cplusplus
 }
index 6f83caf0379346adef020518b87ab295b2b25c86..1d288ca7290004f01dec9d4de9d6ec4fb2a4b366 100644 (file)
@@ -4,7 +4,7 @@ LINK=libtool --tag=CC --mode=link ${CC}
 CFLAGS=`pkg-config libdotneato --cflags`
 LDFLAGS=`pkg-config libdotneato --libs`
 
-all: dot demo
+all: dot demo simple
 
 dot: dot.lo
        ${LINK} ${LDFLAGS} -o $@ dot.lo
@@ -18,5 +18,11 @@ demo: demo.lo
 demo.lo: demo.c
        ${COMPILE} ${CFLAGS} -o $@ demo.c
 
+simple: simple.lo
+       ${LINK} ${LDFLAGS} -o $@ simple.lo
+
+simple.lo: simple.c
+       ${COMPILE} ${CFLAGS} -o $@ simple.c
+
 clean:
-       rm -rf .libs dot demo *.o *.lo
+       rm -rf .libs dot demo simple *.o *.lo
diff --git a/dot.demo/simple.c b/dot.demo/simple.c
new file mode 100644 (file)
index 0000000..0d4ba28
--- /dev/null
@@ -0,0 +1,42 @@
+/* $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             *
+**********************************************************/
+
+#include <dotneato.h>
+
+int main(int argc, char **argv)
+{
+    GVC_t *gvc;
+    graph_t *g;
+    FILE *fp;
+
+    gvc = gvContext();
+
+    if (argc > 1)
+       fp = fopen(argv[1], "r");
+    else
+       fp = stdin;
+    g = agread(fp);
+
+    gvLayout(gvc, g, "dot");
+
+    gvRender(gvc, g, "plain", stdout);
+
+    gvCleanup(gvc);
+
+    agclose(g);
+    
+    return 0;
+}