m_defplot.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 MetaPlotter 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 MetaPlotter struct. */
  24. const Plotter _pl_m_default_plotter =
  25. {
  26. /* initialization (after creation) and termination (before deletion) */
  27. _pl_m_initialize, _pl_m_terminate,
  28. /* page manipulation */
  29. _pl_m_begin_page, _pl_m_erase_page, _pl_m_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_m_paint_path, _pl_m_paint_paths, _pl_m_path_is_flushable, _pl_m_maybe_prepaint_segments,
  34. /* internal methods for drawing of markers and points */
  35. _pl_m_paint_marker, _pl_m_paint_point,
  36. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  37. _pl_m_paint_text_string_with_escapes, _pl_g_paint_text_string,
  38. _pl_g_get_text_width,
  39. /* internal `retrieve font' method */
  40. _pl_g_retrieve_font,
  41. /* `flush output' method, called only if Plotter handles its own output */
  42. _pl_g_flush_output,
  43. /* internal `error handler' methods */
  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. void
  54. _pl_m_initialize (S___(Plotter *_plotter))
  55. {
  56. #ifndef LIBPLOTTER
  57. /* in libplot, manually invoke superclass initialization method */
  58. _pl_g_initialize (S___(_plotter));
  59. #endif
  60. /* override superclass initializations, as necessary */
  61. #ifndef LIBPLOTTER
  62. /* tag field, differs in derived classes */
  63. _plotter->data->type = PL_META;
  64. #endif
  65. /* output model */
  66. _plotter->data->output_model = PL_OUTPUT_VIA_CUSTOM_ROUTINES_IN_REAL_TIME;
  67. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  68. _plotter->data->have_wide_lines = 2;
  69. _plotter->data->have_dash_array = 2;
  70. _plotter->data->have_solid_fill = 2;
  71. _plotter->data->have_odd_winding_fill = 2;
  72. _plotter->data->have_nonzero_winding_fill = 2;
  73. _plotter->data->have_settable_bg = 2;
  74. _plotter->data->have_escaped_string_support = 1;
  75. _plotter->data->have_ps_fonts = 1;
  76. _plotter->data->have_pcl_fonts = 1;
  77. _plotter->data->have_stick_fonts = 1;
  78. _plotter->data->have_extra_stick_fonts = 1;
  79. _plotter->data->have_other_fonts = 1;
  80. /* text and font-related parameters (internal, not queryable by user);
  81. note that we don't set kern_stick_fonts, because it was set by the
  82. superclass initialization (and it's irrelevant for this Plotter type,
  83. anyway) */
  84. _plotter->data->default_font_type = PL_F_HERSHEY;
  85. _plotter->data->pcl_before_ps = false;
  86. _plotter->data->have_horizontal_justification = true;
  87. _plotter->data->have_vertical_justification = true;
  88. _plotter->data->issue_font_warning = true;
  89. /* path-related parameters (also internal) */
  90. _plotter->data->max_unfilled_path_length = PL_MAX_UNFILLED_PATH_LENGTH;
  91. _plotter->data->have_mixed_paths = true;
  92. _plotter->data->allowed_arc_scaling = AS_ANY;
  93. _plotter->data->allowed_ellarc_scaling = AS_ANY;
  94. _plotter->data->allowed_quad_scaling = AS_ANY;
  95. _plotter->data->allowed_cubic_scaling = AS_ANY;
  96. _plotter->data->allowed_box_scaling = AS_ANY;
  97. _plotter->data->allowed_circle_scaling = AS_ANY;
  98. _plotter->data->allowed_ellipse_scaling = AS_ANY;
  99. /* dimensions */
  100. _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
  101. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
  102. _plotter->data->flipped_y = false;
  103. _plotter->data->imin = 0;
  104. _plotter->data->imax = 0;
  105. _plotter->data->jmin = 0;
  106. _plotter->data->jmax = 0;
  107. _plotter->data->xmin = 0.0;
  108. _plotter->data->xmax = 1.0;
  109. _plotter->data->ymin = 0.0;
  110. _plotter->data->ymax = 1.0;
  111. _plotter->data->page_data = (plPageData *)NULL;
  112. /* compute the NDC to device-frame affine map, set it in Plotter */
  113. _compute_ndc_to_device_map (_plotter->data);
  114. /* initialize data members specific to this derived class */
  115. /* parameters */
  116. _plotter->meta_portable_output = false;
  117. /* dynamic variables */
  118. _plotter->meta_pos.x = 0.0;
  119. _plotter->meta_pos.y = 0.0;
  120. _plotter->meta_position_is_unknown = false;
  121. _plotter->meta_m_user_to_ndc[0] = 1.0;
  122. _plotter->meta_m_user_to_ndc[1] = 0.0;
  123. _plotter->meta_m_user_to_ndc[2] = 0.0;
  124. _plotter->meta_m_user_to_ndc[3] = 1.0;
  125. _plotter->meta_m_user_to_ndc[4] = 0.0;
  126. _plotter->meta_m_user_to_ndc[5] = 0.0;
  127. _plotter->meta_fill_rule_type = PL_FILL_ODD_WINDING;
  128. _plotter->meta_line_type = PL_L_SOLID;
  129. _plotter->meta_points_are_connected = true;
  130. _plotter->meta_cap_type = PL_CAP_BUTT;
  131. _plotter->meta_join_type = PL_JOIN_MITER;
  132. _plotter->meta_miter_limit = PL_DEFAULT_MITER_LIMIT;
  133. _plotter->meta_line_width = 0.0;
  134. _plotter->meta_line_width_is_default = true;
  135. _plotter->meta_dash_array = (const double *)NULL;
  136. _plotter->meta_dash_array_len = 0;
  137. _plotter->meta_dash_offset = 0.0;
  138. _plotter->meta_dash_array_in_effect = false;
  139. _plotter->meta_pen_type = 1;
  140. _plotter->meta_fill_type = 0;
  141. _plotter->meta_orientation = 1;
  142. _plotter->meta_font_name = (const char *)NULL;
  143. _plotter->meta_font_size = 0.0;
  144. _plotter->meta_font_size_is_default = true;
  145. _plotter->meta_text_rotation = 0.0;
  146. _plotter->meta_fgcolor.red = 0;
  147. _plotter->meta_fgcolor.green = 0;
  148. _plotter->meta_fgcolor.blue = 0;
  149. _plotter->meta_fillcolor_base.red = 0;
  150. _plotter->meta_fillcolor_base.green = 0;
  151. _plotter->meta_fillcolor_base.blue = 0;
  152. _plotter->meta_bgcolor.red = 65535;
  153. _plotter->meta_bgcolor.green = 65535;
  154. _plotter->meta_bgcolor.blue = 65535;
  155. /* initialize certain data members from device driver parameters */
  156. /* determine version of metafile format */
  157. {
  158. const char *portable_s;
  159. portable_s = (const char *)_get_plot_param (_plotter->data,
  160. "META_PORTABLE");
  161. if (strcasecmp (portable_s, "yes") == 0)
  162. _plotter->meta_portable_output = true;
  163. else
  164. _plotter->meta_portable_output = false; /* default value */
  165. }
  166. }
  167. /* The private `terminate' method, which is invoked when a Plotter is
  168. deleted. It may do such things as write to an output stream from
  169. internal storage, deallocate storage, etc. When this is invoked,
  170. _plotter points to the Plotter that is about to be deleted. */
  171. void
  172. _pl_m_terminate (S___(Plotter *_plotter))
  173. {
  174. #ifndef LIBPLOTTER
  175. /* in libplot, manually invoke superclass termination method */
  176. _pl_g_terminate (S___(_plotter));
  177. #endif
  178. }
  179. #ifdef LIBPLOTTER
  180. MetaPlotter::MetaPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  181. : Plotter (infile, outfile, errfile)
  182. {
  183. _pl_m_initialize ();
  184. }
  185. MetaPlotter::MetaPlotter (FILE *outfile)
  186. : Plotter (outfile)
  187. {
  188. _pl_m_initialize ();
  189. }
  190. MetaPlotter::MetaPlotter (istream& in, ostream& out, ostream& err)
  191. : Plotter (in, out, err)
  192. {
  193. _pl_m_initialize ();
  194. }
  195. MetaPlotter::MetaPlotter (ostream& out)
  196. : Plotter (out)
  197. {
  198. _pl_m_initialize ();
  199. }
  200. MetaPlotter::MetaPlotter ()
  201. {
  202. _pl_m_initialize ();
  203. }
  204. MetaPlotter::MetaPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  205. :Plotter (infile, outfile, errfile, parameters)
  206. {
  207. _pl_m_initialize ();
  208. }
  209. MetaPlotter::MetaPlotter (FILE *outfile, PlotterParams &parameters)
  210. :Plotter (outfile, parameters)
  211. {
  212. _pl_m_initialize ();
  213. }
  214. MetaPlotter::MetaPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  215. : Plotter (in, out, err, parameters)
  216. {
  217. _pl_m_initialize ();
  218. }
  219. MetaPlotter::MetaPlotter (ostream& out, PlotterParams &parameters)
  220. : Plotter (out, parameters)
  221. {
  222. _pl_m_initialize ();
  223. }
  224. MetaPlotter::MetaPlotter (PlotterParams &parameters)
  225. : Plotter (parameters)
  226. {
  227. _pl_m_initialize ();
  228. }
  229. MetaPlotter::~MetaPlotter ()
  230. {
  231. /* if luser left the Plotter open, close it */
  232. if (_plotter->data->open)
  233. _API_closepl ();
  234. _pl_m_terminate ();
  235. }
  236. #endif