Debian Codegraph @

lib/xdot/xdot.h

raw
1 /**
2 * @file
3 * @ingroup public_apis
4 * @brief parsing and deparsing of
5 * [xdot](https://graphviz.org/docs/outputs/canon/#xdot) operations
6 *
7 * **libxdot** provides support for parsing and deparsing graphical operations
8 * specified by the xdot language.
9 * [xdot](https://graphviz.org/docs/outputs/canon/#xdot) is extended dot format
10 * containing complete layout information.
11 *
12 * [man 3 xdot](https://graphviz.org/pdf/xdot.3.pdf)
13 *
14 */
15 /*************************************************************************
16 * Copyright (c) 2011 AT&T Intellectual Property
17 * All rights reserved. This program and the accompanying materials
18 * are made available under the terms of the Eclipse Public License v1.0
19 * which accompanies this distribution, and is available at
20 * https://www.eclipse.org/legal/epl-v10.html
21 *
22 * Contributors: Details at https://graphviz.org
23 *************************************************************************/
24
25 #pragma once
26
27 #include <stddef.h>
28 #include <stdio.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #ifdef GVDLL
35 #ifdef EXPORT_XDOT
36 #define XDOT_API __declspec(dllexport)
37 #else
38 #define XDOT_API __declspec(dllimport)
39 #endif
40 #endif
41
42 #ifndef XDOT_API
43 #define XDOT_API /* nothing */
44 #endif
45
46 typedef enum { xd_none, xd_linear, xd_radial } xdot_grad_type;
47
48 typedef struct {
49 double frac;
50 char *color;
51 } xdot_color_stop;
52
53 typedef struct {
54 double x0, y0;
55 double x1, y1;
56 int n_stops;
57 xdot_color_stop *stops;
58 } xdot_linear_grad;
59
60 typedef struct {
61 double x0, y0, r0;
62 double x1, y1, r1;
63 int n_stops;
64 xdot_color_stop *stops;
65 } xdot_radial_grad;
66
67 typedef struct {
68 xdot_grad_type type;
69 union {
70 char *clr;
71 xdot_linear_grad ling;
72 xdot_radial_grad ring;
73 } u;
74 } xdot_color;
75
76 typedef enum { xd_left, xd_center, xd_right } xdot_align;
77
78 typedef struct {
79 double x, y, z;
80 } xdot_point;
81
82 typedef struct {
83 double x, y, w, h;
84 } xdot_rect;
85
86 typedef struct {
87 size_t cnt;
88 xdot_point *pts;
89 } xdot_polyline;
90
91 typedef struct {
92 double x, y;
93 xdot_align align;
94 double width;
95 char *text;
96 } xdot_text;
97
98 typedef struct {
99 xdot_rect pos;
100 char *name;
101 } xdot_image;
102
103 typedef struct {
104 double size;
105 char *name;
106 } xdot_font;
107
108 typedef enum {
109 xd_filled_ellipse,
110 xd_unfilled_ellipse,
111 xd_filled_polygon,
112 xd_unfilled_polygon,
113 xd_filled_bezier,
114 xd_unfilled_bezier,
115 xd_polyline,
116 xd_text,
117 xd_fill_color,
118 xd_pen_color,
119 xd_font,
120 xd_style,
121 xd_image,
122 xd_grad_fill_color,
123 xd_grad_pen_color,
124 xd_fontchar
125 } xdot_kind;
126
127 typedef enum {
128 xop_ellipse,
129 xop_polygon,
130 xop_bezier,
131 xop_polyline,
132 xop_text,
133 xop_fill_color,
134 xop_pen_color,
135 xop_font,
136 xop_style,
137 xop_image,
138 xop_grad_color,
139 xop_fontchar
140 } xop_kind;
141
142 typedef struct _xdot_op xdot_op;
143 typedef void (*drawfunc_t)(xdot_op *, int);
144 typedef void (*freefunc_t)(xdot_op *);
145
146 struct _xdot_op {
147 xdot_kind kind;
148 union {
149 xdot_rect ellipse; /* xd_filled_ellipse, xd_unfilled_ellipse */
150 xdot_polyline polygon; /* xd_filled_polygon, xd_unfilled_polygon */
151 xdot_polyline polyline; /* xd_polyline */
152 xdot_polyline bezier; /* xd_filled_bezier, xd_unfilled_bezier */
153 xdot_text text; /* xd_text */
154 xdot_image image; /* xd_image */
155 char *color; /* xd_fill_color, xd_pen_color */
156 xdot_color grad_color; /* xd_grad_fill_color, xd_grad_pen_color */
157 xdot_font font; /* xd_font */
158 char *style; /* xd_style */
159 unsigned int fontchar; /* xd_fontchar */
160 } u;
161 drawfunc_t drawfunc;
162 };
163
164 #define XDOT_PARSE_ERROR 1
165
166 typedef struct {
167 size_t cnt; /* no. of xdot ops */
168 size_t sz; /* sizeof structure containing xdot_op as first field */
169 xdot_op *ops;
170 freefunc_t freefunc;
171 int flags;
172 } xdot;
173
174 typedef struct {
175 size_t cnt; /* no. of xdot ops */
176 size_t n_ellipse;
177 size_t n_polygon;
178 size_t n_polygon_pts;
179 size_t n_polyline;
180 size_t n_polyline_pts;
181 size_t n_bezier;
182 size_t n_bezier_pts;
183 size_t n_text;
184 size_t n_font;
185 size_t n_style;
186 size_t n_color;
187 size_t n_image;
188 size_t n_gradcolor;
189 size_t n_fontchar;
190 } xdot_stats;
191
192 /* ops are indexed by xop_kind */
193 XDOT_API xdot *parseXDotF(char *, drawfunc_t opfns[], size_t sz);
194 XDOT_API xdot *parseXDotFOn(char *, drawfunc_t opfns[], size_t sz, xdot *);
195 XDOT_API xdot *parseXDot(char *);
196 XDOT_API char *sprintXDot(xdot *);
197 XDOT_API void fprintXDot(FILE *, xdot *);
198 XDOT_API void jsonXDot(FILE *, xdot *);
199 XDOT_API void freeXDot(xdot *);
200 XDOT_API int statXDot(xdot *, xdot_stats *);
201 XDOT_API xdot_grad_type colorTypeXDot(char *);
202 XDOT_API char *parseXDotColor(char *cp, xdot_color *clr);
203 XDOT_API void freeXDotColor(xdot_color *);
204
205 #ifdef __cplusplus
206 }
207 #endif