/* Render layout in a specified format to an open FILE */ int gvRender(GVC_t *gvc, graph_t *g, const char *format, FILE *out) { 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 (!LAYOUT_DONE(g) && !(job->flags & LAYOUT_NOT_REQUIRED)) { agerrorf( "Layout was not done\n"); return -1; } job->output_file = out; if (out == NULL) job->flags |= OUTPUT_NOT_REQUIRED; rc = gvRenderJobs(gvc, g); gvrender_end_job(job); gvjobs_delete(gvc); return rc; }
int gvFreeContext(GVC_t * gvc) { GVG_t *gvg, *gvg_next; gvplugin_package_t *package, *package_next; emit_once_reset(); gvg_next = gvc->gvgs; while ((gvg = gvg_next)) { gvg_next = gvg->next; free(gvg); } package_next = gvc->packages; while ((package = package_next)) { package_next = package->next; free(package->path); free(package->name); free(package); } gvjobs_delete(gvc); if (gvc->config_path) free(gvc->config_path); if (gvc->input_filenames) free(gvc->input_filenames); free(gvc); return (graphviz_errors + agerrors()); }
/* 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) { 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 (!LAYOUT_DONE(g) && !(job->flags & LAYOUT_NOT_REQUIRED)) { agerrorf( "Layout was not done\n"); return -1; } /* page size on Linux, Mac OS X and Windows */ #define OUTPUT_DATA_INITIAL_ALLOCATION 4096 if(!result || !(*result = malloc(OUTPUT_DATA_INITIAL_ALLOCATION))) { agerr(AGERR, "failure malloc'ing for result string"); return -1; } job->output_data = *result; job->output_data_allocated = OUTPUT_DATA_INITIAL_ALLOCATION; job->output_data_position = 0; rc = gvRenderJobs(gvc, g); gvrender_end_job(job); if (rc == 0) { *result = job->output_data; *length = job->output_data_position; } gvjobs_delete(gvc); return rc; }