| 1 |
.TH LIBXDOT 3 "31 JULY 2009" |
| 2 |
.SH NAME |
| 3 |
\fBlibxdot\fR \- parsing and deparsing of xdot operations |
| 4 |
.SH SYNOPSIS |
| 5 |
.ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i |
| 6 |
.PP |
| 7 |
.nf |
| 8 |
\f5 |
| 9 |
#include <graphviz/xdot.h> |
| 10 |
|
| 11 |
typedef enum { |
| 12 |
xd_none, |
| 13 |
xd_linear, |
| 14 |
xd_radial |
| 15 |
} xdot_grad_type; |
| 16 |
|
| 17 |
typedef struct { |
| 18 |
float frac; |
| 19 |
char* color; |
| 20 |
} xdot_color_stop; |
| 21 |
|
| 22 |
typedef struct { |
| 23 |
double x0, y0; |
| 24 |
double x1, y1; |
| 25 |
int n_stops; |
| 26 |
xdot_color_stop* stops; |
| 27 |
} xdot_linear_grad; |
| 28 |
|
| 29 |
typedef struct { |
| 30 |
double x0, y0, r0; |
| 31 |
double x1, y1, r1; |
| 32 |
int n_stops; |
| 33 |
xdot_color_stop* stops; |
| 34 |
} xdot_radial_grad; |
| 35 |
|
| 36 |
typedef struct { |
| 37 |
xdot_grad_type type; |
| 38 |
union { |
| 39 |
char* clr; |
| 40 |
xdot_linear_grad ling; |
| 41 |
xdot_radial_grad ring; |
| 42 |
} u; |
| 43 |
} xdot_color; |
| 44 |
|
| 45 |
typedef enum { |
| 46 |
xd_left, xd_center, xd_right |
| 47 |
} xdot_align; |
| 48 |
|
| 49 |
typedef struct { |
| 50 |
double x, y, z; |
| 51 |
} xdot_point; |
| 52 |
|
| 53 |
typedef struct { |
| 54 |
double x, y, w, h; |
| 55 |
} xdot_rect; |
| 56 |
|
| 57 |
typedef struct { |
| 58 |
int cnt; |
| 59 |
xdot_point* pts; |
| 60 |
} xdot_polyline; |
| 61 |
|
| 62 |
typedef struct { |
| 63 |
double x, y; |
| 64 |
xdot_align align; |
| 65 |
double width; |
| 66 |
char* text; |
| 67 |
} xdot_text; |
| 68 |
|
| 69 |
typedef struct { |
| 70 |
xdot_rect pos; |
| 71 |
char* name; |
| 72 |
} xdot_image; |
| 73 |
|
| 74 |
typedef struct { |
| 75 |
double size; |
| 76 |
char* name; |
| 77 |
} xdot_font; |
| 78 |
|
| 79 |
typedef enum { |
| 80 |
xd_filled_ellipse, xd_unfilled_ellipse, |
| 81 |
xd_filled_polygon, xd_unfilled_polygon, |
| 82 |
xd_filled_bezier, xd_unfilled_bezier, |
| 83 |
xd_polyline, xd_text, |
| 84 |
xd_fill_color, xd_pen_color, xd_font, xd_style, xd_image, |
| 85 |
xd_grad_fill_color, xd_grad_pen_color, |
| 86 |
xd_fontchar |
| 87 |
} xdot_kind; |
| 88 |
|
| 89 |
typedef enum { |
| 90 |
xop_ellipse, |
| 91 |
xop_polygon, |
| 92 |
xop_bezier, |
| 93 |
xop_polyline, xop_text, |
| 94 |
xop_fill_color, xop_pen_color, xop_font, xop_style, xop_image, |
| 95 |
xop_grad_color, |
| 96 |
xop_fontchar |
| 97 |
} xop_kind; |
| 98 |
|
| 99 |
typedef struct _xdot_op xdot_op; |
| 100 |
typedef void (*drawfunc_t)(xdot_op*, int); |
| 101 |
typedef void (*freefunc_t)(xdot_op*); |
| 102 |
|
| 103 |
struct _xdot_op { |
| 104 |
xdot_kind kind; |
| 105 |
union { |
| 106 |
xdot_rect ellipse; /* xd_filled_ellipse, xd_unfilled_ellipse */ |
| 107 |
xdot_polyline polygon; /* xd_filled_polygon, xd_unfilled_polygon */ |
| 108 |
xdot_polyline polyline; /* xd_polyline */ |
| 109 |
xdot_polyline bezier; /* xd_filled_bezier, xd_unfilled_bezier */ |
| 110 |
xdot_text text; /* xd_text */ |
| 111 |
xdot_image image; /* xd_image */ |
| 112 |
char* color; /* xd_fill_color, xd_pen_color */ |
| 113 |
xdot_color grad_color; /* xd_grad_fill_color, xd_grad_pen_color */ |
| 114 |
xdot_font font; /* xd_font */ |
| 115 |
char* style; /* xd_style */ |
| 116 |
unsigned int fontchar; /* xd_fontchar */ |
| 117 |
} u; |
| 118 |
drawfunc_t drawfunc; |
| 119 |
}; |
| 120 |
|
| 121 |
#define XDOT_PARSE_ERROR 1 |
| 122 |
|
| 123 |
typedef struct { |
| 124 |
int cnt; |
| 125 |
int sz; |
| 126 |
xdot_op* ops; |
| 127 |
freefunc_t freefunc; |
| 128 |
int flags; |
| 129 |
} xdot; |
| 130 |
|
| 131 |
typedef struct { |
| 132 |
int cnt; /* no. of xdot ops */ |
| 133 |
int n_ellipse; |
| 134 |
int n_polygon; |
| 135 |
int n_polygon_pts; |
| 136 |
int n_polyline; |
| 137 |
int n_polyline_pts; |
| 138 |
int n_bezier; |
| 139 |
int n_bezier_pts; |
| 140 |
int n_text; |
| 141 |
int n_font; |
| 142 |
int n_style; |
| 143 |
int n_color; |
| 144 |
int n_image; |
| 145 |
int n_gradcolor; |
| 146 |
int n_fontchar; |
| 147 |
} xdot_stats; |
| 148 |
|
| 149 |
xdot* parseXDotF (char*, drawfunc_t opfns[], int sz); |
| 150 |
xdot* parseXDotFOn (char*, drawfunc_t opfns[], int sz, xdot*); |
| 151 |
xdot* parseXDot (char*); |
| 152 |
char* sprintXDot (xdot*); |
| 153 |
void fprintXDot (FILE*, xdot*); |
| 154 |
void jsonXDot (FILE*, xdot*); |
| 155 |
void freeXDot (xdot*); |
| 156 |
int statXDot (xdot*, xdot_stats*); |
| 157 |
|
| 158 |
xdot_grad_type colorType (char*); |
| 159 |
xdot_color* parseXDotColor (char*); |
| 160 |
void freeXDotColor (xdot_color*); |
| 161 |
\fP |
| 162 |
.fi |
| 163 |
.SH DESCRIPTION |
| 164 |
\fIlibxdot\fP provides support for parsing and deparsing |
| 165 |
graphical operations specified by the \fIxdot\fP language. |
| 166 |
.SS "Types" |
| 167 |
.PP |
| 168 |
.SS " xdot" |
| 169 |
This encapsulates a series of \fIcnt\fP xdot operations, stored |
| 170 |
in the array pointed to by \fIops\fP. The \fIsz\fP indicates |
| 171 |
the size of each item stored in \fIops\fP. If the user sets |
| 172 |
the \fIfreefunc\fP field, this function will be called on each |
| 173 |
item in \fIops\fP during \fIfreeXDot\fP before the library does |
| 174 |
its own clean up of the item. This allows the user to free any |
| 175 |
resources stored in the item by using an expansion of the \fIxdot_op\fP |
| 176 |
structure. |
| 177 |
.PP |
| 178 |
.SS " xdot_op" |
| 179 |
A value of this type represents one xdot operation. The operation |
| 180 |
is specified by the \fIkind\fP field. The corresponding data is |
| 181 |
stored in the union \fIu\fP, with the subfield associated with |
| 182 |
a given \fIkind\fP indicated by the comments. |
| 183 |
.PP |
| 184 |
The \fIdrawfunc\fP field allows the user to attach a drawing-specific |
| 185 |
function to the operation, providing an object-based interface. These |
| 186 |
functions can be automatically attached during parsing by providing a |
| 187 |
non-NULL second argument to \fBparseXDotF\fP. |
| 188 |
.PP |
| 189 |
.SS " xop_kind" |
| 190 |
This type provides an enumeration of the allowed xdot operations. |
| 191 |
See |
| 192 |
.br |
| 193 |
https://graphviz.org/docs/outputs/canon/#xdot |
| 194 |
.br |
| 195 |
for the specific semantics associated with each operation. |
| 196 |
.PP |
| 197 |
.SS " xdot_rect" |
| 198 |
This represents a rectangle. For ellipses, |
| 199 |
the \fIx\fP and \fIx\fP fields represent the center of the rectangle, |
| 200 |
and \fIw\fP and \fIh\fP give the half-width and half-height, respectively. |
| 201 |
For images, (\fIx\fP,\fIy\fP) gives the lower left corner of the |
| 202 |
rectangle, and \fIw\fP and \fIh\fP give the width and height, respectively. |
| 203 |
.PP |
| 204 |
.SS " xdot_polyline" |
| 205 |
This type encapsulates a series of \fIcnt\fP points. |
| 206 |
.PP |
| 207 |
.SS " xdot_text" |
| 208 |
A value of this type corresponds to printing the string \fItext\fP |
| 209 |
using the baseline point (\fIx\fP,\fIy\fP). |
| 210 |
The \fIwidth\fP field gives an approximation of how wide the printed |
| 211 |
string will be using the current font and font size. |
| 212 |
The \fIalign\fP field indicates how the text should be horizontally |
| 213 |
aligned with the point (\fIx\fP,\fIy\fP). |
| 214 |
.PP |
| 215 |
.SS " xdot_image" |
| 216 |
This denotes the insertion of an image. The image source is |
| 217 |
given by \fIname\fP. The images is to be placed into the rectangle |
| 218 |
\fIpos\fP. |
| 219 |
.PP |
| 220 |
.SS " xdot_font" |
| 221 |
The fields give the name and size, in points, of a font. |
| 222 |
.PP |
| 223 |
.SS " xdot_align" |
| 224 |
This enumeration type corresponds to the xdot alignment values |
| 225 |
-1, 0 and 1 used with the text operator, or '\\l', '\\n' and '\\r' |
| 226 |
used in dot text. |
| 227 |
.SS "Functions" |
| 228 |
.PP |
| 229 |
.SS " xdot* parseXDotF (char *str, drawfunc_t* opfns, int sz)" |
| 230 |
Parses the string \fIstr\fP as a sequence of xdot operations |
| 231 |
and returns a pointer to the resulting \fIxdot\fP structure. |
| 232 |
The function parses as many xdot operations as it can. If some |
| 233 |
unknown or incorrect input was encountered in \fIstr\fP, |
| 234 |
the \fIops\fP and \fIcnt\fP fields will reflect the operations |
| 235 |
parsed before the error, and |
| 236 |
the \fIXDOT_PARSE_ERROR\fP bit will be set in the \fIflags\fP field. |
| 237 |
The function returns NULL if it cannot parse anything. |
| 238 |
.PP |
| 239 |
If \fIsz\fP is non-zero, it is assumed to be the size of some |
| 240 |
structure type containing \fIxdot_op\fP as a prefix. In this case, |
| 241 |
the elements in the array pointed to by \fIops\fP will each have |
| 242 |
size \fIsz\fP. |
| 243 |
.PP |
| 244 |
If \fIopfns\fP is non-zero, it is taken to be any array of functions |
| 245 |
indexed by \fIxop_kind\fP. During parsing, the \fIdrawfunc\fP member |
| 246 |
of \fIxop_op\fP will be set to the corresponding function in \fIopfns\fP. |
| 247 |
.PP |
| 248 |
.SS " xdot* parseXDotFOn (char *str, drawfunc_t* opfns, int sz, xdot* x)" |
| 249 |
The same as \fIparseXDotF\fP, but append to the given \fIxdot\fP object \fIx\fP. |
| 250 |
.PP |
| 251 |
.SS " xdot* parseXDot (char *str)" |
| 252 |
This is equivalent to \fIparseXDotF(str, 0, 0)\fP . |
| 253 |
.PP |
| 254 |
.SS " void freeXDot (xdot* xp)" |
| 255 |
This frees the resources associated with the argument. |
| 256 |
If \fIxp\fP is NULL, nothing happens. |
| 257 |
.PP |
| 258 |
.SS " extern char* sprintXDot (xdot* xp)" |
| 259 |
.SS " extern void fprintXDot (FILE* fp, xdot* xp)" |
| 260 |
These two functions deparse the argument xdot structure, producing |
| 261 |
a string representation. \fIfprintXDot\fP writes the output onto |
| 262 |
the open stream \fIfp\fP; \fIsprintXDot\fP returns a heap-allocated |
| 263 |
string. |
| 264 |
.PP |
| 265 |
The color string with fill and draw operations can encode linear |
| 266 |
and radial gradients. These values are parsed automatically by |
| 267 |
\fBparseXDotF\fP or \fBparseXDot\fP, |
| 268 |
with \fIxdot_op\fP having kind \fIxd_grad_pen_color\fP or |
| 269 |
\fIxd_grad_fill_color\fP and the value is stored in \fIgrad_color\fP. |
| 270 |
.PP |
| 271 |
For an application that handles its own parsing of xdot, the library |
| 272 |
provides three helper functions. |
| 273 |
.PP |
| 274 |
.SS " void jsonXDot(FILE * fp, xdot * x)" |
| 275 |
Translate a given \fIxdot\fP object to a JSON representation. This functionality |
| 276 |
is currently considered experimental and the format of the JSON output may not |
| 277 |
be stable across Graphviz releases. |
| 278 |
.PP |
| 279 |
.SS " xdot_grad_type colorTypeXDot (char *str)" |
| 280 |
returns the color type described by the input string. |
| 281 |
.PP |
| 282 |
.SS " char* parseXDotColor (char *str, xdot_color* clr)" |
| 283 |
attempts to parse the string \fIstr\fP as a color value, storing |
| 284 |
the result in \fIclr\fP. It returns NULL on failure. |
| 285 |
.PP |
| 286 |
.SS " void freeXDotColor (xdot_color* cp)" |
| 287 |
This frees the resources associated with a value of type \fIxdot_color\fP. |
| 288 |
.PP |
| 289 |
.SS " int statXDot (xdot *x, xdot_stats *sp)" |
| 290 |
This function is provided for retrieving various statistics about an \fIxdot\fP |
| 291 |
object. Returns 0 on success and populates the output parameter \fIsp\fP with |
| 292 |
counts of various entities in the \fIxdot\fP object. |
| 293 |
|
| 294 |
.SH BUGS |
| 295 |
Although some small checking is done on the \fIsz\fP argument to |
| 296 |
\fIparseXDotF\fP, it is assumed it is a valid value from \fIsizeof\fP |
| 297 |
applied to some structure type containing \fIxdot_op\fP as its first |
| 298 |
field. There can be no validation of the \fIopfns\fP argument. |
| 299 |
.SH AUTHORS |
| 300 |
Emden R. Gansner ([email protected]). |