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 FigPlotter 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 FigPlotter struct. */
30 const Plotter _pl_f_default_plotter =
31 {
32   /* initialization (after creation) and termination (before deletion) */
33   _pl_f_initialize, _pl_f_terminate,
34   /* page manipulation */
35   _pl_f_begin_page, _pl_f_erase_page, _pl_f_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_f_paint_path, _pl_f_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_f_paint_point,
42   /* internal methods that plot strings in Hershey, non-Hershey fonts */
43   _pl_g_paint_text_string_with_escapes, _pl_f_paint_text_string,
44   _pl_g_get_text_width,
45   /* private low-level `retrieve font' method */
46   _pl_f_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 FigPlotter 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. */
64 
65 void
_pl_f_initialize(S___ (Plotter * _plotter))66 _pl_f_initialize (S___(Plotter *_plotter))
67 {
68 #ifndef LIBPLOTTER
69   /* in libplot, manually invoke superclass initialization method */
70   _pl_g_initialize (S___(_plotter));
71 #endif
72 
73   /* override superclass initializations, as necessary */
74 
75 #ifndef LIBPLOTTER
76   /* tag field, differs in derived classes */
77   _plotter->data->type = PL_FIG;
78 #endif
79 
80   /* output model */
81   _plotter->data->output_model = PL_OUTPUT_ONE_PAGE;
82 
83   /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
84   _plotter->data->have_wide_lines = 1;
85   _plotter->data->have_dash_array = 0;
86   _plotter->data->have_solid_fill = 1;
87   _plotter->data->have_odd_winding_fill = 1;
88   _plotter->data->have_nonzero_winding_fill = 0;
89   _plotter->data->have_settable_bg = 0;
90   _plotter->data->have_escaped_string_support = 0;
91   _plotter->data->have_ps_fonts = 1;
92   _plotter->data->have_pcl_fonts = 0;
93   _plotter->data->have_stick_fonts = 0;
94   _plotter->data->have_extra_stick_fonts = 0;
95   _plotter->data->have_other_fonts = 0;
96 
97   /* text and font-related parameters (internal, not queryable by user);
98      note that we don't set kern_stick_fonts, because it was set by the
99      superclass initialization (and it's irrelevant for this Plotter type,
100      anyway) */
101   _plotter->data->default_font_type = PL_F_POSTSCRIPT;
102   _plotter->data->pcl_before_ps = false;
103   _plotter->data->have_horizontal_justification = true;
104   _plotter->data->have_vertical_justification = false;
105   _plotter->data->issue_font_warning = true;
106 
107   /* path-related parameters (also internal); note that we
108      don't set max_unfilled_path_length, because it was set by the
109      superclass initialization */
110   _plotter->data->have_mixed_paths = false;
111   _plotter->data->allowed_arc_scaling = AS_UNIFORM;
112   _plotter->data->allowed_ellarc_scaling = AS_NONE;
113   _plotter->data->allowed_quad_scaling = AS_NONE;
114   _plotter->data->allowed_cubic_scaling = AS_NONE;
115   _plotter->data->allowed_box_scaling = AS_AXES_PRESERVED;
116   _plotter->data->allowed_circle_scaling = AS_UNIFORM;
117   _plotter->data->allowed_ellipse_scaling = AS_ANY;
118 
119   /* dimensions */
120   _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
121   _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI;
122   _plotter->data->flipped_y = true;
123   _plotter->data->imin = 0;
124   _plotter->data->imax = 0;
125   _plotter->data->jmin = 0;
126   _plotter->data->jmax = 0;
127   _plotter->data->xmin = 0.0;
128   _plotter->data->xmax = 0.0;
129   _plotter->data->ymin = 0.0;
130   _plotter->data->ymax = 0.0;
131   _plotter->data->page_data = (plPageData *)NULL;
132 
133   /* initialize data members specific to this derived class */
134   /* dynamic variables */
135   _plotter->fig_drawing_depth = FIG_INITIAL_DEPTH;
136   _plotter->fig_num_usercolors = 0;
137   /* note: this driver also uses fig_usercolors[] */
138   _plotter->fig_colormap_warning_issued = false;
139 
140   /* initialize certain data members from device driver parameters */
141 
142   /* Determine range of device coordinates over which the viewport will
143      extend (and hence the transformation from user to device coordinates;
144      see g_space.c). */
145   {
146     /* determine page type, viewport size and location */
147     _set_page_type (_plotter->data);
148 
149     /* convert viewport size-and-location data (in terms of inches) to
150        device coordinates (i.e. Fig units) */
151     _plotter->data->xmin = (FIG_UNITS_PER_INCH
152 			    * (_plotter->data->viewport_xorigin
153 			       + _plotter->data->viewport_xoffset));
154     _plotter->data->xmax = (FIG_UNITS_PER_INCH
155 			    * (_plotter->data->viewport_xorigin
156 			       + _plotter->data->viewport_xoffset
157 			       + _plotter->data->viewport_xsize));
158 
159     /* Fig coor system has flipped y: y=0 is at the top of the page */
160     _plotter->data->ymin = (FIG_UNITS_PER_INCH
161 			    * (_plotter->data->page_data->ysize
162 			       - (_plotter->data->viewport_yorigin
163 				  + _plotter->data->viewport_yoffset)));
164     _plotter->data->ymax = (FIG_UNITS_PER_INCH
165 			    * (_plotter->data->page_data->ysize
166 				- (_plotter->data->viewport_yorigin
167 				   + _plotter->data->viewport_yoffset
168 				   + _plotter->data->viewport_ysize)));
169   }
170 
171   /* compute the NDC to device-frame affine map, set it in Plotter */
172   _compute_ndc_to_device_map (_plotter->data);
173 }
174 
175 /* The private `terminate' method, which is invoked when a Plotter is
176    deleted.  It may do such things as write to an output stream from
177    internal storage, deallocate storage, etc.  When this is invoked,
178    _plotter points to the Plotter that is about to be deleted. */
179 
180 void
_pl_f_terminate(S___ (Plotter * _plotter))181 _pl_f_terminate (S___(Plotter *_plotter))
182 {
183 #ifndef LIBPLOTTER
184   /* in libplot, manually invoke superclass termination method */
185   _pl_g_terminate (S___(_plotter));
186 #endif
187 }
188 
189 #ifdef LIBPLOTTER
FigPlotter(FILE * infile,FILE * outfile,FILE * errfile)190 FigPlotter::FigPlotter (FILE *infile, FILE *outfile, FILE *errfile)
191 	:Plotter (infile, outfile, errfile)
192 {
193   _pl_f_initialize ();
194 }
195 
FigPlotter(FILE * outfile)196 FigPlotter::FigPlotter (FILE *outfile)
197 	:Plotter (outfile)
198 {
199   _pl_f_initialize ();
200 }
201 
FigPlotter(istream & in,ostream & out,ostream & err)202 FigPlotter::FigPlotter (istream& in, ostream& out, ostream& err)
203 	: Plotter (in, out, err)
204 {
205   _pl_f_initialize ();
206 }
207 
FigPlotter(ostream & out)208 FigPlotter::FigPlotter (ostream& out)
209 	: Plotter (out)
210 {
211   _pl_f_initialize ();
212 }
213 
FigPlotter()214 FigPlotter::FigPlotter ()
215 {
216   _pl_f_initialize ();
217 }
218 
FigPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)219 FigPlotter::FigPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
220 	:Plotter (infile, outfile, errfile, parameters)
221 {
222   _pl_f_initialize ();
223 }
224 
FigPlotter(FILE * outfile,PlotterParams & parameters)225 FigPlotter::FigPlotter (FILE *outfile, PlotterParams &parameters)
226 	:Plotter (outfile, parameters)
227 {
228   _pl_f_initialize ();
229 }
230 
FigPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)231 FigPlotter::FigPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
232 	: Plotter (in, out, err, parameters)
233 {
234   _pl_f_initialize ();
235 }
236 
FigPlotter(ostream & out,PlotterParams & parameters)237 FigPlotter::FigPlotter (ostream& out, PlotterParams &parameters)
238 	: Plotter (out, parameters)
239 {
240   _pl_f_initialize ();
241 }
242 
FigPlotter(PlotterParams & parameters)243 FigPlotter::FigPlotter (PlotterParams &parameters)
244 	: Plotter (parameters)
245 {
246   _pl_f_initialize ();
247 }
248 
~FigPlotter()249 FigPlotter::~FigPlotter ()
250 {
251   _pl_f_terminate ();
252 }
253 #endif
254