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 ReGISPlotter 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 /* Note that ReGIS displays are rectangular, and wider than they are high.
25    In terms of integer ReGIS coordinates a ReGIS display is a
26    [0..767]x[0..479] rectangle, and we choose our viewport to be the square
27    [144..623]x[0..479].  I.e. we define it to be a square, occupying the
28    entire height of the display, and centered on the display. */
29 
30 #include "sys-defines.h"
31 #include "extern.h"
32 
33 #ifndef LIBPLOTTER
34 /* In libplot, this is the initialization for the function-pointer part of
35    a ReGISPlotter struct. */
36 const Plotter _pl_r_default_plotter =
37 {
38   /* initialization (after creation) and termination (before deletion) */
39   _pl_r_initialize, _pl_r_terminate,
40   /* page manipulation */
41   _pl_r_begin_page, _pl_r_erase_page, _pl_r_end_page,
42   /* drawing state manipulation */
43   _pl_g_push_state, _pl_g_pop_state,
44   /* internal path-painting methods (endpath() is a wrapper for the first) */
45   _pl_r_paint_path, _pl_r_paint_paths, _pl_r_path_is_flushable, _pl_r_maybe_prepaint_segments,
46   /* internal methods for drawing of markers and points */
47   _pl_g_paint_marker, _pl_r_paint_point,
48   /* internal methods that plot strings in Hershey, non-Hershey fonts */
49   _pl_g_paint_text_string_with_escapes, _pl_g_paint_text_string,
50   _pl_g_get_text_width,
51   /* private low-level `retrieve font' method */
52   _pl_g_retrieve_font,
53   /* `flush output' method, called only if Plotter handles its own output */
54   _pl_g_flush_output,
55   /* error handlers */
56   _pl_g_warning,
57   _pl_g_error,
58 };
59 #endif /* not LIBPLOTTER */
60 
61 /* The private `initialize' method, which is invoked when a Plotter is
62    created.  It is used for such things as initializing capability flags
63    from the values of class variables, allocating storage, etc.  When this
64    is invoked, _plotter points to the Plotter that has just been
65    created. */
66 
67 void
_pl_r_initialize(S___ (Plotter * _plotter))68 _pl_r_initialize (S___(Plotter *_plotter))
69 {
70 #ifndef LIBPLOTTER
71   /* in libplot, manually invoke superclass initialization method */
72   _pl_g_initialize (S___(_plotter));
73 #endif
74 
75   /* override superclass initializations, as necessary */
76 
77 #ifndef LIBPLOTTER
78   /* tag field, differs in derived classes */
79   _plotter->data->type = PL_REGIS;
80 #endif
81 
82   /* output model */
83   _plotter->data->output_model =  PL_OUTPUT_VIA_CUSTOM_ROUTINES_IN_REAL_TIME;
84 
85   /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
86   _plotter->data->have_wide_lines = 0;
87   _plotter->data->have_dash_array = 0;
88   _plotter->data->have_solid_fill = 1;
89   _plotter->data->have_odd_winding_fill = 1;
90   _plotter->data->have_nonzero_winding_fill = 0;
91   _plotter->data->have_settable_bg = 1;
92   _plotter->data->have_escaped_string_support = 0;
93   _plotter->data->have_ps_fonts = 0;
94   _plotter->data->have_pcl_fonts = 0;
95   _plotter->data->have_stick_fonts = 0;
96   _plotter->data->have_extra_stick_fonts = 0;
97   _plotter->data->have_other_fonts = 0;
98 
99   /* text and font-related parameters (internal, not queryable by user);
100      note that we don't set kern_stick_fonts, because it was set by the
101      superclass initialization (and it's irrelevant for this Plotter type,
102      anyway) */
103   _plotter->data->default_font_type = PL_F_HERSHEY;
104   _plotter->data->pcl_before_ps = false;
105   _plotter->data->have_horizontal_justification = false;
106   _plotter->data->have_vertical_justification = false;
107   _plotter->data->issue_font_warning = true;
108 
109   /* path-related parameters (also internal) */
110   _plotter->data->max_unfilled_path_length = PL_MAX_UNFILLED_PATH_LENGTH;
111   _plotter->data->have_mixed_paths = false;
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_NONE;
116   _plotter->data->allowed_box_scaling = AS_NONE;
117   _plotter->data->allowed_circle_scaling = AS_UNIFORM;
118   _plotter->data->allowed_ellipse_scaling = AS_NONE;
119 
120   /* dimensions */
121   _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
122   _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI;
123   _plotter->data->flipped_y = true;
124   _plotter->data->imin = 144;
125   _plotter->data->imax = 623;
126   _plotter->data->jmin = 479;
127   _plotter->data->jmax = 0;		/* flipped y */
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   /* compute the NDC to device-frame affine map, set it in Plotter */
135   _compute_ndc_to_device_map (_plotter->data);
136 
137   /* initialize data members specific to this derived class */
138   _plotter->regis_pos.x = 0;	/* dummy */
139   _plotter->regis_pos.y = 0;	/* dummy */
140   _plotter->regis_position_is_unknown = true;
141   _plotter->regis_line_type = PL_L_SOLID; /* dummy */
142   _plotter->regis_line_type_is_unknown = true;
143   _plotter->regis_fgcolor = 0; /* dummy */
144   _plotter->regis_bgcolor = 0; /* dummy */
145   _plotter->regis_fgcolor_is_unknown = true;
146   _plotter->regis_bgcolor_is_unknown = true;
147 
148   /* initialize certain data members from device driver parameters */
149 
150 }
151 
152 /* The private `terminate' method, which is invoked when a Plotter is
153    deleted, provided that it is non-NULL.  It may do such things as write
154    to an output stream from internal storage, deallocate storage, etc.
155    When this is invoked, _plotter points to the Plotter that is about to be
156    deleted. */
157 
158 void
_pl_r_terminate(S___ (Plotter * _plotter))159 _pl_r_terminate (S___(Plotter *_plotter))
160 {
161 #ifndef LIBPLOTTER
162   /* invoke generic method, e.g. to deallocate instance-specific copies
163      of class variables */
164   _pl_g_terminate (S___(_plotter));
165 #endif
166 }
167 
168 #ifdef LIBPLOTTER
ReGISPlotter(FILE * infile,FILE * outfile,FILE * errfile)169 ReGISPlotter::ReGISPlotter (FILE *infile, FILE *outfile, FILE *errfile)
170 	:Plotter (infile, outfile, errfile)
171 {
172   _pl_r_initialize ();
173 }
174 
ReGISPlotter(FILE * outfile)175 ReGISPlotter::ReGISPlotter (FILE *outfile)
176 	:Plotter (outfile)
177 {
178   _pl_r_initialize ();
179 }
180 
ReGISPlotter(istream & in,ostream & out,ostream & err)181 ReGISPlotter::ReGISPlotter (istream& in, ostream& out, ostream& err)
182 	: Plotter (in, out, err)
183 {
184   _pl_r_initialize ();
185 }
186 
ReGISPlotter(ostream & out)187 ReGISPlotter::ReGISPlotter (ostream& out)
188 	: Plotter (out)
189 {
190   _pl_r_initialize ();
191 }
192 
ReGISPlotter()193 ReGISPlotter::ReGISPlotter ()
194 {
195   _pl_r_initialize ();
196 }
197 
ReGISPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)198 ReGISPlotter::ReGISPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
199 	:Plotter (infile, outfile, errfile, parameters)
200 {
201   _pl_r_initialize ();
202 }
203 
ReGISPlotter(FILE * outfile,PlotterParams & parameters)204 ReGISPlotter::ReGISPlotter (FILE *outfile, PlotterParams &parameters)
205 	:Plotter (outfile, parameters)
206 {
207   _pl_r_initialize ();
208 }
209 
ReGISPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)210 ReGISPlotter::ReGISPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
211 	: Plotter (in, out, err, parameters)
212 {
213   _pl_r_initialize ();
214 }
215 
ReGISPlotter(ostream & out,PlotterParams & parameters)216 ReGISPlotter::ReGISPlotter (ostream& out, PlotterParams &parameters)
217 	: Plotter (out, parameters)
218 {
219   _pl_r_initialize ();
220 }
221 
ReGISPlotter(PlotterParams & parameters)222 ReGISPlotter::ReGISPlotter (PlotterParams &parameters)
223 	: Plotter (parameters)
224 {
225   _pl_r_initialize ();
226 }
227 
~ReGISPlotter()228 ReGISPlotter::~ReGISPlotter ()
229 {
230   /* if luser left the Plotter open, close it */
231   if (_plotter->data->open)
232     _API_closepl ();
233 
234   _pl_r_terminate ();
235 }
236 #endif
237