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