From: ellson Date: Tue, 21 Jun 2005 19:49:11 +0000 (+0000) Subject: split output "device" plugin from renderer plugin so that we can use X-Git-Tag: LAST_LIBGRAPH~32^2~7509 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5fb382d972960dca1f25dd1de506fb90ae502803;p=graphviz split output "device" plugin from renderer plugin so that we can use cairo for png output without loading x11 --- diff --git a/lib/common/emit.c b/lib/common/emit.c index eab23b82e..6e10e3989 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1337,6 +1337,7 @@ void emit_jobs_eof(GVC_t * gvc) if (job->output_file) { if (gvc->viewNum > 0) { gvrender_end_job(job); + gvdevice_end_job(job); emit_once_reset(); gvc->viewNum = 0; } @@ -1614,6 +1615,7 @@ static void emit_job(GVJ_t * job, graph_t * g) init_job_viewport(job, g); init_job_pagination(job, g); + gvdevice_begin_job(job); gvrender_begin_job(job); switch (job->output_lang) { @@ -1773,12 +1775,12 @@ void emit_jobs (GVC_t * gvc, graph_t * g) if (gvc->active_jobs && strcmp(job->output_langname,gvc->active_jobs->output_langname) != 0) { /* finalize previous jobs */ - gvrender_finalize(gvc); + gvdevice_finalize(gvc); /* clear active list */ gvc->active_jobs = NULL; } if (! gvc->active_jobs) - gvrender_initialize(gvc); + gvdevice_initialize(gvc); /* insert job in active list */ job->next_active = gvc->active_jobs; diff --git a/lib/common/input.c b/lib/common/input.c index 49e2091d2..9e020cef6 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -746,7 +746,7 @@ void do_graph_label(graph_t * sg) void dotneato_terminate(GVC_t * gvc) { if (gvc->active_jobs) - gvrender_finalize(gvc); + gvdevice_finalize(gvc); emit_jobs_eof(gvc); exit(graphviz_errors + agerrors()); } diff --git a/lib/common/types.h b/lib/common/types.h index ebf837e87..92cf01370 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -35,10 +35,10 @@ extern "C" { typedef struct GVC_s GVC_t; typedef struct GVJ_s GVJ_t; + typedef struct gvdevice_engine_s gvdevice_engine_t; typedef struct gvrender_engine_s gvrender_engine_t; typedef struct gvlayout_engine_s gvlayout_engine_t; - typedef struct gvdisplay_engine_s gvdisplay_engine_t; - typedef struct gvtext_engine_s gvtext_engine_t; + typedef struct gvtextlayout_engine_s gvtextlayout_engine_t; typedef struct htmllabel_t htmllabel_t; diff --git a/lib/gvc/Makefile.am b/lib/gvc/Makefile.am index 8fe45fa02..7a29c1429 100644 --- a/lib/gvc/Makefile.am +++ b/lib/gvc/Makefile.am @@ -11,10 +11,10 @@ AM_CPPFLAGS = \ LIBS = $(LIBLTDL) $(SOCKET_LIBS) pkginclude_HEADERS = gvc.h gvcint.h gvplugin.h \ - gvplugin_render.h gvplugin_layout.h gvplugin_textlayout.h + gvplugin_render.h gvplugin_layout.h gvplugin_textlayout.h gvplugin_device.h pkglib_LTLIBRARIES = libgvc.la -libgvc_la_SOURCES = gvrender.c gvlayout.c gvtextlayout.c gvcontext.c \ - gvjobs.c gvevent.c gvplugin.c gvconfig.c +libgvc_la_SOURCES = gvrender.c gvlayout.c gvtextlayout.c gvdevice.c \ + gvcontext.c gvjobs.c gvevent.c gvplugin.c gvconfig.c EXTRA_DIST = Makefile.old diff --git a/lib/gvc/Makefile.old b/lib/gvc/Makefile.old index 4792e1404..c77678279 100644 --- a/lib/gvc/Makefile.old +++ b/lib/gvc/Makefile.old @@ -13,10 +13,10 @@ INCS = -I. \ DEFINES = -DHAVE_CONFIG_H -DGVLIBDIR=$(LIBDIR) -HDRS = gvc.h gvcint.h gvplugin_render.h \ +HDRS = gvc.h gvcint.h gvplugin_render.h gvplugin_device.h \ gvplugin_layout.h gvplugin_textlayout.h gvplugin.h -OBJS = gvrender.o gvlayout.o gvcontext.o gvjobs.o \ +OBJS = gvrender.o gvlayout.o gvdevice.o gvcontext.o gvjobs.o \ gvplugin.o gvconfig.o gvevent.o gvtextlayout.o libgvc.a : $(OBJS) diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 9f1b918df..5022a9e08 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -65,10 +65,14 @@ extern "C" { char *fontname, double fontsize, char *fontpath); -/* render */ +/* device */ + + extern void gvdevice_initialize(GVC_t * gvc); + extern void gvdevice_finalize(GVC_t * gvc); + extern void gvdevice_begin_job(GVJ_t * job); + extern void gvdevice_end_job(GVJ_t * job); - extern void gvrender_initialize(GVC_t * gvc); - extern void gvrender_finalize(GVC_t * gvc); +/* render */ extern void gvrender_begin_job(GVJ_t * job); extern void gvrender_end_job(GVJ_t * job); diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index 59d9b3f48..e2927a2ec 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -64,8 +64,13 @@ extern "C" { char **knowncolors; int sz_knowncolors; color_type_t color_type; + char *device; } gvrender_features_t; + typedef struct { + int flags; + } gvdevice_features_t; + struct GVJ_s { GVJ_t *next; /* linked list of jobs */ GVJ_t *next_active; /* linked list of active jobs (e.g. multiple windows) */ @@ -74,6 +79,10 @@ extern "C" { FILE *output_file; int output_lang; + gvdevice_engine_t *device_engine; /* current device engine */ + int device_id; /* internal id of current device engine within plugin */ + gvdevice_features_t *device_features; /* features of current device */ + gvrender_engine_t *render_engine; /* current render engine */ int render_id; /* internal id of current render engine within plugin */ gvrender_features_t *render_features; /* features of current render */ @@ -180,9 +189,8 @@ extern "C" { #undef ELEM void *display; /* display-specific data for gvdisplay plugin */ - gvdisplay_engine_t *display_engine; /* current display engine */ - gvtext_engine_t *text_engine; /* current text_layout engine */ + gvtextlayout_engine_t *textlayout_engine; /* current text_layout engine */ /* gvrender_begin_job() */ char *layout_type; /* string name of layout type */ diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c new file mode 100644 index 000000000..1c56c59c2 --- /dev/null +++ b/lib/gvc/gvdevice.c @@ -0,0 +1,147 @@ +/* $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 * +**********************************************************/ + +/* + * graphics code generator wrapper + * + * This library forms the socket for run-time loadable device plugins. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "const.h" +#include "types.h" +#include "macros.h" + +#include "gvplugin_device.h" +#include "gvc.h" + +int gvdevice_select(GVJ_t * job, char *str) +{ + GVC_t *gvc = job->gvc; + gv_plugin_t *plugin; + gvplugin_type_t *typeptr; +#ifndef DISABLE_CODEGENS + codegen_info_t *cg_info; +#endif + + plugin = gvplugin_load(gvc, API_device, str); + if (plugin) { +#ifndef DISABLE_CODEGENS + if (strcmp(plugin->packagename, "cg") == 0) { + cg_info = (codegen_info_t *) (plugin->typeptr); + job->codegen = cg_info->cg; + return cg_info->id; + } else { +#endif + typeptr = plugin->typeptr; + job->device_engine = (gvdevice_engine_t *) (typeptr->engine); + job->device_features = + (gvdevice_features_t *) (typeptr->features); + job->device_id = typeptr->id; + return GVRENDER_PLUGIN; +#ifndef DISABLE_CODEGENS + } +#endif + } + return NO_SUPPORT; +} + +int gvdevice_features(GVJ_t * job) +{ + gvdevice_engine_t *gvde = job->device_engine; + int features = 0; + + if (gvde) + features = job->device_features->flags; + return features; +} + +extern gvevent_key_binding_t gvevent_key_binding[]; +extern int gvevent_key_binding_size; + +void gvdevice_initialize(GVC_t * gvc) +{ + GVJ_t *job = gvc->job; + gvdevice_engine_t *gvde = job->device_engine; + + if (gvde && gvde->initialize) + gvde->initialize(gvc, gvevent_key_binding, gvevent_key_binding_size); +} + +void gvdevice_finalize(GVC_t * gvc) +{ + GVJ_t *job = gvc->active_jobs; + gvdevice_engine_t *gvde = job->device_engine; + + if (gvde) { + if (gvde->finalize) + gvde->finalize(gvc); + } +#ifndef DISABLE_CODEGENS + else { + codegen_t *cg = job->codegen; + + if (cg && cg->reset) + cg->reset(); + } +#endif +} + +void gvdevice_begin_job(GVJ_t * job) +{ + gvdevice_engine_t *gvde = job->device_engine; + + if (gvde) { + if (gvde->begin_job) + gvde->begin_job(job); + } +#if 0 +#ifndef DISABLE_CODEGENS + else { + codegen_t *cg = job->codegen; + + if (cg && cg->begin_job) + cg->begin_job(job->output_file, job->g, job->gvc->lib, job->gvc->user, + job->gvc->info, job->pagesArraySize); + } +#endif +#endif +} + +void gvdevice_end_job(GVJ_t * job) +{ + gvdevice_engine_t *gvde = job->device_engine; + + if (gvde && gvde->end_job) + gvde->end_job(job); +#if 0 +#ifndef DISABLE_CODEGENS + else { + codegen_t *cg = job->codegen; + + if (cg && cg->end_job) + cg->end_job(); + } +#endif +#endif + job->gvc->lib = NULL; +} diff --git a/lib/gvc/gvplugin.h b/lib/gvc/gvplugin.h index da56e1e3a..a1443c610 100644 --- a/lib/gvc/gvplugin.h +++ b/lib/gvc/gvplugin.h @@ -41,7 +41,7 @@ extern "C" { * The enumerated type is defined here. The apis array is * inititialized in gvplugin.c by redefining ELEM and reinvoking APIS. */ -#define APIS ELEM(render) ELEM(layout) ELEM(textlayout) +#define APIS ELEM(render) ELEM(layout) ELEM(textlayout) ELEM(device) #define ELEM(x) API_##x, typedef enum { APIS } api_t; /* API_render, API_layout, ... */ diff --git a/lib/gvc/gvplugin_device.h b/lib/gvc/gvplugin_device.h new file mode 100644 index 000000000..ae2e1416e --- /dev/null +++ b/lib/gvc/gvplugin_device.h @@ -0,0 +1,44 @@ +/* $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 * +**********************************************************/ + +#ifndef GVDEVICE_PLUGIN_H +#define GVDEVICE_PLUGIN_H + +#include "gvplugin.h" +#include "gvcint.h" + +#ifdef __cplusplus +extern "C" { +#endif + + struct gvdevice_engine_s { + void (*initialize) (GVC_t * gvc, gvevent_key_binding_t *keybindings, int numkeys); + void (*finalize) (GVC_t * gvc); + void (*begin_job) (GVJ_t * job); + void (*end_job) (GVJ_t * job); + }; + +/* callbacks */ + extern void gvevent_refresh(GVJ_t * job); + extern void gvevent_button_press(GVJ_t * job, int button, double x, double y); + extern void gvevent_button_release(GVJ_t * job, int button, double x, double y); + extern void gvevent_motion(GVJ_t * job, double x, double y); + + +#ifdef __cplusplus +} +#endif +#endif /* GVDEVICE_PLUGIN_H */ diff --git a/lib/gvc/gvplugin_render.h b/lib/gvc/gvplugin_render.h index 894eb9e43..d86d9ecea 100644 --- a/lib/gvc/gvplugin_render.h +++ b/lib/gvc/gvplugin_render.h @@ -25,8 +25,6 @@ extern "C" { #endif struct gvrender_engine_s { - void (*initialize) (GVC_t * gvc, gvevent_key_binding_t *keys, int numkeys); - void (*finalize) (GVC_t * gvc); void (*begin_job) (GVJ_t * job); void (*end_job) (GVJ_t * job); void (*begin_graph) (GVJ_t * job, char *graphname); @@ -62,12 +60,6 @@ extern "C" { int filled); }; -/* callbacks */ - extern void gvevent_refresh(GVJ_t * job); - extern void gvevent_button_press(GVJ_t * job, int button, double x, double y); - extern void gvevent_button_release(GVJ_t * job, int button, double x, double y); - extern void gvevent_motion(GVJ_t * job, double x, double y); - #ifdef __cplusplus } #endif diff --git a/lib/gvc/gvplugin_textlayout.h b/lib/gvc/gvplugin_textlayout.h index 345f2b121..e7bdfa7b7 100644 --- a/lib/gvc/gvplugin_textlayout.h +++ b/lib/gvc/gvplugin_textlayout.h @@ -14,8 +14,8 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -#ifndef GVTEXT_PLUGIN_H -#define GVTEXT_PLUGIN_H +#ifndef GVTEXTLAYOUT_PLUGIN_H +#define GVTEXTLAYOUT_PLUGIN_H #include "gvplugin.h" #include "gvcint.h" @@ -24,11 +24,11 @@ extern "C" { #endif - struct gvtext_engine_s { + struct gvtextlayout_engine_s { boolean (*width) (textline_t *textline, char *fontname, double fontsize, char* fontpath); }; #ifdef __cplusplus } #endif -#endif /* GVTEXT_PLUGIN_H */ +#endif /* GVTEXTLAYOUT_PLUGIN_H */ diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 131fbe669..11de867b5 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -17,11 +17,7 @@ /* * graphics code generator wrapper * - * This library will eventually form the socket for run-time loadable - * render plugins. Initially it just provides wrapper functions - * to the old codegens so that the changes can be locallized away from all - * the various codegen callers. - * + * This library forms the socket for run-time loadable render plugins. */ #ifdef HAVE_CONFIG_H @@ -53,6 +49,7 @@ int gvrender_select(GVJ_t * job, char *str) GVC_t *gvc = job->gvc; gv_plugin_t *plugin; gvplugin_type_t *typeptr; + char *device; #ifndef DISABLE_CODEGENS codegen_info_t *cg_info; #endif @@ -71,6 +68,17 @@ int gvrender_select(GVJ_t * job, char *str) job->render_features = (gvrender_features_t *) (typeptr->features); job->render_id = typeptr->id; + device = job->render_features->device; + if (device) { + plugin = gvplugin_load(gvc, API_device, device); + if (! plugin) + return NO_SUPPORT; + typeptr = plugin->typeptr; + job->device_engine = (gvdevice_engine_t *) (typeptr->engine); + job->device_features = + (gvdevice_features_t *) (typeptr->features); + job->device_id = typeptr->id; + } return GVRENDER_PLUGIN; #ifndef DISABLE_CODEGENS } @@ -105,50 +113,6 @@ int gvrender_features(GVJ_t * job) return features; } -extern gvevent_key_binding_t gvevent_key_binding[]; -extern int gvevent_key_binding_size; - -void gvrender_initialize(GVC_t * gvc) -{ - GVJ_t *job = gvc->job; - gvrender_engine_t *gvre = job->render_engine; - - if (gvre) { - if (gvre->initialize) - gvre->initialize(gvc, gvevent_key_binding, gvevent_key_binding_size); - } -#if 0 -/* codegens don't have this entry point */ -#ifndef DISABLE_CODEGENS - else { - codegen_t *cg = job->codegen; - - if (cg && cg->init) - cg->init(); - } -#endif -#endif -} - -void gvrender_finalize(GVC_t * gvc) -{ - GVJ_t *job = gvc->active_jobs; - gvrender_engine_t *gvre = job->render_engine; - - if (gvre) { - if (gvre->finalize) - gvre->finalize(gvc); - } -#ifndef DISABLE_CODEGENS - else { - codegen_t *cg = job->codegen; - - if (cg && cg->reset) - cg->reset(); - } -#endif -} - void gvrender_begin_job(GVJ_t * job) { gvrender_engine_t *gvre = job->render_engine; diff --git a/lib/gvc/gvtextlayout.c b/lib/gvc/gvtextlayout.c index 0b128fed8..9eadc10a0 100644 --- a/lib/gvc/gvtextlayout.c +++ b/lib/gvc/gvtextlayout.c @@ -47,7 +47,7 @@ int gvtext_select(GVC_t * gvc, char *text_layout) double gvtext_width(GVC_t *gvc, textline_t *textline, char *fontname, double fontsize, char *fontpath) { - gvtext_engine_t *gvte = gvc->text_engine; + gvtextlayout_engine_t *gvte = gvc->textlayout_engine; boolean rc; if (gvte && gvte->width) {