1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14/* Common header used by both clients and plugins */
15
16#ifndef GVCJOB_H
17#define GVCJOB_H
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#include "gvcommon.h"
24#include "color.h"
25
26#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
27
28 typedef struct gvdevice_engine_s gvdevice_engine_t;
29 typedef struct gvformatter_engine_s gvformatter_engine_t;
30 typedef struct gvrender_engine_s gvrender_engine_t;
31 typedef struct gvlayout_engine_s gvlayout_engine_t;
32 typedef struct gvtextlayout_engine_s gvtextlayout_engine_t;
33 typedef struct gvloadimage_engine_s gvloadimage_engine_t;
34
35 typedef enum { PEN_NONE, PEN_DASHED, PEN_DOTTED, PEN_SOLID } pen_type;
36 typedef enum { FILL_NONE, FILL_SOLID, FILL_LINEAR, FILL_RADIAL } fill_type;
37 typedef enum { FONT_REGULAR, FONT_BOLD, FONT_ITALIC } font_type;
38 typedef enum { LABEL_PLAIN, LABEL_HTML } label_type;
39
40#define PENWIDTH_NORMAL 1.
41#define PENWIDTH_BOLD 2.
42 typedef enum { GVATTR_STRING, GVATTR_BOOL, GVATTR_COLOR } gvattr_t;
43
44/* The -T output formats listed below are examples only, they are not definitive or inclusive,
45 other outputs may use the flags now, or in the future
46
47 Default emit order is breadth first graph walk order
48 EMIT_SORTED emits nodes before edges
49 EMIT_COLORS emits colors before nodes or edge -Tfig
50 EMIT_CLUSTERS_LAST emits cluster after nodes and edges
51 EMIT_PREORDER emit in preorder traversal ???
52 EMIT_EDGE_SORTED emits edges before nodes
53
54 GVDEVICE_DOES_PAGES provides pagination support -Tps
55 GVDEVICE_DOES_LAYERS provides support for layers -Tps
56 GVDEVICE_EVENTS supports mouse events -Tgtk, -Txlib
57 GVDEVICE_DOES_TRUECOLOR supports alpha channel -Tpng, -Tgtk, -Txlib
58 GVDEVICE_BINARY_FORMAT Suppresses \r\n substitution for linends
59 GVDEVICE_COMPRESSED_FORMAT controls libz compression
60 GVDEVICE_NO_WRITER used when gvdevice is not used because device uses its own writer, -Tming, devil outputs (FIXME seems to overlap OUTPUT_NOT_REQUIRED)
61
62 GVRENDER_Y_GOES_DOWN device origin top left, y goes down, otherwise
63 device origin lower left, y goes up
64 GVRENDER_DOES_TRANSFORM device uses scale, translate, rotate to do its own
65 coordinate transformations, otherwise coordinates
66 are pre-transformed
67 GVRENDER_DOES_ARROWS renderer has its own idea of arrow shapes (deprecated)
68 GVRENDER_DOES_LABELS basically, maps don't need labels
69 GVRENDER_DOES_MAPS renderer encodes mapping information for mouse events -Tcmapx -Tsvg
70 GVRENDER_DOES_MAP_RECTANGLE supports a 2 coord rectngle optimization
71 GVRENDER_DOES_MAP_CIRCLE supports a 1 coord + radius circle optimization
72 GVRENDER_DOES_MAP_POLYGON supports polygons (basically, -Tsvg uses anchors, so doesn't need to support any map shapes)
73 GVRENDER_DOES_MAP_ELLIPSE supports a 2 coord ellipse optimization
74 GVRENDER_DOES_MAP_BSPLINE supports mapping of splines
75 GVRENDER_DOES_TOOLTIPS can represent tooltip info -Tcmapx, -Tsvg
76 GVRENDER_DOES_TARGETS can represent target info (open link in a new tab or window)
77 GVRENDER_DOES_Z render support 2.5D representation -Tvrml
78 GVRENDER_NO_WHITE_BG don't paint white background, assumes white paper -Tps
79 LAYOUT_NOT_REQUIRED don't perform layout -Tcanon
80 OUTPUT_NOT_REQUIRED don't use gvdevice for output (basically when agwrite() used instead) -Tcanon, -Txdot
81 */
82
83
84#define EMIT_SORTED (1<<0)
85#define EMIT_COLORS (1<<1)
86#define EMIT_CLUSTERS_LAST (1<<2)
87#define EMIT_PREORDER (1<<3)
88#define EMIT_EDGE_SORTED (1<<4)
89#define GVDEVICE_DOES_PAGES (1<<5)
90#define GVDEVICE_DOES_LAYERS (1<<6)
91#define GVDEVICE_EVENTS (1<<7)
92#define GVDEVICE_DOES_TRUECOLOR (1<<8)
93#define GVDEVICE_BINARY_FORMAT (1<<9)
94#define GVDEVICE_COMPRESSED_FORMAT (1<<10)
95#define GVDEVICE_NO_WRITER (1<<11)
96#define GVRENDER_Y_GOES_DOWN (1<<12)
97#define GVRENDER_DOES_TRANSFORM (1<<13)
98#define GVRENDER_DOES_ARROWS (1<<14)
99#define GVRENDER_DOES_LABELS (1<<15)
100#define GVRENDER_DOES_MAPS (1<<16)
101#define GVRENDER_DOES_MAP_RECTANGLE (1<<17)
102#define GVRENDER_DOES_MAP_CIRCLE (1<<18)
103#define GVRENDER_DOES_MAP_POLYGON (1<<19)
104#define GVRENDER_DOES_MAP_ELLIPSE (1<<20)
105#define GVRENDER_DOES_MAP_BSPLINE (1<<21)
106#define GVRENDER_DOES_TOOLTIPS (1<<22)
107#define GVRENDER_DOES_TARGETS (1<<23)
108#define GVRENDER_DOES_Z (1<<24)
109#define GVRENDER_NO_WHITE_BG (1<<25)
110#define LAYOUT_NOT_REQUIRED (1<<26)
111#define OUTPUT_NOT_REQUIRED (1<<27)
112
113 typedef struct {
114 int flags;
115 double default_pad; /* graph units */
116 char **knowncolors;
117 int sz_knowncolors;
118 color_type_t color_type;
119 } gvrender_features_t;
120
121 typedef struct {
122 int flags;
123 pointf default_margin; /* left/right, top/bottom - points */
124 pointf default_pagesize;/* default page width, height - points */
125 pointf default_dpi;
126 } gvdevice_features_t;
127
128#define LAYOUT_USES_RANKDIR (1<<0)
129
130 typedef struct gvplugin_active_device_s {
131 gvdevice_engine_t *engine;
132 int id;
133 gvdevice_features_t *features;
134 const char *type;
135 } gvplugin_active_device_t;
136
137 typedef struct gvplugin_active_render_s {
138 gvrender_engine_t *engine;
139 int id;
140 gvrender_features_t *features;
141 const char *type;
142 } gvplugin_active_render_t;
143
144 typedef struct gvplugin_active_loadimage_t {
145 gvloadimage_engine_t *engine;
146 int id;
147 const char *type;
148 } gvplugin_active_loadimage_t;
149
150 typedef struct gv_argvlist_s {
151 char **argv;
152 int argc;
153 int alloc;
154 } gv_argvlist_t;
155
156 typedef struct gvdevice_callbacks_s {
157 void (*refresh) (GVJ_t * job);
158 void (*button_press) (GVJ_t * job, int button, pointf pointer);
159 void (*button_release) (GVJ_t * job, int button, pointf pointer);
160 void (*motion) (GVJ_t * job, pointf pointer);
161 void (*modify) (GVJ_t * job, const char *name, const char *value);
162 void (*del) (GVJ_t * job); /* can't use "delete" 'cos C++ stole it */
163 void (*read) (GVJ_t * job, const char *filename, const char *layout);
164 void (*layout) (GVJ_t * job, const char *layout);
165 void (*render) (GVJ_t * job, const char *format, const char *filename);
166 } gvdevice_callbacks_t;
167
168 typedef int (*gvevent_key_callback_t) (GVJ_t * job);
169
170 typedef struct gvevent_key_binding_s {
171 char *keystring;
172 gvevent_key_callback_t callback;
173 } gvevent_key_binding_t;
174
175 typedef enum {MAP_RECTANGLE, MAP_CIRCLE, MAP_POLYGON, } map_shape_t;
176
177 typedef enum {ROOTGRAPH_OBJTYPE, CLUSTER_OBJTYPE, NODE_OBJTYPE, EDGE_OBJTYPE} obj_type;
178
179 /* If this enum is changed, the implementation of xbuf and xbufs in
180 * gvrender_core_dot.c will probably need to be changed.
181 */
182 typedef enum {
183 EMIT_GDRAW, EMIT_CDRAW, EMIT_TDRAW, EMIT_HDRAW,
184 EMIT_GLABEL, EMIT_CLABEL, EMIT_TLABEL, EMIT_HLABEL,
185 EMIT_NDRAW, EMIT_EDRAW, EMIT_NLABEL, EMIT_ELABEL,
186 } emit_state_t;
187
188 typedef struct obj_state_s obj_state_t;
189
190 struct obj_state_s {
191 obj_state_t *parent;
192
193 obj_type type;
194 union {
195 graph_t *g;
196 graph_t *sg;
197 node_t *n;
198 edge_t *e;
199 } u;
200
201 emit_state_t emit_state;
202
203 gvcolor_t pencolor, fillcolor, stopcolor;
204 int gradient_angle;
205 float gradient_frac;
206 pen_type pen;
207 fill_type fill;
208 double penwidth;
209 char **rawstyle;
210
211 double z, tail_z, head_z; /* z depths for 2.5D renderers such as vrml */
212
213 /* fully substituted text strings */
214 char *label;
215 char *xlabel;
216 char *taillabel;
217 char *headlabel;
218
219 char *url; /* if GVRENDER_DOES_MAPS */
220 char *id;
221 char *labelurl;
222 char *tailurl;
223 char *headurl;
224
225 char *tooltip; /* if GVRENDER_DOES_TOOLTIPS */
226 char *labeltooltip;
227 char *tailtooltip;
228 char *headtooltip;
229
230 char *target; /* if GVRENDER_DOES_TARGETS */
231 char *labeltarget;
232 char *tailtarget;
233 char *headtarget;
234
235 int explicit_tooltip:1;
236 int explicit_tailtooltip:1;
237 int explicit_headtooltip:1;
238 int explicit_labeltooltip:1;
239 int explicit_tailtarget:1;
240 int explicit_headtarget:1;
241 int explicit_edgetarget:1;
242 int explicit_tailurl:1;
243 int explicit_headurl:1;
244 int labeledgealigned:1;
245
246 /* primary mapped region - node shape, edge labels */
247 map_shape_t url_map_shape;
248 int url_map_n; /* number of points for url map if GVRENDER_DOES_MAPS */
249 pointf *url_map_p;
250
251 /* additional mapped regions for edges */
252 int url_bsplinemap_poly_n; /* number of polygons in url bspline map
253 if GVRENDER_DOES_MAPS && GVRENDER_DOES_MAP_BSPLINES */
254 int *url_bsplinemap_n; /* array of url_bsplinemap_poly_n ints
255 of number of points in each polygon */
256 pointf *url_bsplinemap_p; /* all the polygon points */
257
258 int tailendurl_map_n; /* tail end intersection with node */
259 pointf *tailendurl_map_p;
260
261 int headendurl_map_n; /* head end intersection with node */
262 pointf *headendurl_map_p;
263 };
264
265/* Note on units:
266 * points - a physical distance (1/72 inch) unaffected by zoom or dpi.
267 * graph units - related to physical distance by zoom. Equals points at zoom=1
268 * device units - related to physical distance in points by dpi/72
269 */
270
271 struct GVJ_s {
272 GVC_t *gvc; /* parent gvc */
273 GVJ_t *next; /* linked list of jobs */
274 GVJ_t *next_active; /* linked list of active jobs (e.g. multiple windows) */
275
276 GVCOMMON_t *common;
277
278 obj_state_t *obj; /* objects can be nested (at least clusters can)
279 so keep object state on a stack */
280 char *input_filename;
281 int graph_index;
282
283 const char *layout_type;
284
285 const char *output_filename;
286 FILE *output_file;
287 char *output_data;
288 unsigned int output_data_allocated;
289 unsigned int output_data_position;
290
291 const char *output_langname;
292 int output_lang;
293
294 gvplugin_active_render_t render;
295 gvplugin_active_device_t device;
296 gvplugin_active_loadimage_t loadimage;
297 gvdevice_callbacks_t *callbacks;
298 pointf device_dpi;
299 boolean device_sets_dpi;
300
301 void *display;
302 int screen;
303
304 void *context; /* gd or cairo surface */
305 boolean external_context; /* context belongs to caller */
306 char *imagedata; /* location of imagedata */
307
308 int flags; /* emit_graph flags */
309
310 int numLayers; /* number of layers */
311 int layerNum; /* current layer - 1 based*/
312
313 point pagesArraySize; /* 2D size of page array */
314 point pagesArrayFirst;/* 2D starting corner in */
315 point pagesArrayMajor;/* 2D major increment */
316 point pagesArrayMinor;/* 2D minor increment */
317 point pagesArrayElem; /* 2D coord of current page - 0,0 based */
318 int numPages; /* number of pages */
319
320 boxf bb; /* graph bb with padding - graph units */
321 pointf pad; /* padding around bb - graph units */
322 boxf clip; /* clip region in graph units */
323 boxf pageBox; /* current page in graph units */
324 pointf pageSize; /* page size in graph units */
325 pointf focus; /* viewport focus - graph units */
326
327 double zoom; /* viewport zoom factor (points per graph unit) */
328 int rotation; /* viewport rotation (degrees) 0=portrait, 90=landscape */
329
330 pointf view; /* viewport size - points */
331 boxf canvasBox; /* viewport area - points */
332 pointf margin; /* job-specific margin - points */
333
334 pointf dpi; /* device resolution device-units-per-inch */
335
336 unsigned int width; /* device width - device units */
337 unsigned int height; /* device height - device units */
338 box pageBoundingBox;/* rotated boundingBox - device units */
339 box boundingBox; /* cumulative boundingBox over all pages - device units */
340
341 pointf scale; /* composite device to graph units (zoom and dpi) */
342 pointf translation; /* composite translation */
343 pointf devscale; /* composite device to points: dpi, y_goes_down */
344
345 boolean fit_mode,
346 needs_refresh,
347 click,
348 has_grown,
349 has_been_rendered;
350
351 unsigned char button; /* active button */
352 pointf pointer; /* pointer position in device units */
353 pointf oldpointer; /* old pointer position in device units */
354
355 void *current_obj; /* graph object that pointer is in currently */
356
357 void *selected_obj; /* graph object that has been selected */
358 /* (e.g. button 1 clicked on current obj) */
359 char *active_tooltip; /* tooltip of active object - or NULL */
360 char *selected_href; /* href of selected object - or NULL */
361 gv_argvlist_t selected_obj_type_name; /* (e.g. "edge" "node3" "e" "->" "node5" "") */
362 gv_argvlist_t selected_obj_attributes; /* attribute triplets: name, value, type */
363 /* e.g. "color", "red", GVATTR_COLOR,
364 "style", "filled", GVATTR_BOOL, */
365
366 void *window; /* display-specific data for gvrender plugin */
367
368 /* keybindings for keyboard events */
369 gvevent_key_binding_t *keybindings;
370 int numkeys;
371 void *keycodes;
372 };
373
374#ifdef __cplusplus
375}
376#endif
377#endif /* GVCJOB_H */
378