1 /* This file is part of the GNU plotutils package. Copyright (C) 1995,
2 1996, 1997, 1998, 1999, 2000, 2005, 2008, 2009, Free Software
3 Foundation, Inc.
4
5 The GNU plotutils package is free software. You may redistribute it
6 and/or modify it under the terms of the GNU General Public License as
7 published by the Free Software foundation; either version 2, or (at your
8 option) any later version.
9
10 The GNU plotutils package is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with the GNU plotutils package; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
18 Boston, MA 02110-1301, USA. */
19
20 /* This file defines the initialization for any SVGPlotter object,
21 including both private data and public methods. There is a one-to-one
22 correspondence between public methods and user-callable functions in the
23 C API. */
24
25 #include "sys-defines.h"
26 #include "extern.h"
27
28 #ifndef LIBPLOTTER
29 /* In libplot, this is the initialization for the function-pointer part of
30 a SVGPlotter struct. */
31 const Plotter _pl_s_default_plotter =
32 {
33 /* initialization (after creation) and termination (before deletion) */
34 _pl_s_initialize, _pl_s_terminate,
35 /* page manipulation */
36 _pl_s_begin_page, _pl_s_erase_page, _pl_s_end_page,
37 /* drawing state manipulation */
38 _pl_g_push_state, _pl_g_pop_state,
39 /* internal path-painting methods (endpath() is a wrapper for the first) */
40 _pl_s_paint_path, _pl_s_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
41 /* internal methods for drawing of markers and points */
42 _pl_g_paint_marker, _pl_s_paint_point,
43 /* internal methods that plot strings in Hershey, non-Hershey fonts */
44 _pl_g_paint_text_string_with_escapes, _pl_s_paint_text_string,
45 _pl_g_get_text_width,
46 /* private low-level `retrieve font' method */
47 _pl_g_retrieve_font,
48 /* `flush output' method, called only if Plotter handles its own output */
49 _pl_g_flush_output,
50 /* error handlers */
51 _pl_g_warning,
52 _pl_g_error,
53 };
54 #endif /* not LIBPLOTTER */
55
56 /* The private `initialize' method, which is invoked when a Plotter is
57 created. It is used for such things as initializing capability flags
58 from the values of class variables, allocating storage, etc. When this
59 is invoked, _plotter points to the Plotter that has just been
60 created. */
61
62 void
_pl_s_initialize(S___ (Plotter * _plotter))63 _pl_s_initialize (S___(Plotter *_plotter))
64 {
65 #ifndef LIBPLOTTER
66 /* in libplot, manually invoke superclass initialization method */
67 _pl_g_initialize (S___(_plotter));
68 #endif
69
70 /* override generic initializations (which are appropriate to the base
71 Plotter class), as necessary */
72
73 #ifndef LIBPLOTTER
74 /* tag field, differs in derived classes */
75 _plotter->data->type = PL_SVG;
76 #endif
77
78 /* output model */
79 _plotter->data->output_model = PL_OUTPUT_ONE_PAGE;
80
81 /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
82 _plotter->data->have_wide_lines = 1;
83 _plotter->data->have_dash_array = 1;
84 _plotter->data->have_solid_fill = 1;
85 _plotter->data->have_odd_winding_fill = 1;
86 _plotter->data->have_nonzero_winding_fill = 1;
87 _plotter->data->have_settable_bg = 1;
88 _plotter->data->have_escaped_string_support = 0;
89 _plotter->data->have_ps_fonts = 1;
90 _plotter->data->have_pcl_fonts = 1;
91 _plotter->data->have_stick_fonts = 0;
92 _plotter->data->have_extra_stick_fonts = 0;
93 _plotter->data->have_other_fonts = 0;
94
95 /* text and font-related parameters (internal, not queryable by user);
96 note that we don't set kern_stick_fonts, because it was set by the
97 superclass initialization (and it's irrelevant for this Plotter type,
98 anyway) */
99 _plotter->data->default_font_type = PL_F_POSTSCRIPT;
100 _plotter->data->pcl_before_ps = false;
101 _plotter->data->have_horizontal_justification = false;
102 _plotter->data->have_vertical_justification = false;
103 _plotter->data->issue_font_warning = true;
104
105 /* path-related parameters (also internal); note that we
106 don't set max_unfilled_path_length, because it was set by the
107 superclass initialization */
108 _plotter->data->have_mixed_paths = false;
109 _plotter->data->allowed_arc_scaling = AS_ANY;
110 _plotter->data->allowed_ellarc_scaling = AS_ANY;
111 _plotter->data->allowed_quad_scaling = AS_ANY;
112 _plotter->data->allowed_cubic_scaling = AS_ANY;
113 _plotter->data->allowed_box_scaling = AS_ANY;
114 _plotter->data->allowed_circle_scaling = AS_ANY;
115 _plotter->data->allowed_ellipse_scaling = AS_ANY;
116
117 /* color-related parameters (also internal) */
118 _plotter->data->emulate_color = false;
119
120 /* dimensions */
121 _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
122 _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
123 _plotter->data->flipped_y = true;
124 _plotter->data->imin = 0; /* not used */
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 = 1.0;
130 _plotter->data->ymin = 1.0; /* note flipped y coordinate */
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->s_matrix[0] = 1.0;/* dummy matrix values */
136 _plotter->s_matrix[1] = 0.0;
137 _plotter->s_matrix[2] = 0.0;
138 _plotter->s_matrix[3] = 1.0;
139 _plotter->s_matrix[4] = 0.0;
140 _plotter->s_matrix[5] = 0.0;
141 _plotter->s_matrix_is_unknown = true;
142 _plotter->s_matrix_is_bogus = false;
143 _plotter->s_bgcolor.red = -1; /* initialized in s_begin_page */
144 _plotter->s_bgcolor.green = -1;
145 _plotter->s_bgcolor.blue = -1;
146 _plotter->s_bgcolor_suppressed = false;
147
148 /* Note: xmin,xmax,ymin,ymax determine the range of device coordinates
149 over which the viewport will extend (and hence the transformation from
150 user to device coordinates; see g_space.c).
151
152 For an SVG Plotter, `device coordinates' are usually almost the same
153 as libplot's NDC coordinates, on account of the way we wrap a global
154 transformation matrix around all graphics in the output file; see
155 s_closepl.c. However, SVG uses a flipped-y convention: ymin,ymax are
156 1 and 0 respectively (see above).
157
158 Actually, if the user specifies a negative xsize or ysize as part of
159 the PAGESIZE parameter, we perform an additional flipping, so we can
160 emit nonnegative width and height attributes for the top-level SVG
161 element. We do this additional flipping right now. */
162
163 /* determine page type, and viewport size and location/offset (the
164 viewport size, i.e., (xsize,ysize), will be written out at the head of
165 the SVG file, and the location/offset, i.e., (xorigin,yorigin) and
166 (xoffset,yoffset), will be ignored) */
167 _set_page_type (_plotter->data);
168
169 if (_plotter->data->viewport_xsize < 0.0)
170 /* flip map from user to NDC space */
171 {
172 _plotter->data->xmin = 1.0;
173 _plotter->data->xmax = 0.0;
174 }
175 if (_plotter->data->viewport_ysize < 0.0)
176 /* flip map from user to NDC space */
177 {
178 _plotter->data->ymin = 0.0;
179 _plotter->data->ymax = 1.0;
180 }
181
182 /* compute the NDC to device-frame affine map, set it in Plotter */
183 _compute_ndc_to_device_map (_plotter->data);
184 }
185
186 /* The private `terminate' method, which is invoked when a Plotter is
187 deleted. It may do such things as write to an output stream from
188 internal storage, deallocate storage, etc. When this is invoked,
189 _plotter points to the Plotter that is about to be deleted. */
190
191 void
_pl_s_terminate(S___ (Plotter * _plotter))192 _pl_s_terminate (S___(Plotter *_plotter))
193 {
194 }
195
196 #ifdef LIBPLOTTER
SVGPlotter(FILE * infile,FILE * outfile,FILE * errfile)197 SVGPlotter::SVGPlotter (FILE *infile, FILE *outfile, FILE *errfile)
198 :Plotter (infile, outfile, errfile)
199 {
200 _pl_s_initialize ();
201 }
202
SVGPlotter(FILE * outfile)203 SVGPlotter::SVGPlotter (FILE *outfile)
204 :Plotter (outfile)
205 {
206 _pl_s_initialize ();
207 }
208
SVGPlotter(istream & in,ostream & out,ostream & err)209 SVGPlotter::SVGPlotter (istream& in, ostream& out, ostream& err)
210 : Plotter (in, out, err)
211 {
212 _pl_s_initialize ();
213 }
214
SVGPlotter(ostream & out)215 SVGPlotter::SVGPlotter (ostream& out)
216 : Plotter (out)
217 {
218 _pl_s_initialize ();
219 }
220
SVGPlotter()221 SVGPlotter::SVGPlotter ()
222 {
223 _pl_s_initialize ();
224 }
225
SVGPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)226 SVGPlotter::SVGPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams ¶meters)
227 :Plotter (infile, outfile, errfile, parameters)
228 {
229 _pl_s_initialize ();
230 }
231
SVGPlotter(FILE * outfile,PlotterParams & parameters)232 SVGPlotter::SVGPlotter (FILE *outfile, PlotterParams ¶meters)
233 :Plotter (outfile, parameters)
234 {
235 _pl_s_initialize ();
236 }
237
SVGPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)238 SVGPlotter::SVGPlotter (istream& in, ostream& out, ostream& err, PlotterParams ¶meters)
239 : Plotter (in, out, err, parameters)
240 {
241 _pl_s_initialize ();
242 }
243
SVGPlotter(ostream & out,PlotterParams & parameters)244 SVGPlotter::SVGPlotter (ostream& out, PlotterParams ¶meters)
245 : Plotter (out, parameters)
246 {
247 _pl_s_initialize ();
248 }
249
SVGPlotter(PlotterParams & parameters)250 SVGPlotter::SVGPlotter (PlotterParams ¶meters)
251 : Plotter (parameters)
252 {
253 _pl_s_initialize ();
254 }
255
~SVGPlotter()256 SVGPlotter::~SVGPlotter ()
257 {
258 _pl_s_terminate ();
259 }
260 #endif
261