b_defplot.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 Bitmap Plotter 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. #include "xmi.h" /* use libxmi scan conversion module */
  22. /* forward references */
  23. static bool parse_bitmap_size (const char *bitmap_size_s, int *width, int *height);
  24. #ifndef LIBPLOTTER
  25. /* In libplot, this is the initialization for the function-pointer part of
  26. a BitmapPlotter struct. */
  27. const Plotter _pl_b_default_plotter =
  28. {
  29. /* initialization (after creation) and termination (before deletion) */
  30. _pl_b_initialize, _pl_b_terminate,
  31. /* page manipulation */
  32. _pl_b_begin_page, _pl_b_erase_page, _pl_b_end_page,
  33. /* drawing state manipulation */
  34. _pl_g_push_state, _pl_g_pop_state,
  35. /* internal path-painting methods (endpath() is a wrapper for the first) */
  36. _pl_b_paint_path, _pl_b_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
  37. /* internal methods for drawing of markers and points */
  38. _pl_g_paint_marker, _pl_b_paint_point,
  39. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  40. _pl_g_paint_text_string_with_escapes, _pl_g_paint_text_string,
  41. _pl_g_get_text_width,
  42. /* private low-level `retrieve font' method */
  43. _pl_g_retrieve_font,
  44. /* `flush output' method, called only if Plotter handles its own output */
  45. _pl_g_flush_output,
  46. /* error handlers */
  47. _pl_g_warning,
  48. _pl_g_error,
  49. };
  50. #endif /* not LIBPLOTTER */
  51. /* The private `initialize' method, which is invoked when a Plotter is
  52. created. It is used for such things as initializing capability flags
  53. from the values of class variables, allocating storage, etc. When this
  54. is invoked, _plotter points to the Plotter that has just been
  55. created. */
  56. void
  57. _pl_b_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_BITMAP;
  67. #endif
  68. /* output model */
  69. _plotter->data->output_model = PL_OUTPUT_NONE;
  70. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  71. _plotter->data->have_wide_lines = 1;
  72. _plotter->data->have_dash_array = 1;
  73. _plotter->data->have_solid_fill = 1;
  74. _plotter->data->have_odd_winding_fill = 1;
  75. _plotter->data->have_nonzero_winding_fill = 1;
  76. _plotter->data->have_settable_bg = 1;
  77. _plotter->data->have_escaped_string_support = 0;
  78. _plotter->data->have_ps_fonts = 0;
  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_HERSHEY;
  88. _plotter->data->pcl_before_ps = false;
  89. _plotter->data->have_horizontal_justification = false;
  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_AXES_PRESERVED;
  97. _plotter->data->allowed_ellarc_scaling = AS_AXES_PRESERVED;
  98. _plotter->data->allowed_quad_scaling = AS_NONE;
  99. _plotter->data->allowed_cubic_scaling = AS_NONE;
  100. _plotter->data->allowed_box_scaling = AS_NONE;
  101. _plotter->data->allowed_circle_scaling = AS_NONE;
  102. _plotter->data->allowed_ellipse_scaling = AS_AXES_PRESERVED;
  103. /* dimensions */
  104. _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
  105. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_LIBXMI;
  106. _plotter->data->flipped_y = true;
  107. _plotter->data->imin = 0;
  108. _plotter->data->imax = 569;
  109. _plotter->data->jmin = 569;
  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. _plotter->b_xn = _plotter->data->imax + 1;
  118. _plotter->b_yn = _plotter->data->jmin + 1;
  119. _plotter->b_painted_set = (void *)NULL;
  120. _plotter->b_canvas = (void *)NULL;
  121. /* initialize storage used by libxmi's reentrant miDrawArcs_r() function
  122. for cacheing rasterized ellipses */
  123. _plotter->b_arc_cache_data = (void *)miNewEllipseCache ();
  124. /* determine the range of device coordinates over which the graphics
  125. display will extend (and hence the transformation from user to device
  126. coordinates). */
  127. {
  128. const char *bitmap_size_s;
  129. int width = 1, height = 1;
  130. bitmap_size_s = (const char *)_get_plot_param (_plotter->data, "BITMAPSIZE");
  131. if (bitmap_size_s && parse_bitmap_size (bitmap_size_s, &width, &height)
  132. /* insist on >=1 */
  133. && width >= 1 && height >= 1)
  134. /* override defaults above */
  135. {
  136. _plotter->data->imax = width - 1;
  137. _plotter->data->jmin = height - 1;
  138. _plotter->b_xn = width;
  139. _plotter->b_yn = height;
  140. }
  141. }
  142. /* compute the NDC to device-frame affine map, set it in Plotter */
  143. _compute_ndc_to_device_map (_plotter->data);
  144. /* initialize certain data members from device driver parameters */
  145. /* for this class, there are none */
  146. }
  147. static bool
  148. parse_bitmap_size (const char *bitmap_size_s, int *width, int *height)
  149. {
  150. int local_width = 1, local_height = 1;
  151. if (bitmap_size_s
  152. /* should parse this better */
  153. && sscanf (bitmap_size_s, "%dx%d", &local_width, &local_height) == 2
  154. && local_width > 0 && local_height > 0)
  155. {
  156. *width = local_width;
  157. *height = local_height;
  158. return true;
  159. }
  160. else
  161. return false;
  162. }
  163. /* The private `terminate' method, which is invoked when a Plotter is
  164. deleted. It may do such things as write to an output stream from
  165. internal storage, deallocate storage, etc. When this is invoked,
  166. _plotter points (temporarily) to the Plotter that is about to be
  167. deleted. */
  168. void
  169. _pl_b_terminate (S___(Plotter *_plotter))
  170. {
  171. /* free storage used by libxmi's reentrant miDrawArcs_r() function */
  172. miDeleteEllipseCache ((miEllipseCache *)_plotter->b_arc_cache_data);
  173. #ifndef LIBPLOTTER
  174. /* in libplot, manually invoke superclass termination method */
  175. _pl_g_terminate (S___(_plotter));
  176. #endif
  177. }
  178. #ifdef LIBPLOTTER
  179. BitmapPlotter::BitmapPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  180. :Plotter (infile, outfile, errfile)
  181. {
  182. _pl_b_initialize ();
  183. }
  184. BitmapPlotter::BitmapPlotter (FILE *outfile)
  185. :Plotter (outfile)
  186. {
  187. _pl_b_initialize ();
  188. }
  189. BitmapPlotter::BitmapPlotter (istream& in, ostream& out, ostream& err)
  190. : Plotter (in, out, err)
  191. {
  192. _pl_b_initialize ();
  193. }
  194. BitmapPlotter::BitmapPlotter (ostream& out)
  195. : Plotter (out)
  196. {
  197. _pl_b_initialize ();
  198. }
  199. BitmapPlotter::BitmapPlotter ()
  200. {
  201. _pl_b_initialize ();
  202. }
  203. BitmapPlotter::BitmapPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  204. :Plotter (infile, outfile, errfile, parameters)
  205. {
  206. _pl_b_initialize ();
  207. }
  208. BitmapPlotter::BitmapPlotter (FILE *outfile, PlotterParams &parameters)
  209. :Plotter (outfile, parameters)
  210. {
  211. _pl_b_initialize ();
  212. }
  213. BitmapPlotter::BitmapPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  214. : Plotter (in, out, err, parameters)
  215. {
  216. _pl_b_initialize ();
  217. }
  218. BitmapPlotter::BitmapPlotter (ostream& out, PlotterParams &parameters)
  219. : Plotter (out, parameters)
  220. {
  221. _pl_b_initialize ();
  222. }
  223. BitmapPlotter::BitmapPlotter (PlotterParams &parameters)
  224. : Plotter (parameters)
  225. {
  226. _pl_b_initialize ();
  227. }
  228. BitmapPlotter::~BitmapPlotter ()
  229. {
  230. /* if luser left the Plotter open, close it */
  231. if (_plotter->data->open)
  232. _API_closepl ();
  233. _pl_b_terminate ();
  234. }
  235. #endif
  236. #ifndef LIBPLOTTER
  237. /* The following forwarding functions provide special support in libplot
  238. for deriving classes such as the PNMPlotter and PNGPlotter classes from
  239. the BitmapPlotter class. In libplotter, forwarding is implemented by a
  240. virtual function; see plotter.h. */
  241. /* Forwarding function called by any BitmapPlotter in closepl. See
  242. b_closepl.c, n_write.c, z_write.c for the forwarded-to functions. The
  243. first is currently a no-op. */
  244. int
  245. _maybe_output_image (Plotter *_plotter)
  246. {
  247. int retval;
  248. switch ((int)(_plotter->data->type))
  249. {
  250. case (int)PL_BITMAP:
  251. default:
  252. retval = _pl_b_maybe_output_image (_plotter);
  253. break;
  254. case (int)PL_PNM:
  255. retval = _pl_n_maybe_output_image (_plotter);
  256. break;
  257. #ifdef INCLUDE_PNG_SUPPORT
  258. case (int)PL_PNG:
  259. retval = _pl_z_maybe_output_image (_plotter);
  260. break;
  261. #endif
  262. }
  263. return retval;
  264. }
  265. #endif /* not LIBPLOTTER */