1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 /* $Id: gdevcgml.h 8022 2007-06-05 22:23:38Z giles $ */
14 /* Interface definitions for CGM-writing library */
15 
16 #ifndef gdevcgml_INCLUDED
17 #  define gdevcgml_INCLUDED
18 
19 /* The names in the following follow the CGM standard exactly, */
20 /* except that we have substituted the American spellings of */
21 /* color (colour) and center (centre). */
22 
23 /* ================ Types ================ */
24 
25 /* Define the abstract type for the CGM writer state. */
26 typedef struct cgm_state_s cgm_state;
27 
28 /* Define the type for the allocator used by the CGM writer. */
29 typedef struct cgm_allocator_s {
30     void *private_data;
31     void *(*alloc) (void *, uint);
32     void (*free) (void *, void *);
33 } cgm_allocator;
34 
35 /* Define types for CGM coordinates. */
36 typedef int cgm_int;
37 typedef double cgm_real;
38 typedef union cgm_vdc_s {
39     cgm_int integer;
40     cgm_real real;
41 } cgm_vdc;
42 typedef struct cgm_int_point_s {
43     cgm_int x, y;
44 } cgm_int_point;
45 typedef struct cgm_real_point_s {
46     cgm_real x, y;
47 } cgm_real_point;
48 typedef union cgm_point_s {
49     cgm_int_point integer;
50     cgm_real_point real;
51 } cgm_point;
52 
53 /* Define types for colors. */
54 typedef struct cgm_rgb_s {
55     cgm_int r, g, b;
56 } cgm_rgb;
57 typedef union cgm_color_s {
58     cgm_int index;
59     cgm_rgb rgb;
60 } cgm_color;
61 
62 /*
63  * Define other types used in CGM elements or API calls.
64  * If cgm_xxx is an enumerated type, let xxx' be xxx with any of the
65  * following words dropped: mode, specification, type; then the values
66  * of the enumerated type are named cgm_xxx'_yyy.
67  */
68 typedef enum {
69     cgm_vdc_integer = 0,
70     cgm_vdc_real
71 } cgm_vdc_type;
72 typedef struct cgm_string_s {
73     const char *chars;
74     uint length;
75 } cgm_string;
76 typedef enum {
77     cgm_scaling_abstract = 0,
78     cgm_scaling_metric
79 } cgm_scaling_mode;
80 typedef enum {
81     cgm_color_selection_indexed = 0,
82     cgm_color_selection_direct
83 } cgm_color_selection_mode;
84 typedef enum {
85     cgm_line_marker_absolute = 0,
86     cgm_line_marker_scaled
87 } cgm_line_marker_specification_mode;
88 typedef cgm_line_marker_specification_mode
89         cgm_line_width_specification_mode, cgm_marker_size_specification_mode,
90         cgm_edge_width_specification_mode;
91 typedef union cgm_line_marker_extent_s {
92     cgm_vdc absolute;
93     cgm_real scaled;
94 } cgm_line_marker_extent;
95 typedef cgm_line_marker_extent
96         cgm_line_width, cgm_marker_size, cgm_edge_width;
97 typedef enum {
98     cgm_transparency_off = 0,
99     cgm_transparency_on
100 } cgm_transparency;
101 typedef enum {
102     cgm_clip_off = 0,
103     cgm_clip_on
104 } cgm_clip_indicator;
105 typedef struct cgm_precision_s {
106     enum {
107 	cgm_representation_floating, cgm_representation_fixed
108     } representation;
109     int exponent_or_whole_width;
110     int fraction_width;
111 } cgm_precision;
112 typedef enum {
113     cgm_line_solid = 1,
114     cgm_line_dash,
115     cgm_line_dot,
116     cgm_line_dash_dot,
117     cgm_line_dash_dot_dot
118 } cgm_line_type;
119 typedef enum {
120     cgm_marker_dot = 1,
121     cgm_marker_plus,
122     cgm_marker_asterisk,
123     cgm_marker_circle,
124     cgm_marker_cross
125 } cgm_marker_type;
126 typedef enum {
127     cgm_text_precision_string = 0,
128     cgm_text_precision_character,
129     cgm_text_precision_stroke
130 } cgm_text_precision;
131 typedef enum {
132     cgm_text_path_right = 0,
133     cgm_text_path_left,
134     cgm_text_path_up,
135     cgm_text_path_down
136 } cgm_text_path;
137 typedef enum {
138     cgm_text_horizontal_normal = 0,
139     cgm_text_horizontal_left,
140     cgm_text_horizontal_center,
141     cgm_text_horizontal_right,
142     cgm_text_horizontal_continuous
143 } cgm_text_alignment_horizontal;
144 typedef enum {
145     cgm_text_vertical_normal = 0,
146     cgm_text_vertical_top,
147     cgm_text_vertical_cap,
148     cgm_text_vertical_half,
149     cgm_text_vertical_base,
150     cgm_text_vertical_bottom,
151     cgm_text_vertical_continuous
152 } cgm_text_alignment_vertical;
153 typedef enum {
154     cgm_interior_style_hollow = 0,
155     cgm_interior_style_solid,
156     cgm_interior_style_pattern,
157     cgm_interior_style_hatch,
158     cgm_interior_style_empty
159 } cgm_interior_style;
160 typedef enum {
161     cgm_hatch_horizontal = 1,
162     cgm_hatch_vertical,
163     cgm_hatch_positive_slope,
164     cgm_hatch_negative_slope,
165     cgm_hatch_combined_v_h_slant,
166     cgm_hatch_combined_l_r_slant
167 } cgm_hatch_index;
168 typedef enum {
169     cgm_arc_closure_pie = 0,
170     cgm_arc_closure_chord
171 } cgm_arc_closure;
172 typedef enum {
173     cgm_edge_out_invisible = 0,
174     cgm_edge_out_visible,
175     cgm_edge_out_close_invisible,
176     cgm_edge_out_close_visible
177 } cgm_edge_out;
178 typedef struct cgm_polygon_edge_s {
179     cgm_point vertex;
180     cgm_edge_out edge_out;
181 } cgm_polygon_edge;
182 typedef enum {
183     cgm_cell_mode_run_length = 0,
184     cgm_cell_mode_packed
185 } cgm_cell_representation_mode;
186 typedef enum {
187     cgm_edge_solid = 1,
188     cgm_edge_dash,
189     cgm_edge_dot,
190     cgm_edge_dash_dot,
191     cgm_edge_dash_dot_dot
192 } cgm_edge_type;
193 typedef enum {
194     cgm_aspect_source_individual = 0,
195     cgm_aspect_source_bundled
196 } cgm_aspect_source;
197 typedef enum {
198     cgm_aspect_line_type = 0,
199     cgm_aspect_line_width,
200     cgm_aspect_line_color,
201     cgm_aspect_marker_type,
202     cgm_aspect_marker_size,
203     cgm_aspect_marker_color,
204     cgm_aspect_text_font_index,
205     cgm_aspect_text_precision,
206     cgm_aspect_character_expansion_factor,
207     cgm_aspect_character_spacing,
208     cgm_aspect_text_color,
209     cgm_aspect_interior_style,
210     cgm_aspect_fill_color,
211     cgm_aspect_hatch_index,
212     cgm_aspect_pattern_index,
213     cgm_aspect_edge_type,
214     cgm_aspect_edge_width,
215     cgm_aspect_edge_color
216 } cgm_aspect_type;
217 typedef struct cgm_aspect_source_flag_s {
218     cgm_aspect_type type;
219     cgm_aspect_source source;
220 } cgm_aspect_source_flag;
221 
222 /* ================ API ================ */
223 
224 typedef enum {
225     cgm_result_ok = 0,
226     cgm_result_wrong_state = -1,
227     cgm_result_out_of_range = -2,
228     cgm_result_io_error = -3,
229     cgm_result_out_of_memory = -4
230 } cgm_result;
231 
232 /* ---------------- Initialize/terminate ---------------- */
233 
234 cgm_state *cgm_initialize(FILE *, const cgm_allocator *);
235 cgm_result cgm_terminate(cgm_state *);
236 
237 /* ---------------- Metafile elements ---------------- */
238 
239 typedef struct cgm_metafile_elements_s {
240     cgm_int metafile_version;
241     cgm_string metafile_description;
242     cgm_vdc_type vdc_type;
243     int integer_precision;
244     cgm_precision real_precision;
245     int index_precision;
246     int color_precision;
247     int color_index_precision;
248     cgm_int maximum_color_index;
249     cgm_color color_value_extent[2];
250     const int *metafile_element_list;
251     int metafile_element_list_count;
252     const cgm_string *font_list;
253     int font_list_count;
254     /* character_set_list */
255     /* character_coding_announcer */
256 } cgm_metafile_elements;
257 
258 #define cgm_set_METAFILE_VERSION	(1L<<0)
259 #define cgm_set_METAFILE_DESCRIPTION	(1L<<1)
260 #define cgm_set_VDC_TYPE		(1L<<2)
261 #define cgm_set_INTEGER_PRECISION	(1L<<3)
262 #define cgm_set_REAL_PRECISION		(1L<<4)
263 #define cgm_set_INDEX_PRECISION		(1L<<5)
264 #define cgm_set_COLOR_PRECISION		(1L<<6)
265 #define cgm_set_COLOR_INDEX_PRECISION	(1L<<7)
266 #define cgm_set_MAXIMUM_COLOR_INDEX	(1L<<8)
267 #define cgm_set_COLOR_VALUE_EXTENT	(1L<<9)
268 #define cgm_set_METAFILE_ELEMENT_LIST	(1L<<10)
269 #define cgm_set_FONT_LIST		(1L<<11)
270 #define cgm_set_CHARACTER_SET_LIST	(1L<<12)
271 #define cgm_set_CHARACTER_CODING_ANNOUNCER	(1L<<13)
272 
273 cgm_result
274     cgm_BEGIN_METAFILE(cgm_state *, const char *, uint),
275     cgm_set_metafile_elements(cgm_state *,
276 			      const cgm_metafile_elements *, long),
277     cgm_END_METAFILE(cgm_state *);
278 
279 /* ---------------- Picture elements ---------------- */
280 
281 typedef struct cgm_picture_elements_s {
282     cgm_scaling_mode scaling_mode;
283     cgm_real scale_factor;
284     cgm_color_selection_mode color_selection_mode;
285     cgm_line_width_specification_mode line_width_specification_mode;
286     cgm_marker_size_specification_mode marker_size_specification_mode;
287     cgm_edge_width_specification_mode edge_width_specification_mode;
288     cgm_point vdc_extent[2];
289     cgm_color background_color;
290 } cgm_picture_elements;
291 
292 #define cgm_set_SCALING_MODE		(1L<<0)
293 #define cgm_set_COLOR_SELECTION_MODE	(1L<<1)
294 #define cgm_set_LINE_WIDTH_SPECIFICATION_MODE	(1L<<2)
295 #define cgm_set_MARKER_SIZE_SPECIFICATION_MODE	(1L<<3)
296 #define cgm_set_EDGE_WIDTH_SPECIFICATION_MODE	(1L<<4)
297 #define cgm_set_VDC_EXTENT		(1L<<5)
298 #define cgm_set_BACKGROUND_COLOR	(1L<<6)
299 
300 cgm_result
301     cgm_BEGIN_PICTURE(cgm_state *, const char *, uint),
302     cgm_set_picture_elements(cgm_state *,
303 			     const cgm_picture_elements *, long),
304     cgm_BEGIN_PICTURE_BODY(cgm_state *),
305     cgm_END_PICTURE(cgm_state *);
306 
307 /* ---------------- Control elements ---------------- */
308 
309 cgm_result
310     cgm_VDC_INTEGER_PRECISION(cgm_state *, int),
311     cgm_VDC_REAL_PRECISION(cgm_state *, const cgm_precision *),
312     cgm_AUXILIARY_COLOR(cgm_state *, const cgm_color *),
313     cgm_TRANSPARENCY(cgm_state *, cgm_transparency),
314     cgm_CLIP_RECTANGLE(cgm_state *, const cgm_point[2]),
315     cgm_CLIP_INDICATOR(cgm_state *, cgm_clip_indicator);
316 
317 /* ---------------- Graphical primitive elements ---------------- */
318 
319 cgm_result
320     cgm_POLYLINE(cgm_state *, const cgm_point *, int),
321     cgm_DISJOINT_POLYLINE(cgm_state *, const cgm_point *, int),
322     cgm_POLYMARKER(cgm_state *, const cgm_point *, int),
323     cgm_TEXT(cgm_state *, const cgm_point *, bool, const char *, uint),
324     cgm_RESTRICTED_TEXT(cgm_state *, const cgm_vdc *, const cgm_vdc *,
325 			const cgm_point *, bool, const char *, uint),
326     cgm_APPEND_TEXT(cgm_state *, bool, const char *, uint),
327     cgm_POLYGON(cgm_state *, const cgm_point *, int),
328     cgm_POLYGON_SET(cgm_state *, const cgm_polygon_edge *, int),
329     cgm_CELL_ARRAY(cgm_state *, const cgm_point * /*[3] */ , cgm_int,
330 		   cgm_int, cgm_int, cgm_cell_representation_mode,
331 		   const byte *, uint, uint),
332     cgm_RECTANGLE(cgm_state *, const cgm_point *, const cgm_point *),
333     cgm_CIRCLE(cgm_state *, const cgm_point *, const cgm_vdc *),
334     cgm_CIRCULAR_ARC_3_POINT(cgm_state *, const cgm_point *,
335 			     const cgm_point *, const cgm_point *),
336     cgm_CIRCULAR_ARC_3_POINT_CLOSE(cgm_state *, const cgm_point *,
337 				   const cgm_point *,
338 				   const cgm_point *, cgm_arc_closure),
339     cgm_CIRCULAR_ARC_CENTER(cgm_state *, const cgm_point *,
340 			    const cgm_vdc *, const cgm_vdc *,
341 			    const cgm_vdc *, const cgm_vdc *,
342 			    const cgm_vdc *),
343     cgm_CIRCULAR_ARC_CENTER_CLOSE(cgm_state *, const cgm_point *,
344 				  const cgm_vdc *, const cgm_vdc *,
345 				  const cgm_vdc *, const cgm_vdc *,
346 				  const cgm_vdc *, cgm_arc_closure),
347     cgm_ELLIPSE(cgm_state *, const cgm_point *, const cgm_point *,
348 		const cgm_point *),
349     cgm_ELLIPTICAL_ARC(cgm_state *, const cgm_point *,
350 		       const cgm_point *, const cgm_point *,
351 		       const cgm_vdc *, const cgm_vdc *,
352 		       const cgm_vdc *, const cgm_vdc *),
353     cgm_ELLIPTICAL_ARC_CLOSE(cgm_state *, const cgm_point *,
354 			     const cgm_point *, const cgm_point *,
355 			     const cgm_vdc *, const cgm_vdc *,
356 			     const cgm_vdc *, const cgm_vdc *,
357 			     cgm_arc_closure);
358 
359 /* ---------------- Attribute elements ---------------- */
360 
361 cgm_result
362     cgm_LINE_BUNDLE_INDEX(cgm_state *, cgm_int),
363     cgm_LINE_TYPE(cgm_state *, cgm_line_type),
364     cgm_LINE_WIDTH(cgm_state *, const cgm_line_width *),
365     cgm_LINE_COLOR(cgm_state *, const cgm_color *),
366     cgm_MARKER_BUNDLE_INDEX(cgm_state *, cgm_int),
367     cgm_MARKER_TYPE(cgm_state *, cgm_marker_type),
368     cgm_MARKER_SIZE(cgm_state *, const cgm_marker_size *),
369     cgm_MARKER_COLOR(cgm_state *, const cgm_color *),
370     cgm_TEXT_BUNDLE_INDEX(cgm_state *, cgm_int),
371     cgm_TEXT_FONT_INDEX(cgm_state *, cgm_int),
372     cgm_TEXT_PRECISION(cgm_state *, cgm_text_precision),
373     cgm_CHARACTER_EXPANSION_FACTOR(cgm_state *, cgm_real),
374     cgm_CHARACTER_SPACING(cgm_state *, cgm_real),
375     cgm_TEXT_COLOR(cgm_state *, const cgm_color *),
376     cgm_CHARACTER_HEIGHT(cgm_state *, const cgm_vdc *),
377     cgm_CHARACTER_ORIENTATION(cgm_state *, const cgm_vdc *,
378 			      const cgm_vdc *, const cgm_vdc *,
379 			      const cgm_vdc *),
380     cgm_TEXT_PATH(cgm_state *, cgm_text_path),
381     cgm_TEXT_ALIGNMENT(cgm_state *, cgm_text_alignment_horizontal,
382 		       cgm_text_alignment_vertical, cgm_real, cgm_real),
383     cgm_CHARACTER_SET_INDEX(cgm_state *, cgm_int),
384     /* The following should be cgm_ALTERNATE_..., but the VAX DEC C */
385     /* compiler gives an error for names longer than 31 characters. */
386     cgm_ALT_CHARACTER_SET_INDEX(cgm_state *, cgm_int),
387     cgm_FILL_BUNDLE_INDEX(cgm_state *, cgm_int),
388     cgm_INTERIOR_STYLE(cgm_state *, cgm_interior_style),
389     cgm_FILL_COLOR(cgm_state *, const cgm_color *),
390     cgm_HATCH_INDEX(cgm_state *, cgm_hatch_index),
391     cgm_PATTERN_INDEX(cgm_state *, cgm_int),
392     cgm_EDGE_BUNDLE_INDEX(cgm_state *, cgm_int),
393     cgm_EDGE_TYPE(cgm_state *, cgm_edge_type),
394     cgm_EDGE_WIDTH(cgm_state *, const cgm_edge_width *),
395     cgm_EDGE_COLOR(cgm_state *, const cgm_color *),
396     cgm_EDGE_VISIBILITY(cgm_state *, bool),
397     cgm_FILL_REFERENCE_POINT(cgm_state *, const cgm_point *),
398     /* PATTERN_TABLE */
399     cgm_PATTERN_SIZE(cgm_state *, const cgm_vdc *, const cgm_vdc *,
400 		     const cgm_vdc *, const cgm_vdc *),
401     cgm_COLOR_TABLE(cgm_state *, cgm_int, const cgm_color *, int),
402     cgm_ASPECT_SOURCE_FLAGS(cgm_state *, const cgm_aspect_source_flag *, int);
403 
404 #endif /* gdevcgml_INCLUDED */
405