1 /* This file is part of the GNU plotutils package. Copyright (C) 1995,
2 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
3
4 The GNU plotutils package is free software. You may redistribute it
5 and/or modify it under the terms of the GNU General Public License as
6 published by the Free Software foundation; either version 2, or (at your
7 option) any later version.
8
9 The GNU plotutils package is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with the GNU plotutils package; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17 Boston, MA 02110-1301, USA. */
18
19 /* This file defines the initialization for any AIPlotter object, including
20 both private data and public methods. There is a one-to-one
21 correspondence between public methods and user-callable functions in the
22 C API. */
23
24 #include "sys-defines.h"
25 #include "extern.h"
26
27 #ifndef LIBPLOTTER
28 /* In libplot, this is the initialization for the function-pointer part of
29 an AIPlotter struct. */
30 const Plotter _pl_a_default_plotter =
31 {
32 /* initialization (after creation) and termination (before deletion) */
33 _pl_a_initialize, _pl_a_terminate,
34 /* page manipulation */
35 _pl_a_begin_page, _pl_a_erase_page, _pl_a_end_page,
36 /* drawing state manipulation */
37 _pl_g_push_state, _pl_g_pop_state,
38 /* internal path-painting methods (endpath() is a wrapper for the first) */
39 _pl_a_paint_path, _pl_a_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
40 /* internal methods for drawing of markers and points */
41 _pl_g_paint_marker, _pl_a_paint_point,
42 /* internal methods that plot strings in Hershey, non-Hershey fonts */
43 _pl_g_paint_text_string_with_escapes, _pl_a_paint_text_string,
44 _pl_g_get_text_width,
45 /* private low-level `retrieve font' method */
46 _pl_g_retrieve_font,
47 /* `flush output' method, called only if Plotter handles its own output */
48 _pl_g_flush_output,
49 /* error handlers */
50 _pl_g_warning,
51 _pl_g_error,
52 };
53 #endif /* not LIBPLOTTER */
54
55 /* The private `initialize' method, which is invoked when a Plotter is
56 created. It is used for such things as initializing capability flags
57 from the values of class variables, allocating storage, etc. When this
58 is invoked, _plotter points to the Plotter that has just been
59 created. */
60
61 /* For AI Plotter objects, we determine the page size and the location of
62 the viewport on the page, so that we'll be able to work out the map from
63 user coordinates to device coordinates in space.c. Also we determine
64 which version of Illustrator file format we'll emit. */
65
66 void
_pl_a_initialize(S___ (Plotter * _plotter))67 _pl_a_initialize (S___(Plotter *_plotter))
68 {
69 #ifndef LIBPLOTTER
70 /* in libplot, manually invoke superclass initialization method */
71 _pl_g_initialize (S___(_plotter));
72 #endif
73
74 /* override superclass initializations, as necessary */
75
76 #ifndef LIBPLOTTER
77 /* tag field, differs in derived classes */
78 _plotter->data->type = PL_AI;
79 #endif
80
81 /* output model */
82 _plotter->data->output_model = PL_OUTPUT_ONE_PAGE;
83
84 /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
85 _plotter->data->have_wide_lines = 1;
86 _plotter->data->have_dash_array = 1;
87 _plotter->data->have_solid_fill = 1;
88 _plotter->data->have_odd_winding_fill = 1;
89 _plotter->data->have_nonzero_winding_fill = 1;
90 _plotter->data->have_settable_bg = 0;
91 _plotter->data->have_escaped_string_support = 0;
92 _plotter->data->have_ps_fonts = 1;
93 _plotter->data->have_pcl_fonts = 1;
94 _plotter->data->have_stick_fonts = 0;
95 _plotter->data->have_extra_stick_fonts = 0;
96 _plotter->data->have_other_fonts = 0;
97
98 /* text and font-related parameters (internal, not queryable by user);
99 note that we don't set kern_stick_fonts, because it was set by the
100 superclass initialization (and it's irrelevant for this Plotter type,
101 anyway) */
102 _plotter->data->default_font_type = PL_F_POSTSCRIPT;
103 _plotter->data->pcl_before_ps = false;
104 _plotter->data->issue_font_warning = true;
105 _plotter->data->have_horizontal_justification = true;
106 _plotter->data->have_vertical_justification = false;
107
108 /* path-related parameters (also internal); note that we
109 don't set max_unfilled_path_length, because it was set by the
110 superclass initialization */
111 _plotter->data->have_mixed_paths = true;
112 _plotter->data->allowed_arc_scaling = AS_NONE;
113 _plotter->data->allowed_ellarc_scaling = AS_NONE;
114 _plotter->data->allowed_quad_scaling = AS_NONE;
115 _plotter->data->allowed_cubic_scaling = AS_ANY;
116 _plotter->data->allowed_box_scaling = AS_NONE;
117 _plotter->data->allowed_circle_scaling = AS_NONE;
118 _plotter->data->allowed_ellipse_scaling = AS_NONE;
119
120 /* dimensions */
121 _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
122 _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
123 _plotter->data->flipped_y = false;
124 _plotter->data->imin = 0;
125 _plotter->data->imax = 0;
126 _plotter->data->jmin = 0;
127 _plotter->data->jmax = 0;
128 _plotter->data->xmin = 0.0;
129 _plotter->data->xmax = 0.0;
130 _plotter->data->ymin = 0.0;
131 _plotter->data->ymax = 0.0;
132 _plotter->data->page_data = (plPageData *)NULL;
133
134 /* initialize data members specific to this derived class */
135 _plotter->ai_version = AI_VERSION_5;
136 _plotter->ai_pen_cyan = 0.0;
137 _plotter->ai_pen_magenta = 0.0;
138 _plotter->ai_pen_yellow = 0.0;
139 _plotter->ai_pen_black = 1.0;
140 _plotter->ai_fill_cyan = 0.0;
141 _plotter->ai_fill_magenta = 0.0;
142 _plotter->ai_fill_yellow = 0.0;
143 _plotter->ai_fill_black = 1.0;
144 _plotter->ai_cyan_used = false;
145 _plotter->ai_magenta_used = false;
146 _plotter->ai_yellow_used = false;
147 _plotter->ai_black_used = false;
148 _plotter->ai_cap_style = AI_LINE_CAP_BUTT;
149 _plotter->ai_join_style = AI_LINE_JOIN_MITER;
150 /* Maximum value the cosecant of the half-angle between any two line
151 segments can have, if the join is to be mitered rather than beveled.
152 Default value for AI is 4.0. */
153 _plotter->ai_miter_limit = 4.0;
154 _plotter->ai_line_type = PL_L_SOLID;
155 _plotter->ai_line_width = 1.0;
156 _plotter->ai_fill_rule_type = 0; /* i.e. nonzero winding number rule */
157
158 /* initialize certain data members from device driver parameters */
159
160 /* determine which version of AI format we'll emit (obsolescent) */
161 {
162 const char *version_s;
163
164 version_s = (const char *)_get_plot_param (_plotter->data, "AI_VERSION");
165 if (strcmp (version_s, "3") == 0)
166 _plotter->ai_version = AI_VERSION_3;
167 else if (strcmp (version_s, "5") == 0)
168 _plotter->ai_version = AI_VERSION_5;
169 else
170 {
171 version_s = (const char *)_get_default_plot_param ("AI_VERSION");
172 if (strcmp (version_s, "3") == 0)
173 _plotter->ai_version = AI_VERSION_3;
174 else if (strcmp (version_s, "5") == 0)
175 _plotter->ai_version = AI_VERSION_5;
176 }
177 }
178 /* AI didn't support even-odd fill until version 5 */
179 if (_plotter->ai_version == AI_VERSION_3)
180 _plotter->data->have_odd_winding_fill = 0;
181
182 /* Determine range of device coordinates over which the viewport will
183 extend (and hence the transformation from user to device coordinates;
184 see g_space.c). */
185 {
186 /* determine page type, viewport size and location */
187 _set_page_type (_plotter->data);
188
189 /* convert viewport size-and-location data (in terms of inches) to
190 device coordinates (i.e. points) */
191 _plotter->data->xmin = 72 * (_plotter->data->viewport_xorigin
192 + _plotter->data->viewport_xoffset);
193 _plotter->data->xmax = 72 * (_plotter->data->viewport_xorigin
194 + _plotter->data->viewport_xoffset
195 + _plotter->data->viewport_xsize);
196
197 _plotter->data->ymin = 72 * (_plotter->data->viewport_yorigin
198 + _plotter->data->viewport_yoffset);
199 _plotter->data->ymax = 72 * (_plotter->data->viewport_yorigin
200 + _plotter->data->viewport_yoffset
201 + _plotter->data->viewport_ysize);
202 }
203
204 /* compute the NDC to device-frame affine map, set it in Plotter */
205 _compute_ndc_to_device_map (_plotter->data);
206 }
207
208 /* The private `terminate' method, which is invoked when a Plotter is
209 deleted. It may do such things as write to an output stream from
210 internal storage, deallocate storage, etc. When this is invoked,
211 _plotter points to the Plotter that is about to be deleted. */
212
213 void
_pl_a_terminate(S___ (Plotter * _plotter))214 _pl_a_terminate (S___(Plotter *_plotter))
215 {
216 #ifndef LIBPLOTTER
217 /* in libplot, manually invoke superclass termination method */
218 _pl_g_terminate (S___(_plotter));
219 #endif
220 }
221
222 #ifdef LIBPLOTTER
AIPlotter(FILE * infile,FILE * outfile,FILE * errfile)223 AIPlotter::AIPlotter (FILE *infile, FILE *outfile, FILE *errfile)
224 :Plotter (infile, outfile, errfile)
225 {
226 _pl_a_initialize ();
227 }
228
AIPlotter(FILE * outfile)229 AIPlotter::AIPlotter (FILE *outfile)
230 :Plotter (outfile)
231 {
232 _pl_a_initialize ();
233 }
234
AIPlotter(istream & in,ostream & out,ostream & err)235 AIPlotter::AIPlotter (istream& in, ostream& out, ostream& err)
236 : Plotter (in, out, err)
237 {
238 _pl_a_initialize ();
239 }
240
AIPlotter(ostream & out)241 AIPlotter::AIPlotter (ostream& out)
242 : Plotter (out)
243 {
244 _pl_a_initialize ();
245 }
246
AIPlotter()247 AIPlotter::AIPlotter ()
248 {
249 _pl_a_initialize ();
250 }
251
AIPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)252 AIPlotter::AIPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams ¶meters)
253 :Plotter (infile, outfile, errfile, parameters)
254 {
255 _pl_a_initialize ();
256 }
257
AIPlotter(FILE * outfile,PlotterParams & parameters)258 AIPlotter::AIPlotter (FILE *outfile, PlotterParams ¶meters)
259 :Plotter (outfile, parameters)
260 {
261 _pl_a_initialize ();
262 }
263
AIPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)264 AIPlotter::AIPlotter (istream& in, ostream& out, ostream& err, PlotterParams ¶meters)
265 : Plotter (in, out, err, parameters)
266 {
267 _pl_a_initialize ();
268 }
269
AIPlotter(ostream & out,PlotterParams & parameters)270 AIPlotter::AIPlotter (ostream& out, PlotterParams ¶meters)
271 : Plotter (out, parameters)
272 {
273 _pl_a_initialize ();
274 }
275
AIPlotter(PlotterParams & parameters)276 AIPlotter::AIPlotter (PlotterParams ¶meters)
277 : Plotter (parameters)
278 {
279 _pl_a_initialize ();
280 }
281
~AIPlotter()282 AIPlotter::~AIPlotter ()
283 {
284 /* if luser left the Plotter open, close it */
285 if (_plotter->data->open)
286 _API_closepl ();
287
288 _pl_a_terminate ();
289 }
290 #endif
291