a_defplot.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 AIPlotter object, including
  16. 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. an AIPlotter struct. */
  24. const Plotter _pl_a_default_plotter =
  25. {
  26. /* initialization (after creation) and termination (before deletion) */
  27. _pl_a_initialize, _pl_a_terminate,
  28. /* page manipulation */
  29. _pl_a_begin_page, _pl_a_erase_page, _pl_a_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_a_paint_path, _pl_a_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_a_paint_point,
  36. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  37. _pl_g_paint_text_string_with_escapes, _pl_a_paint_text_string,
  38. _pl_g_get_text_width,
  39. /* private low-level `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. /* 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 AI Plotter 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. Also we determine
  56. which version of Illustrator file format we'll emit. */
  57. void
  58. _pl_a_initialize (S___(Plotter *_plotter))
  59. {
  60. #ifndef LIBPLOTTER
  61. /* in libplot, manually invoke superclass initialization method */
  62. _pl_g_initialize (S___(_plotter));
  63. #endif
  64. /* override superclass initializations, as necessary */
  65. #ifndef LIBPLOTTER
  66. /* tag field, differs in derived classes */
  67. _plotter->data->type = PL_AI;
  68. #endif
  69. /* output model */
  70. _plotter->data->output_model = PL_OUTPUT_ONE_PAGE;
  71. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  72. _plotter->data->have_wide_lines = 1;
  73. _plotter->data->have_dash_array = 1;
  74. _plotter->data->have_solid_fill = 1;
  75. _plotter->data->have_odd_winding_fill = 1;
  76. _plotter->data->have_nonzero_winding_fill = 1;
  77. _plotter->data->have_settable_bg = 0;
  78. _plotter->data->have_escaped_string_support = 0;
  79. _plotter->data->have_ps_fonts = 1;
  80. _plotter->data->have_pcl_fonts = 1;
  81. _plotter->data->have_stick_fonts = 0;
  82. _plotter->data->have_extra_stick_fonts = 0;
  83. _plotter->data->have_other_fonts = 0;
  84. /* text and font-related parameters (internal, not queryable by user);
  85. note that we don't set kern_stick_fonts, because it was set by the
  86. superclass initialization (and it's irrelevant for this Plotter type,
  87. anyway) */
  88. _plotter->data->default_font_type = PL_F_POSTSCRIPT;
  89. _plotter->data->pcl_before_ps = false;
  90. _plotter->data->issue_font_warning = true;
  91. _plotter->data->have_horizontal_justification = true;
  92. _plotter->data->have_vertical_justification = false;
  93. /* path-related parameters (also internal); note that we
  94. don't set max_unfilled_path_length, because it was set by the
  95. superclass initialization */
  96. _plotter->data->have_mixed_paths = true;
  97. _plotter->data->allowed_arc_scaling = AS_NONE;
  98. _plotter->data->allowed_ellarc_scaling = AS_NONE;
  99. _plotter->data->allowed_quad_scaling = AS_NONE;
  100. _plotter->data->allowed_cubic_scaling = AS_ANY;
  101. _plotter->data->allowed_box_scaling = AS_NONE;
  102. _plotter->data->allowed_circle_scaling = AS_NONE;
  103. _plotter->data->allowed_ellipse_scaling = AS_NONE;
  104. /* dimensions */
  105. _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
  106. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
  107. _plotter->data->flipped_y = false;
  108. _plotter->data->imin = 0;
  109. _plotter->data->imax = 0;
  110. _plotter->data->jmin = 0;
  111. _plotter->data->jmax = 0;
  112. _plotter->data->xmin = 0.0;
  113. _plotter->data->xmax = 0.0;
  114. _plotter->data->ymin = 0.0;
  115. _plotter->data->ymax = 0.0;
  116. _plotter->data->page_data = (plPageData *)NULL;
  117. /* initialize data members specific to this derived class */
  118. _plotter->ai_version = AI_VERSION_5;
  119. _plotter->ai_pen_cyan = 0.0;
  120. _plotter->ai_pen_magenta = 0.0;
  121. _plotter->ai_pen_yellow = 0.0;
  122. _plotter->ai_pen_black = 1.0;
  123. _plotter->ai_fill_cyan = 0.0;
  124. _plotter->ai_fill_magenta = 0.0;
  125. _plotter->ai_fill_yellow = 0.0;
  126. _plotter->ai_fill_black = 1.0;
  127. _plotter->ai_cyan_used = false;
  128. _plotter->ai_magenta_used = false;
  129. _plotter->ai_yellow_used = false;
  130. _plotter->ai_black_used = false;
  131. _plotter->ai_cap_style = AI_LINE_CAP_BUTT;
  132. _plotter->ai_join_style = AI_LINE_JOIN_MITER;
  133. /* Maximum value the cosecant of the half-angle between any two line
  134. segments can have, if the join is to be mitered rather than beveled.
  135. Default value for AI is 4.0. */
  136. _plotter->ai_miter_limit = 4.0;
  137. _plotter->ai_line_type = PL_L_SOLID;
  138. _plotter->ai_line_width = 1.0;
  139. _plotter->ai_fill_rule_type = 0; /* i.e. nonzero winding number rule */
  140. /* initialize certain data members from device driver parameters */
  141. /* determine which version of AI format we'll emit (obsolescent) */
  142. {
  143. const char *version_s;
  144. version_s = (const char *)_get_plot_param (_plotter->data, "AI_VERSION");
  145. if (strcmp (version_s, "3") == 0)
  146. _plotter->ai_version = AI_VERSION_3;
  147. else if (strcmp (version_s, "5") == 0)
  148. _plotter->ai_version = AI_VERSION_5;
  149. else
  150. {
  151. version_s = (const char *)_get_default_plot_param ("AI_VERSION");
  152. if (strcmp (version_s, "3") == 0)
  153. _plotter->ai_version = AI_VERSION_3;
  154. else if (strcmp (version_s, "5") == 0)
  155. _plotter->ai_version = AI_VERSION_5;
  156. }
  157. }
  158. /* AI didn't support even-odd fill until version 5 */
  159. if (_plotter->ai_version == AI_VERSION_3)
  160. _plotter->data->have_odd_winding_fill = 0;
  161. /* Determine range of device coordinates over which the viewport will
  162. extend (and hence the transformation from user to device coordinates;
  163. see g_space.c). */
  164. {
  165. /* determine page type, viewport size and location */
  166. _set_page_type (_plotter->data);
  167. /* convert viewport size-and-location data (in terms of inches) to
  168. device coordinates (i.e. points) */
  169. _plotter->data->xmin = 72 * (_plotter->data->viewport_xorigin
  170. + _plotter->data->viewport_xoffset);
  171. _plotter->data->xmax = 72 * (_plotter->data->viewport_xorigin
  172. + _plotter->data->viewport_xoffset
  173. + _plotter->data->viewport_xsize);
  174. _plotter->data->ymin = 72 * (_plotter->data->viewport_yorigin
  175. + _plotter->data->viewport_yoffset);
  176. _plotter->data->ymax = 72 * (_plotter->data->viewport_yorigin
  177. + _plotter->data->viewport_yoffset
  178. + _plotter->data->viewport_ysize);
  179. }
  180. /* compute the NDC to device-frame affine map, set it in Plotter */
  181. _compute_ndc_to_device_map (_plotter->data);
  182. }
  183. /* The private `terminate' method, which is invoked when a Plotter is
  184. deleted. It may do such things as write to an output stream from
  185. internal storage, deallocate storage, etc. When this is invoked,
  186. _plotter points to the Plotter that is about to be deleted. */
  187. void
  188. _pl_a_terminate (S___(Plotter *_plotter))
  189. {
  190. #ifndef LIBPLOTTER
  191. /* in libplot, manually invoke superclass termination method */
  192. _pl_g_terminate (S___(_plotter));
  193. #endif
  194. }
  195. #ifdef LIBPLOTTER
  196. AIPlotter::AIPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  197. :Plotter (infile, outfile, errfile)
  198. {
  199. _pl_a_initialize ();
  200. }
  201. AIPlotter::AIPlotter (FILE *outfile)
  202. :Plotter (outfile)
  203. {
  204. _pl_a_initialize ();
  205. }
  206. AIPlotter::AIPlotter (istream& in, ostream& out, ostream& err)
  207. : Plotter (in, out, err)
  208. {
  209. _pl_a_initialize ();
  210. }
  211. AIPlotter::AIPlotter (ostream& out)
  212. : Plotter (out)
  213. {
  214. _pl_a_initialize ();
  215. }
  216. AIPlotter::AIPlotter ()
  217. {
  218. _pl_a_initialize ();
  219. }
  220. AIPlotter::AIPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  221. :Plotter (infile, outfile, errfile, parameters)
  222. {
  223. _pl_a_initialize ();
  224. }
  225. AIPlotter::AIPlotter (FILE *outfile, PlotterParams &parameters)
  226. :Plotter (outfile, parameters)
  227. {
  228. _pl_a_initialize ();
  229. }
  230. AIPlotter::AIPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  231. : Plotter (in, out, err, parameters)
  232. {
  233. _pl_a_initialize ();
  234. }
  235. AIPlotter::AIPlotter (ostream& out, PlotterParams &parameters)
  236. : Plotter (out, parameters)
  237. {
  238. _pl_a_initialize ();
  239. }
  240. AIPlotter::AIPlotter (PlotterParams &parameters)
  241. : Plotter (parameters)
  242. {
  243. _pl_a_initialize ();
  244. }
  245. AIPlotter::~AIPlotter ()
  246. {
  247. /* if luser left the Plotter open, close it */
  248. if (_plotter->data->open)
  249. _API_closepl ();
  250. _pl_a_terminate ();
  251. }
  252. #endif