1 /* vim:set shiftwidth=4 ts=8: */
2 
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  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors: See CVS logs. Details at http://www.graphviz.org/
11  *************************************************************************/
12 
13 #ifndef XDOT_H
14 #define XDOT_H
15 #include <stdio.h>
16 #ifdef _WIN32
17 #include <windows.h>
18 #endif
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #ifdef _WIN32
25 #   ifdef EXPORT_XDOT
26 #       define XDOT_API __declspec(dllexport)
27 #   else
28 #       define XDOT_API __declspec(dllimport)
29 #   endif
30 #else
31 #   define XDOT_API extern
32 #endif
33 
34 #define INITIAL_XDOT_CAPACITY 512
35 
36 typedef enum {
37     xd_none,
38     xd_linear,
39     xd_radial
40 } xdot_grad_type;
41 
42 typedef struct {
43     float frac;
44     char* color;
45 } xdot_color_stop;
46 
47 typedef struct {
48     double x0, y0;
49     double x1, y1;
50     int n_stops;
51     xdot_color_stop* stops;
52 } xdot_linear_grad;
53 
54 typedef struct {
55     double x0, y0, r0;
56     double x1, y1, r1;
57     int n_stops;
58     xdot_color_stop* stops;
59 } xdot_radial_grad;
60 
61 typedef struct {
62     xdot_grad_type type;
63     union {
64 	char* clr;
65 	xdot_linear_grad ling;
66 	xdot_radial_grad ring;
67     } u;
68 } xdot_color;
69 
70 typedef enum {
71     xd_left, xd_center, xd_right
72 } xdot_align;
73 
74 typedef struct {
75     double x, y, z;
76 } xdot_point;
77 
78 typedef struct {
79     double x, y, w, h;
80 } xdot_rect;
81 
82 typedef struct {
83     int cnt;
84     xdot_point* pts;
85 } xdot_polyline;
86 
87 typedef struct {
88   double x, y;
89   xdot_align align;
90   double width;
91   char* text;
92 } xdot_text;
93 
94 typedef struct {
95     xdot_rect pos;
96     char* name;
97 } xdot_image;
98 
99 typedef struct {
100     double size;
101     char* name;
102 } xdot_font;
103 
104 typedef enum {
105     xd_filled_ellipse, xd_unfilled_ellipse,
106     xd_filled_polygon, xd_unfilled_polygon,
107     xd_filled_bezier,  xd_unfilled_bezier,
108     xd_polyline,       xd_text,
109     xd_fill_color,     xd_pen_color, xd_font, xd_style, xd_image,
110     xd_grad_fill_color,     xd_grad_pen_color,
111     xd_fontchar
112 } xdot_kind;
113 
114 typedef enum {
115     xop_ellipse,
116     xop_polygon,
117     xop_bezier,
118     xop_polyline,       xop_text,
119     xop_fill_color,     xop_pen_color, xop_font, xop_style, xop_image,
120     xop_grad_color,
121     xop_fontchar
122 } xop_kind;
123 
124 typedef struct _xdot_op xdot_op;
125 typedef void (*drawfunc_t)(xdot_op*, int);
126 typedef void (*freefunc_t)(xdot_op*);
127 
128 struct _xdot_op {
129     xdot_kind kind;
130     union {
131       xdot_rect ellipse;       /* xd_filled_ellipse, xd_unfilled_ellipse */
132       xdot_polyline polygon;   /* xd_filled_polygon, xd_unfilled_polygon */
133       xdot_polyline polyline;  /* xd_polyline */
134       xdot_polyline bezier;    /* xd_filled_bezier,  xd_unfilled_bezier */
135       xdot_text text;          /* xd_text */
136       xdot_image image;        /* xd_image */
137       char* color;             /* xd_fill_color, xd_pen_color */
138       xdot_color grad_color;   /* xd_grad_fill_color, xd_grad_pen_color */
139       xdot_font font;          /* xd_font */
140       char* style;             /* xd_style */
141       unsigned int fontchar;   /* xd_fontchar */
142     } u;
143     drawfunc_t drawfunc;
144 };
145 
146 #define XDOT_PARSE_ERROR 1
147 
148 typedef struct {
149     int cnt;  /* no. of xdot ops */
150     int sz;   /* sizeof structure containing xdot_op as first field */
151     xdot_op* ops;
152     freefunc_t freefunc;
153     int flags;
154 } xdot;
155 
156 typedef struct {
157     int cnt;  /* no. of xdot ops */
158     int n_ellipse;
159     int n_polygon;
160     int n_polygon_pts;
161     int n_polyline;
162     int n_polyline_pts;
163     int n_bezier;
164     int n_bezier_pts;
165     int n_text;
166     int n_font;
167     int n_style;
168     int n_color;
169     int n_image;
170     int n_gradcolor;
171     int n_fontchar;
172 } xdot_stats;
173 
174 /* ops are indexed by xop_kind */
175 XDOT_API xdot* parseXDotF (char*, drawfunc_t opfns[], int sz);
176 XDOT_API xdot* parseXDotFOn (char*, drawfunc_t opfns[], int sz, xdot*);
177 XDOT_API xdot* parseXDot (char*);
178 XDOT_API char* sprintXDot (xdot*);
179 XDOT_API void fprintXDot (FILE*, xdot*);
180 XDOT_API void jsonXDot (FILE*, xdot*);
181 XDOT_API void freeXDot (xdot*);
182 XDOT_API int statXDot (xdot*, xdot_stats*);
183 XDOT_API xdot_grad_type colorTypeXDot (char*);
184 XDOT_API char* parseXDotColor (char* cp, xdot_color* clr);
185 XDOT_API void freeXDotColor (xdot_color*);
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 #endif
191