s_defplot.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, 2009, Free Software
  3. Foundation, Inc.
  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. The GNU plotutils package is distributed in the hope that it will be
  9. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with the GNU plotutils package; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. /* This file defines the initialization for any SVGPlotter object,
  17. including both private data and public methods. There is a one-to-one
  18. correspondence between public methods and user-callable functions in the
  19. C API. */
  20. #include "sys-defines.h"
  21. #include "extern.h"
  22. #ifndef LIBPLOTTER
  23. /* In libplot, this is the initialization for the function-pointer part of
  24. a SVGPlotter struct. */
  25. const Plotter _pl_s_default_plotter =
  26. {
  27. /* initialization (after creation) and termination (before deletion) */
  28. _pl_s_initialize, _pl_s_terminate,
  29. /* page manipulation */
  30. _pl_s_begin_page, _pl_s_erase_page, _pl_s_end_page,
  31. /* drawing state manipulation */
  32. _pl_g_push_state, _pl_g_pop_state,
  33. /* internal path-painting methods (endpath() is a wrapper for the first) */
  34. _pl_s_paint_path, _pl_s_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
  35. /* internal methods for drawing of markers and points */
  36. _pl_g_paint_marker, _pl_s_paint_point,
  37. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  38. _pl_g_paint_text_string_with_escapes, _pl_s_paint_text_string,
  39. _pl_g_get_text_width,
  40. /* private low-level `retrieve font' method */
  41. _pl_g_retrieve_font,
  42. /* `flush output' method, called only if Plotter handles its own output */
  43. _pl_g_flush_output,
  44. /* error handlers */
  45. _pl_g_warning,
  46. _pl_g_error,
  47. };
  48. #endif /* not LIBPLOTTER */
  49. /* The private `initialize' method, which is invoked when a Plotter is
  50. created. It is used for such things as initializing capability flags
  51. from the values of class variables, allocating storage, etc. When this
  52. is invoked, _plotter points to the Plotter that has just been
  53. created. */
  54. void
  55. _pl_s_initialize (S___(Plotter *_plotter))
  56. {
  57. #ifndef LIBPLOTTER
  58. /* in libplot, manually invoke superclass initialization method */
  59. _pl_g_initialize (S___(_plotter));
  60. #endif
  61. /* override generic initializations (which are appropriate to the base
  62. Plotter class), as necessary */
  63. #ifndef LIBPLOTTER
  64. /* tag field, differs in derived classes */
  65. _plotter->data->type = PL_SVG;
  66. #endif
  67. /* output model */
  68. _plotter->data->output_model = PL_OUTPUT_ONE_PAGE;
  69. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  70. _plotter->data->have_wide_lines = 1;
  71. _plotter->data->have_dash_array = 1;
  72. _plotter->data->have_solid_fill = 1;
  73. _plotter->data->have_odd_winding_fill = 1;
  74. _plotter->data->have_nonzero_winding_fill = 1;
  75. _plotter->data->have_settable_bg = 1;
  76. _plotter->data->have_escaped_string_support = 0;
  77. _plotter->data->have_ps_fonts = 1;
  78. _plotter->data->have_pcl_fonts = 1;
  79. _plotter->data->have_stick_fonts = 0;
  80. _plotter->data->have_extra_stick_fonts = 0;
  81. _plotter->data->have_other_fonts = 0;
  82. /* text and font-related parameters (internal, not queryable by user);
  83. note that we don't set kern_stick_fonts, because it was set by the
  84. superclass initialization (and it's irrelevant for this Plotter type,
  85. anyway) */
  86. _plotter->data->default_font_type = PL_F_POSTSCRIPT;
  87. _plotter->data->pcl_before_ps = false;
  88. _plotter->data->have_horizontal_justification = false;
  89. _plotter->data->have_vertical_justification = false;
  90. _plotter->data->issue_font_warning = true;
  91. /* path-related parameters (also internal); note that we
  92. don't set max_unfilled_path_length, because it was set by the
  93. superclass initialization */
  94. _plotter->data->have_mixed_paths = false;
  95. _plotter->data->allowed_arc_scaling = AS_ANY;
  96. _plotter->data->allowed_ellarc_scaling = AS_ANY;
  97. _plotter->data->allowed_quad_scaling = AS_ANY;
  98. _plotter->data->allowed_cubic_scaling = AS_ANY;
  99. _plotter->data->allowed_box_scaling = AS_ANY;
  100. _plotter->data->allowed_circle_scaling = AS_ANY;
  101. _plotter->data->allowed_ellipse_scaling = AS_ANY;
  102. /* color-related parameters (also internal) */
  103. _plotter->data->emulate_color = false;
  104. /* dimensions */
  105. _plotter->data->display_model_type = (int)DISP_MODEL_VIRTUAL;
  106. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_REAL;
  107. _plotter->data->flipped_y = true;
  108. _plotter->data->imin = 0; /* not used */
  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 = 1.0;
  114. _plotter->data->ymin = 1.0; /* note flipped y coordinate */
  115. _plotter->data->ymax = 0.0;
  116. _plotter->data->page_data = (plPageData *)NULL;
  117. /* initialize data members specific to this derived class */
  118. _plotter->s_matrix[0] = 1.0;/* dummy matrix values */
  119. _plotter->s_matrix[1] = 0.0;
  120. _plotter->s_matrix[2] = 0.0;
  121. _plotter->s_matrix[3] = 1.0;
  122. _plotter->s_matrix[4] = 0.0;
  123. _plotter->s_matrix[5] = 0.0;
  124. _plotter->s_matrix_is_unknown = true;
  125. _plotter->s_matrix_is_bogus = false;
  126. _plotter->s_bgcolor.red = -1; /* initialized in s_begin_page */
  127. _plotter->s_bgcolor.green = -1;
  128. _plotter->s_bgcolor.blue = -1;
  129. _plotter->s_bgcolor_suppressed = false;
  130. /* Note: xmin,xmax,ymin,ymax determine the range of device coordinates
  131. over which the viewport will extend (and hence the transformation from
  132. user to device coordinates; see g_space.c).
  133. For an SVG Plotter, `device coordinates' are usually almost the same
  134. as libplot's NDC coordinates, on account of the way we wrap a global
  135. transformation matrix around all graphics in the output file; see
  136. s_closepl.c. However, SVG uses a flipped-y convention: ymin,ymax are
  137. 1 and 0 respectively (see above).
  138. Actually, if the user specifies a negative xsize or ysize as part of
  139. the PAGESIZE parameter, we perform an additional flipping, so we can
  140. emit nonnegative width and height attributes for the top-level SVG
  141. element. We do this additional flipping right now. */
  142. /* determine page type, and viewport size and location/offset (the
  143. viewport size, i.e., (xsize,ysize), will be written out at the head of
  144. the SVG file, and the location/offset, i.e., (xorigin,yorigin) and
  145. (xoffset,yoffset), will be ignored) */
  146. _set_page_type (_plotter->data);
  147. if (_plotter->data->viewport_xsize < 0.0)
  148. /* flip map from user to NDC space */
  149. {
  150. _plotter->data->xmin = 1.0;
  151. _plotter->data->xmax = 0.0;
  152. }
  153. if (_plotter->data->viewport_ysize < 0.0)
  154. /* flip map from user to NDC space */
  155. {
  156. _plotter->data->ymin = 0.0;
  157. _plotter->data->ymax = 1.0;
  158. }
  159. /* compute the NDC to device-frame affine map, set it in Plotter */
  160. _compute_ndc_to_device_map (_plotter->data);
  161. }
  162. /* The private `terminate' method, which is invoked when a Plotter is
  163. deleted. It may do such things as write to an output stream from
  164. internal storage, deallocate storage, etc. When this is invoked,
  165. _plotter points to the Plotter that is about to be deleted. */
  166. void
  167. _pl_s_terminate (S___(Plotter *_plotter))
  168. {
  169. }
  170. #ifdef LIBPLOTTER
  171. SVGPlotter::SVGPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  172. :Plotter (infile, outfile, errfile)
  173. {
  174. _pl_s_initialize ();
  175. }
  176. SVGPlotter::SVGPlotter (FILE *outfile)
  177. :Plotter (outfile)
  178. {
  179. _pl_s_initialize ();
  180. }
  181. SVGPlotter::SVGPlotter (istream& in, ostream& out, ostream& err)
  182. : Plotter (in, out, err)
  183. {
  184. _pl_s_initialize ();
  185. }
  186. SVGPlotter::SVGPlotter (ostream& out)
  187. : Plotter (out)
  188. {
  189. _pl_s_initialize ();
  190. }
  191. SVGPlotter::SVGPlotter ()
  192. {
  193. _pl_s_initialize ();
  194. }
  195. SVGPlotter::SVGPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  196. :Plotter (infile, outfile, errfile, parameters)
  197. {
  198. _pl_s_initialize ();
  199. }
  200. SVGPlotter::SVGPlotter (FILE *outfile, PlotterParams &parameters)
  201. :Plotter (outfile, parameters)
  202. {
  203. _pl_s_initialize ();
  204. }
  205. SVGPlotter::SVGPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  206. : Plotter (in, out, err, parameters)
  207. {
  208. _pl_s_initialize ();
  209. }
  210. SVGPlotter::SVGPlotter (ostream& out, PlotterParams &parameters)
  211. : Plotter (out, parameters)
  212. {
  213. _pl_s_initialize ();
  214. }
  215. SVGPlotter::SVGPlotter (PlotterParams &parameters)
  216. : Plotter (parameters)
  217. {
  218. _pl_s_initialize ();
  219. }
  220. SVGPlotter::~SVGPlotter ()
  221. {
  222. _pl_s_terminate ();
  223. }
  224. #endif