f_defplot.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. /* This file defines the initialization for any FigPlotter object,
  16. including both private data and public methods. There is a one-to-one
  17. correspondence between public methods and user-callable functions in the
  18. C API. */
  19. #include "sys-defines.h"
  20. #include "extern.h"
  21. #ifndef LIBPLOTTER
  22. /* In libplot, this is the initialization for the function-pointer part of
  23. a FigPlotter struct. */
  24. const Plotter _pl_f_default_plotter =
  25. {
  26. /* initialization (after creation) and termination (before deletion) */
  27. _pl_f_initialize, _pl_f_terminate,
  28. /* page manipulation */
  29. _pl_f_begin_page, _pl_f_erase_page, _pl_f_end_page,
  30. /* drawing state manipulation */
  31. _pl_g_push_state, _pl_g_pop_state,
  32. /* internal path-painting methods (endpath() is a wrapper for the first) */
  33. _pl_f_paint_path, _pl_f_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
  34. /* internal methods for drawing of markers and points */
  35. _pl_g_paint_marker, _pl_f_paint_point,
  36. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  37. _pl_g_paint_text_string_with_escapes, _pl_f_paint_text_string,
  38. _pl_g_get_text_width,
  39. /* private low-level `retrieve font' method */
  40. _pl_f_retrieve_font,
  41. /* `flush output' method, called only if Plotter handles its own output */
  42. _pl_g_flush_output,
  43. /* error handlers */
  44. _pl_g_warning,
  45. _pl_g_error,
  46. };
  47. #endif /* not LIBPLOTTER */
  48. /* The private `initialize' method, which is invoked when a Plotter is
  49. created. It is used for such things as initializing capability flags
  50. from the values of class variables, allocating storage, etc. When this
  51. is invoked, _plotter points to the Plotter that has just been
  52. created. */
  53. /* For FigPlotter objects, we determine the page size and the location of
  54. the viewport on the page, so that we'll be able to work out the map from
  55. user coordinates to device coordinates in space.c. */
  56. void
  57. _pl_f_initialize (S___(Plotter *_plotter))
  58. {
  59. #ifndef LIBPLOTTER
  60. /* in libplot, manually invoke superclass initialization method */
  61. _pl_g_initialize (S___(_plotter));
  62. #endif
  63. /* override superclass initializations, as necessary */
  64. #ifndef LIBPLOTTER
  65. /* tag field, differs in derived classes */
  66. _plotter->data->type = PL_FIG;
  67. #endif
  68. /* output model */
  69. _plotter->data->output_model = PL_OUTPUT_ONE_PAGE;
  70. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  71. _plotter->data->have_wide_lines = 1;
  72. _plotter->data->have_dash_array = 0;
  73. _plotter->data->have_solid_fill = 1;
  74. _plotter->data->have_odd_winding_fill = 1;
  75. _plotter->data->have_nonzero_winding_fill = 0;
  76. _plotter->data->have_settable_bg = 0;
  77. _plotter->data->have_escaped_string_support = 0;
  78. _plotter->data->have_ps_fonts = 1;
  79. _plotter->data->have_pcl_fonts = 0;
  80. _plotter->data->have_stick_fonts = 0;
  81. _plotter->data->have_extra_stick_fonts = 0;
  82. _plotter->data->have_other_fonts = 0;
  83. /* text and font-related parameters (internal, not queryable by user);
  84. note that we don't set kern_stick_fonts, because it was set by the
  85. superclass initialization (and it's irrelevant for this Plotter type,
  86. anyway) */
  87. _plotter->data->default_font_type = PL_F_POSTSCRIPT;
  88. _plotter->data->pcl_before_ps = false;
  89. _plotter->data->have_horizontal_justification = true;
  90. _plotter->data->have_vertical_justification = false;
  91. _plotter->data->issue_font_warning = true;
  92. /* path-related parameters (also internal); note that we
  93. don't set max_unfilled_path_length, because it was set by the
  94. superclass initialization */
  95. _plotter->data->have_mixed_paths = false;
  96. _plotter->data->allowed_arc_scaling = AS_UNIFORM;
  97. _plotter->data->allowed_ellarc_scaling = AS_NONE;
  98. _plotter->data->allowed_quad_scaling = AS_NONE;
  99. _plotter->data->allowed_cubic_scaling = AS_NONE;
  100. _plotter->data->allowed_box_scaling = AS_AXES_PRESERVED;
  101. _plotter->data->allowed_circle_scaling = AS_UNIFORM;
  102. _plotter->data->allowed_ellipse_scaling = AS_ANY;
  103. /* dimensions */
  104. _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
  105. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI;
  106. _plotter->data->flipped_y = true;
  107. _plotter->data->imin = 0;
  108. _plotter->data->imax = 0;
  109. _plotter->data->jmin = 0;
  110. _plotter->data->jmax = 0;
  111. _plotter->data->xmin = 0.0;
  112. _plotter->data->xmax = 0.0;
  113. _plotter->data->ymin = 0.0;
  114. _plotter->data->ymax = 0.0;
  115. _plotter->data->page_data = (plPageData *)NULL;
  116. /* initialize data members specific to this derived class */
  117. /* dynamic variables */
  118. _plotter->fig_drawing_depth = FIG_INITIAL_DEPTH;
  119. _plotter->fig_num_usercolors = 0;
  120. /* note: this driver also uses fig_usercolors[] */
  121. _plotter->fig_colormap_warning_issued = false;
  122. /* initialize certain data members from device driver parameters */
  123. /* Determine range of device coordinates over which the viewport will
  124. extend (and hence the transformation from user to device coordinates;
  125. see g_space.c). */
  126. {
  127. /* determine page type, viewport size and location */
  128. _set_page_type (_plotter->data);
  129. /* convert viewport size-and-location data (in terms of inches) to
  130. device coordinates (i.e. Fig units) */
  131. _plotter->data->xmin = (FIG_UNITS_PER_INCH
  132. * (_plotter->data->viewport_xorigin
  133. + _plotter->data->viewport_xoffset));
  134. _plotter->data->xmax = (FIG_UNITS_PER_INCH
  135. * (_plotter->data->viewport_xorigin
  136. + _plotter->data->viewport_xoffset
  137. + _plotter->data->viewport_xsize));
  138. /* Fig coor system has flipped y: y=0 is at the top of the page */
  139. _plotter->data->ymin = (FIG_UNITS_PER_INCH
  140. * (_plotter->data->page_data->ysize
  141. - (_plotter->data->viewport_yorigin
  142. + _plotter->data->viewport_yoffset)));
  143. _plotter->data->ymax = (FIG_UNITS_PER_INCH
  144. * (_plotter->data->page_data->ysize
  145. - (_plotter->data->viewport_yorigin
  146. + _plotter->data->viewport_yoffset
  147. + _plotter->data->viewport_ysize)));
  148. }
  149. /* compute the NDC to device-frame affine map, set it in Plotter */
  150. _compute_ndc_to_device_map (_plotter->data);
  151. }
  152. /* The private `terminate' method, which is invoked when a Plotter is
  153. deleted. It may do such things as write to an output stream from
  154. internal storage, deallocate storage, etc. When this is invoked,
  155. _plotter points to the Plotter that is about to be deleted. */
  156. void
  157. _pl_f_terminate (S___(Plotter *_plotter))
  158. {
  159. #ifndef LIBPLOTTER
  160. /* in libplot, manually invoke superclass termination method */
  161. _pl_g_terminate (S___(_plotter));
  162. #endif
  163. }
  164. #ifdef LIBPLOTTER
  165. FigPlotter::FigPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  166. :Plotter (infile, outfile, errfile)
  167. {
  168. _pl_f_initialize ();
  169. }
  170. FigPlotter::FigPlotter (FILE *outfile)
  171. :Plotter (outfile)
  172. {
  173. _pl_f_initialize ();
  174. }
  175. FigPlotter::FigPlotter (istream& in, ostream& out, ostream& err)
  176. : Plotter (in, out, err)
  177. {
  178. _pl_f_initialize ();
  179. }
  180. FigPlotter::FigPlotter (ostream& out)
  181. : Plotter (out)
  182. {
  183. _pl_f_initialize ();
  184. }
  185. FigPlotter::FigPlotter ()
  186. {
  187. _pl_f_initialize ();
  188. }
  189. FigPlotter::FigPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  190. :Plotter (infile, outfile, errfile, parameters)
  191. {
  192. _pl_f_initialize ();
  193. }
  194. FigPlotter::FigPlotter (FILE *outfile, PlotterParams &parameters)
  195. :Plotter (outfile, parameters)
  196. {
  197. _pl_f_initialize ();
  198. }
  199. FigPlotter::FigPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  200. : Plotter (in, out, err, parameters)
  201. {
  202. _pl_f_initialize ();
  203. }
  204. FigPlotter::FigPlotter (ostream& out, PlotterParams &parameters)
  205. : Plotter (out, parameters)
  206. {
  207. _pl_f_initialize ();
  208. }
  209. FigPlotter::FigPlotter (PlotterParams &parameters)
  210. : Plotter (parameters)
  211. {
  212. _pl_f_initialize ();
  213. }
  214. FigPlotter::~FigPlotter ()
  215. {
  216. _pl_f_terminate ();
  217. }
  218. #endif