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 TekPlotter 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 Tektronix displays are rectangular, and wider than they are
25    high: the aspect ratio is approximately 4:3.  In terms of integer
26    Tektronix coordinates the Tektronix display is a [0..4095]x[0..3119]
27    rectangle, and we choose our viewport to be the square
28    [488..3607]x[0..3119].  I.e. we define it to be a square, occupying the
29    entire height of the display, and centered on the display. */
30 
31 #include "sys-defines.h"
32 #include "extern.h"
33 
34 #ifndef LIBPLOTTER
35 /* In libplot, this is the initialization for the function-pointer part of
36    a TekPlotter struct. */
37 const Plotter _pl_t_default_plotter =
38 {
39   /* initialization (after creation) and termination (before deletion) */
40   _pl_t_initialize, _pl_t_terminate,
41   /* page manipulation */
42   _pl_t_begin_page, _pl_t_erase_page, _pl_t_end_page,
43   /* drawing state manipulation */
44   _pl_g_push_state, _pl_g_pop_state,
45   /* internal path-painting methods (endpath() is a wrapper for the first) */
46   _pl_g_paint_path, _pl_g_paint_paths, _pl_t_path_is_flushable, _pl_t_maybe_prepaint_segments,
47   /* internal methods for drawing of markers and points */
48   _pl_g_paint_marker, _pl_t_paint_point,
49   /* internal methods that plot strings in Hershey, non-Hershey fonts */
50   _pl_g_paint_text_string_with_escapes, _pl_g_paint_text_string,
51   _pl_g_get_text_width,
52   /* private low-level `retrieve font' method */
53   _pl_g_retrieve_font,
54   /* `flush output' method, called only if Plotter handles its own output */
55   _pl_g_flush_output,
56   /* error handlers */
57   _pl_g_warning,
58   _pl_g_error,
59 };
60 #endif /* not LIBPLOTTER */
61 
62 /* The private `initialize' method, which is invoked when a Plotter is
63    created.  It is used for such things as initializing capability flags
64    from the values of class variables, allocating storage, etc.  When this
65    is invoked, _plotter points to the Plotter that has just been
66    created. */
67 
68 void
_pl_t_initialize(S___ (Plotter * _plotter))69 _pl_t_initialize (S___(Plotter *_plotter))
70 {
71 #ifndef LIBPLOTTER
72   /* in libplot, manually invoke superclass initialization method */
73   _pl_g_initialize (S___(_plotter));
74 #endif
75 
76   /* override superclass initializations, as necessary */
77 
78 #ifndef LIBPLOTTER
79   /* tag field, differs in derived classes */
80   _plotter->data->type = PL_TEK;
81 #endif
82 
83   /* output model */
84   _plotter->data->output_model = PL_OUTPUT_VIA_CUSTOM_ROUTINES_IN_REAL_TIME;
85 
86   /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
87   _plotter->data->have_wide_lines = 0;
88   _plotter->data->have_dash_array = 0;
89   _plotter->data->have_solid_fill = 0;
90   _plotter->data->have_odd_winding_fill = 1;
91   _plotter->data->have_nonzero_winding_fill = 1;
92   _plotter->data->have_settable_bg = 0;
93   _plotter->data->have_escaped_string_support = 0;
94   _plotter->data->have_ps_fonts = 0;
95   _plotter->data->have_pcl_fonts = 0;
96   _plotter->data->have_stick_fonts = 0;
97   _plotter->data->have_extra_stick_fonts = 0;
98   _plotter->data->have_other_fonts = 0;
99 
100   /* text and font-related parameters (internal, not queryable by user);
101      note that we don't set kern_stick_fonts, because it was set by the
102      superclass initialization (and it's irrelevant for this Plotter type,
103      anyway) */
104   _plotter->data->default_font_type = PL_F_HERSHEY;
105   _plotter->data->pcl_before_ps = false;
106   _plotter->data->have_horizontal_justification = false;
107   _plotter->data->have_vertical_justification = false;
108   _plotter->data->issue_font_warning = true;
109 
110   /* path-related parameters (also internal) */
111   _plotter->data->max_unfilled_path_length = PL_MAX_UNFILLED_PATH_LENGTH;
112   _plotter->data->have_mixed_paths = false;
113   _plotter->data->allowed_arc_scaling = AS_NONE;
114   _plotter->data->allowed_ellarc_scaling = AS_NONE;
115   _plotter->data->allowed_quad_scaling = AS_NONE;
116   _plotter->data->allowed_cubic_scaling = AS_NONE;
117   _plotter->data->allowed_box_scaling = AS_NONE;
118   _plotter->data->allowed_circle_scaling = AS_NONE;
119   _plotter->data->allowed_ellipse_scaling = AS_NONE;
120 
121   /* dimensions */
122   _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
123   _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI;
124   _plotter->data->flipped_y = false;
125   _plotter->data->imin = 488;
126   _plotter->data->imax = 3607;
127   _plotter->data->jmin = 0;
128   _plotter->data->jmax = 3119;
129   _plotter->data->xmin = 0.0;
130   _plotter->data->xmax = 0.0;
131   _plotter->data->ymin = 0.0;
132   _plotter->data->ymax = 0.0;
133   _plotter->data->page_data = (plPageData *)NULL;
134 
135   /* compute the NDC to device-frame affine map, set it in Plotter */
136   _compute_ndc_to_device_map (_plotter->data);
137 
138   /* initialize data members specific to this derived class */
139   _plotter->tek_display_type = TEK_DPY_GENERIC;
140   _plotter->tek_mode = TEK_MODE_ALPHA;
141   _plotter->tek_line_type = PL_L_SOLID;
142   _plotter->tek_mode_is_unknown = true;
143   _plotter->tek_line_type_is_unknown = true;
144   _plotter->tek_kermit_fgcolor = -1; /* nonsensical value; means `unknown' */
145   _plotter->tek_kermit_bgcolor = -1; /* same */
146   _plotter->tek_position_is_unknown = true;
147   _plotter->tek_pos.x = 0;
148   _plotter->tek_pos.y = 0;
149 
150   /* initialize certain data members from device driver parameters */
151 
152   /* determine Tek display type (xterm(1) / kermit(1) / generic Tektronix);
153      there are so many possible termcap/terminfo names out there that we
154      key only on an initial substring */
155   {
156     const char* term_type;
157 
158     term_type = (const char *)_get_plot_param (_plotter->data, "TERM");
159     if (term_type != NULL)
160       {
161 	if (strncmp (term_type, "xterm", 5) == 0
162 	    || strncmp (term_type, "nxterm", 6) == 0
163 	    || strncmp (term_type, "kterm", 5) == 0)
164 	  _plotter->tek_display_type = TEK_DPY_XTERM;
165 	else if (strncmp (term_type, "ansi.sys", 8) == 0
166 		 || strncmp (term_type, "nansi.sys", 9) == 0
167 		 || strncmp (term_type, "ansisys", 7) == 0 /* undocumented */
168 		 || strncmp (term_type, "kermit", 6) == 0)
169 	  _plotter->tek_display_type = TEK_DPY_KERMIT;
170 	else
171 	  _plotter->tek_display_type = TEK_DPY_GENERIC;
172       }
173     else
174       _plotter->tek_display_type = TEK_DPY_GENERIC; /* default value */
175   }
176 }
177 
178 /* The private `terminate' method, which is invoked when a Plotter is
179    deleted, provided that it is non-NULL.  It may do such things as write
180    to an output stream from internal storage, deallocate storage, etc.
181    When this is invoked, _plotter points to the Plotter that is about to be
182    deleted. */
183 
184 void
_pl_t_terminate(S___ (Plotter * _plotter))185 _pl_t_terminate (S___(Plotter *_plotter))
186 {
187 #ifndef LIBPLOTTER
188   /* in libplot, manually invoke superclass termination method */
189   _pl_g_terminate (S___(_plotter));
190 #endif
191 }
192 
193 #ifdef LIBPLOTTER
TekPlotter(FILE * infile,FILE * outfile,FILE * errfile)194 TekPlotter::TekPlotter (FILE *infile, FILE *outfile, FILE *errfile)
195 	:Plotter (infile, outfile, errfile)
196 {
197   _pl_t_initialize ();
198 }
199 
TekPlotter(FILE * outfile)200 TekPlotter::TekPlotter (FILE *outfile)
201 	:Plotter (outfile)
202 {
203   _pl_t_initialize ();
204 }
205 
TekPlotter(istream & in,ostream & out,ostream & err)206 TekPlotter::TekPlotter (istream& in, ostream& out, ostream& err)
207 	: Plotter (in, out, err)
208 {
209   _pl_t_initialize ();
210 }
211 
TekPlotter(ostream & out)212 TekPlotter::TekPlotter (ostream& out)
213 	: Plotter (out)
214 {
215   _pl_t_initialize ();
216 }
217 
TekPlotter()218 TekPlotter::TekPlotter ()
219 {
220   _pl_t_initialize ();
221 }
222 
TekPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)223 TekPlotter::TekPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
224 	:Plotter (infile, outfile, errfile, parameters)
225 {
226   _pl_t_initialize ();
227 }
228 
TekPlotter(FILE * outfile,PlotterParams & parameters)229 TekPlotter::TekPlotter (FILE *outfile, PlotterParams &parameters)
230 	:Plotter (outfile, parameters)
231 {
232   _pl_t_initialize ();
233 }
234 
TekPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)235 TekPlotter::TekPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
236 	: Plotter (in, out, err, parameters)
237 {
238   _pl_t_initialize ();
239 }
240 
TekPlotter(ostream & out,PlotterParams & parameters)241 TekPlotter::TekPlotter (ostream& out, PlotterParams &parameters)
242 	: Plotter (out, parameters)
243 {
244   _pl_t_initialize ();
245 }
246 
TekPlotter(PlotterParams & parameters)247 TekPlotter::TekPlotter (PlotterParams &parameters)
248 	: Plotter (parameters)
249 {
250   _pl_t_initialize ();
251 }
252 
~TekPlotter()253 TekPlotter::~TekPlotter ()
254 {
255   _pl_t_terminate ();
256 }
257 #endif
258