From 9a2751560ae0212a7791b7ea9693005548a9b3bc Mon Sep 17 00:00:00 2001 From: glenlow Date: Wed, 18 Feb 2009 12:36:32 +0000 Subject: [PATCH] gvRenderContext: render to an arbitrary external context --- lib/gvc/gvc.c | 35 +++++++++++++++++++++++++++++++++++ lib/gvc/gvc.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/lib/gvc/gvc.c b/lib/gvc/gvc.c index 23bbbcea2..e81e24d07 100644 --- a/lib/gvc/gvc.c +++ b/lib/gvc/gvc.c @@ -138,6 +138,41 @@ int gvRenderFilename(GVC_t *gvc, graph_t *g, const char *format, const char *fil return 0; } +/* Render layout in a specified format to an external context */ +int gvRenderContext(GVC_t *gvc, graph_t *g, const char *format, void *context) +{ + int rc; + GVJ_t *job; + + g = g->root; + + /* create a job for the required format */ + rc = gvjobs_output_langname(gvc, format); + job = gvc->job; + if (rc == NO_SUPPORT) { + agerr(AGERR, "Format: \"%s\" not recognized. Use one of:%s\n", + format, gvplugin_list(gvc, API_device, format)); + return -1; + } + + job->output_lang = gvrender_select(job, job->output_langname); + if (!GD_drawing(g) && !(job->flags & LAYOUT_NOT_REQUIRED)) { + fprintf(stderr, "Layout was not done\n"); + return -1; + } + + job->context = context; + job->external_context = TRUE; + + gvRenderJobs(gvc, g); + gvrender_end_job(job); + gvdevice_finalize(job); + + gvjobs_delete(gvc); + + return 0; +} + /* Render layout in a specified format to a malloc'ed string */ int gvRenderData(GVC_t *gvc, graph_t *g, const char *format, char **result, unsigned int *length) { diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 8ad4bdfbe..44a91f15f 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -80,6 +80,9 @@ extern int gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out); /* Render layout in a specified format to an open FILE */ extern int gvRenderFilename(GVC_t *gvc, graph_t *g, const char *format, const char *filename); +/* Render layout in a specified format to an external context */ +extern int gvRenderContext(GVC_t *gvc, graph_t *g, const char *format, void *context); + /* Render layout in a specified format to a malloc'ed string */ extern int gvRenderData(GVC_t *gvc, graph_t *g, const char *format, char **result, unsigned int *length); -- 2.40.0