xdot.3 9.1 KB

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