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 PNG Plotter 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 PNGPlotter struct.  It is the same as for a BitmapPlotter, except for
30    the routines _pl_z_initialize and _pl_z_terminate. */
31 const Plotter _pl_z_default_plotter =
32 {
33   /* initialization (after creation) and termination (before deletion) */
34   _pl_z_initialize, _pl_z_terminate,
35   /* page manipulation */
36   _pl_b_begin_page, _pl_b_erase_page, _pl_b_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_b_paint_path, _pl_b_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_b_paint_point,
43   /* internal methods that plot strings in Hershey, non-Hershey fonts */
44   _pl_g_paint_text_string_with_escapes, _pl_g_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_z_initialize(S___ (Plotter * _plotter))63 _pl_z_initialize (S___(Plotter *_plotter))
64 {
65 #ifndef LIBPLOTTER
66   /* in libplot, manually invoke superclass initialization method */
67   _pl_b_initialize (S___(_plotter));
68 #endif
69 
70   /* override superclass initializations, as necessary */
71 
72 #ifndef LIBPLOTTER
73   /* tag field, differs in derived classes */
74   _plotter->data->type = PL_PNG;
75 #endif
76 
77   /* output model */
78   _plotter->data->output_model = PL_OUTPUT_VIA_CUSTOM_ROUTINES;
79 
80   /* initialize data members specific to this derived class */
81   /* parameters */
82   _plotter->z_interlace = false;
83   _plotter->z_transparent = false;
84   _plotter->z_transparent_color.red = 255; /* dummy */
85   _plotter->z_transparent_color.green = 255; /* dummy */
86   _plotter->z_transparent_color.blue = 255; /* dummy */
87 
88   /* initialize certain data members from device driver parameters */
89 
90   /* produce an interlaced PNG? */
91   {
92     const char *interlace_s;
93 
94     interlace_s = (const char *)_get_plot_param (_plotter->data, "INTERLACE" );
95     if (strcasecmp (interlace_s, "yes") == 0)
96       _plotter->z_interlace = true;
97   }
98 
99   /* is there a user-specified transparent color? */
100   {
101     const char *transparent_name_s;
102     plColor color;
103 
104     transparent_name_s = (const char *)_get_plot_param (_plotter->data, "TRANSPARENT_COLOR");
105     if (transparent_name_s
106 	&& _string_to_color (transparent_name_s, &color, _plotter->data->color_name_cache))
107       /* have 24-bit RGB */
108       {
109 	_plotter->z_transparent = true;
110 	_plotter->z_transparent_color = color;
111       }
112   }
113 }
114 
115 /* The private `terminate' method, which is invoked when a Plotter is
116    deleted.  It may do such things as write to an output stream from
117    internal storage, deallocate storage, etc.  When this is invoked,
118    _plotter points (temporarily) to the Plotter that is about to be
119    deleted. */
120 
121 void
_pl_z_terminate(S___ (Plotter * _plotter))122 _pl_z_terminate (S___(Plotter *_plotter))
123 {
124 #ifndef LIBPLOTTER
125   /* in libplot, manually invoke superclass termination method */
126   _pl_b_terminate (S___(_plotter));
127 #endif
128 }
129 
130 #ifdef LIBPLOTTER
PNGPlotter(FILE * infile,FILE * outfile,FILE * errfile)131 PNGPlotter::PNGPlotter (FILE *infile, FILE *outfile, FILE *errfile)
132 	: BitmapPlotter (infile, outfile, errfile)
133 {
134   _pl_z_initialize ();
135 }
136 
PNGPlotter(FILE * outfile)137 PNGPlotter::PNGPlotter (FILE *outfile)
138 	: BitmapPlotter (outfile)
139 {
140   _pl_z_initialize ();
141 }
142 
PNGPlotter(istream & in,ostream & out,ostream & err)143 PNGPlotter::PNGPlotter (istream& in, ostream& out, ostream& err)
144 	: BitmapPlotter (in, out, err)
145 {
146   _pl_z_initialize ();
147 }
148 
PNGPlotter(ostream & out)149 PNGPlotter::PNGPlotter (ostream& out)
150 	: BitmapPlotter (out)
151 {
152   _pl_z_initialize ();
153 }
154 
PNGPlotter()155 PNGPlotter::PNGPlotter ()
156 {
157   _pl_z_initialize ();
158 }
159 
PNGPlotter(FILE * infile,FILE * outfile,FILE * errfile,PlotterParams & parameters)160 PNGPlotter::PNGPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
161 	: BitmapPlotter (infile, outfile, errfile, parameters)
162 {
163   _pl_z_initialize ();
164 }
165 
PNGPlotter(FILE * outfile,PlotterParams & parameters)166 PNGPlotter::PNGPlotter (FILE *outfile, PlotterParams &parameters)
167 	: BitmapPlotter (outfile, parameters)
168 {
169   _pl_z_initialize ();
170 }
171 
PNGPlotter(istream & in,ostream & out,ostream & err,PlotterParams & parameters)172 PNGPlotter::PNGPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
173 	: BitmapPlotter (in, out, err, parameters)
174 {
175   _pl_z_initialize ();
176 }
177 
PNGPlotter(ostream & out,PlotterParams & parameters)178 PNGPlotter::PNGPlotter (ostream& out, PlotterParams &parameters)
179 	: BitmapPlotter (out, parameters)
180 {
181   _pl_z_initialize ();
182 }
183 
PNGPlotter(PlotterParams & parameters)184 PNGPlotter::PNGPlotter (PlotterParams &parameters)
185 	: BitmapPlotter (parameters)
186 {
187   _pl_z_initialize ();
188 }
189 
~PNGPlotter()190 PNGPlotter::~PNGPlotter ()
191 {
192   _pl_z_terminate ();
193 }
194 #endif
195