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 MetaPlotter object,
20 including 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 a MetaPlotter struct. */
30 const Plotter _pl_m_default_plotter =
31 {
32 /* initialization (after creation) and termination (before deletion) */
33 _pl_m_initialize, _pl_m_terminate,
34 /* page manipulation */
35 _pl_m_begin_page, _pl_m_erase_page, _pl_m_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_m_paint_path, _pl_m_paint_paths, _pl_m_path_is_flushable, _pl_m_maybe_prepaint_segments,
40 /* internal methods for drawing of markers and points */
41 _pl_m_paint_marker, _pl_m_paint_point,
42 /* internal methods that plot strings in Hershey, non-Hershey fonts */
43 _pl_m_paint_text_string_with_escapes, _pl_g_paint_text_string,
44 _pl_g_get_text_width,
45 /* internal `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 /* internal `error handler' methods */
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 void
_pl_m_initialize(S___ (Plotter * _plotter))62 _pl_m_initialize (S___(Plotter *_plotter))
63 {
64 #ifndef LIBPLOTTER
65 /* in libplot, manually invoke superclass initialization method */
66 _pl_g_initialize (S___(_plotter));
67 #endif
68
69 /* override superclass initializations, as necessary */
70
71 #ifndef LIBPLOTTER
72 /* tag field, differs in derived classes */
73 _plotter->data->type = PL_META;
74 #endif
75
76 /* output model */
77 _plotter->data->output_model = PL_OUTPUT_VIA_CUSTOM_ROUTINES_IN_REAL_TIME;
78
79 /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
80 _plotter->data->have_wide_lines = 2;
81 _plotter->data->have_dash_array = 2;
82 _plotter->data->have_solid_fill = 2;
83 _plotter->data->have_odd_winding_fill = 2;
84 _plotter->data->have_nonzero_winding_fill = 2;
85 _plotter->data->have_settable_bg = 2;
86 _plotter->data->have_escaped_string_support = 1;
87 _plotter->data->have_ps_fonts = 1;
88 _plotter->data->have_pcl_fonts = 1;
89 _plotter->data->have_stick_fonts = 1;
90 _plotter->data->have_extra_stick_fonts = 1;
91 _plotter->data->have_other_fonts = 1;
92
93 /* text and font-related parameters (internal, not queryable by user);
94 note that we don't set kern_stick_fonts, because it was set by the
95 superclass initialization (and it's irrelevant for this Plotter type,
96 anyway) */
97 _plotter->data->default_font_type = PL_F_HERSHEY;
98 _plotter->data->pcl_before_ps = false;
99 _plotter->data->have_horizontal_justification = true;
100 _plotter->data->have_vertical_justification = true;
101 _plotter->data->issue_font_warning = true;
102
103 /* path-related parameters (also internal) */
104 _plotter->data->max_unfilled_path_length = PL_MAX_UNFILLED_PATH_LENGTH;
105 _plotter->data->have_mixed_paths = true;
106 _plotter->data->allowed_arc_scaling = AS_ANY;
107 _plotter->data->allowed_ellarc_scaling = AS_ANY;
108 _plotter->data->allowed_quad_scaling = AS_ANY;
109 _plotter->data->allowed_cubic_scaling = AS_ANY;
110 _plotter->data->allowed_box_scaling = AS_ANY;
111 _plotter->data->allowed_circle_scaling = AS_ANY;
112 _plotter->data->allowed_ellipse_scaling = AS_ANY;
113
114 /* dimensions */
115 _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
116 _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
117 _plotter->data->flipped_y = false;
118 _plotter->data->imin = 0;
119 _plotter->data->imax = 0;
120 _plotter->data->jmin = 0;
121 _plotter->data->jmax = 0;
122 _plotter->data->xmin = 0.0;
123 _plotter->data->xmax = 1.0;
124 _plotter->data->ymin = 0.0;
125 _plotter->data->ymax = 1.0;
126 _plotter->data->page_data = (plPageData *)NULL;
127
128 /* compute the NDC to device-frame affine map, set it in Plotter */
129 _compute_ndc_to_device_map (_plotter->data);
130
131 /* initialize data members specific to this derived class */
132 /* parameters */
133 _plotter->meta_portable_output = false;
134 /* dynamic variables */
135 _plotter->meta_pos.x = 0.0;
136 _plotter->meta_pos.y = 0.0;
137 _plotter->meta_position_is_unknown = false;
138 _plotter->meta_m_user_to_ndc[0] = 1.0;
139 _plotter->meta_m_user_to_ndc[1] = 0.0;
140 _plotter->meta_m_user_to_ndc[2] = 0.0;
141 _plotter->meta_m_user_to_ndc[3] = 1.0;
142 _plotter->meta_m_user_to_ndc[4] = 0.0;
143 _plotter->meta_m_user_to_ndc[5] = 0.0;
144 _plotter->meta_fill_rule_type = PL_FILL_ODD_WINDING;
145 _plotter->meta_line_type = PL_L_SOLID;
146 _plotter->meta_points_are_connected = true;
147 _plotter->meta_cap_type = PL_CAP_BUTT;
148 _plotter->meta_join_type = PL_JOIN_MITER;
149 _plotter->meta_miter_limit = PL_DEFAULT_MITER_LIMIT;
150 _plotter->meta_line_width = 0.0;
151 _plotter->meta_line_width_is_default = true;
152 _plotter->meta_dash_array = (const double *)NULL;
153 _plotter->meta_dash_array_len = 0;
154 _plotter->meta_dash_offset = 0.0;
155 _plotter->meta_dash_array_in_effect = false;
156 _plotter->meta_pen_type = 1;
157 _plotter->meta_fill_type = 0;
158 _plotter->meta_orientation = 1;
159 _plotter->meta_font_name = (const char *)NULL;
160 _plotter->meta_font_size = 0.0;
161 _plotter->meta_font_size_is_default = true;
162 _plotter->meta_text_rotation = 0.0;
163 _plotter->meta_fgcolor.red = 0;
164 _plotter->meta_fgcolor.green = 0;
165 _plotter->meta_fgcolor.blue = 0;
166 _plotter->meta_fillcolor_base.red = 0;
167 _plotter->meta_fillcolor_base.green = 0;
168 _plotter->meta_fillcolor_base.blue = 0;
169 _plotter->meta_bgcolor.red = 65535;
170 _plotter->meta_bgcolor.green = 65535;
171 _plotter->meta_bgcolor.blue = 65535;
172
173 /* initialize certain data members from device driver parameters */
174
175 /* determine version of metafile format */
176 {
177 const char *portable_s;
178
179 portable_s = (const char *)_get_plot_param (_plotter->data,
180 "META_PORTABLE");
181 if (strcasecmp (portable_s, "yes") == 0)
182 _plotter->meta_portable_output = true;
183 else
184 _plotter->meta_portable_output = false; /* default value */
185 }
186 }
187
188 /* The private `terminate' method, which is invoked when a Plotter is
189 deleted. It may do such things as write to an output stream from
190 internal storage, deallocate storage, etc. When this is invoked,
191 _plotter points to the Plotter that is about to be deleted. */
192
193 void
_pl_m_terminate(S___ (Plotter * _plotter))194 _pl_m_terminate (S___(Plotter *_plotter))
195 {
196 #ifndef LIBPLOTTER
197 /* in libplot, manually invoke superclass termination method */
198 _pl_g_terminate (S___(_plotter));
199 #endif
200 }
201
202 #ifdef LIBPLOTTER
MetaPlotter(FILE * infile,FILE * outfile,FILE * errfile)203 MetaPlotter::MetaPlotter (FILE *infile, FILE *outfile, FILE *errfile)
204 : Plotter (infile, outfile, errfile)
205 {
206 _pl_m_initialize ();
207 }
208
MetaPlotter(FILE * outfile)209 MetaPlotter::MetaPlotter (FILE *outfile)
210 : Plotter (outfile)
211 {
212 _pl_m_initialize ();
213 }
214
MetaPlotter(istream & in,ostream & out,ostream & err)215 MetaPlotter::MetaPlotter (istream& in, ostream& out, ostream& err)
216 : Plotter (in, out, err)
217 {
218 _pl_m_initialize ();
219 }
220
MetaPlotter(ostream & out)221 MetaPlotter::MetaPlotter (ostream& out)
222 : Plotter (out)
223 {
224 _pl_m_initialize ();
225 }
226
MetaPlotter()227 MetaPlotter::MetaPlotter ()
228 {
229 _pl_m_initialize ();
230 }
231
MetaPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)232 MetaPlotter::MetaPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams ¶meters)
233 :Plotter (infile, outfile, errfile, parameters)
234 {
235 _pl_m_initialize ();
236 }
237
MetaPlotter(FILE * outfile,PlotterParams & parameters)238 MetaPlotter::MetaPlotter (FILE *outfile, PlotterParams ¶meters)
239 :Plotter (outfile, parameters)
240 {
241 _pl_m_initialize ();
242 }
243
MetaPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)244 MetaPlotter::MetaPlotter (istream& in, ostream& out, ostream& err, PlotterParams ¶meters)
245 : Plotter (in, out, err, parameters)
246 {
247 _pl_m_initialize ();
248 }
249
MetaPlotter(ostream & out,PlotterParams & parameters)250 MetaPlotter::MetaPlotter (ostream& out, PlotterParams ¶meters)
251 : Plotter (out, parameters)
252 {
253 _pl_m_initialize ();
254 }
255
MetaPlotter(PlotterParams & parameters)256 MetaPlotter::MetaPlotter (PlotterParams ¶meters)
257 : Plotter (parameters)
258 {
259 _pl_m_initialize ();
260 }
261
~MetaPlotter()262 MetaPlotter::~MetaPlotter ()
263 {
264 /* if luser left the Plotter open, close it */
265 if (_plotter->data->open)
266 _API_closepl ();
267
268 _pl_m_terminate ();
269 }
270 #endif
271