n_defplot.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 PNM 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. #ifndef LIBPLOTTER
  22. /* In libplot, this is the initialization for the function-pointer part of
  23. a PNMPlotter struct. It is the same as for a BitmapPlotter, except for
  24. the routines _pl_n_initialize and _pl_n_terminate. */
  25. const Plotter _pl_n_default_plotter =
  26. {
  27. /* initialization (after creation) and termination (before deletion) */
  28. _pl_n_initialize, _pl_n_terminate,
  29. /* page manipulation */
  30. _pl_b_begin_page, _pl_b_erase_page, _pl_b_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_b_paint_path, _pl_b_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_b_paint_point,
  37. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  38. _pl_g_paint_text_string_with_escapes, _pl_g_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_n_initialize (S___(Plotter *_plotter))
  56. {
  57. #ifndef LIBPLOTTER
  58. /* in libplot, manually invoke superclass initialization method */
  59. _pl_b_initialize (S___(_plotter));
  60. #endif
  61. /* override superclass initializations, as necessary */
  62. #ifndef LIBPLOTTER
  63. /* tag field, differs in derived classes */
  64. _plotter->data->type = PL_PNM;
  65. #endif
  66. /* output model */
  67. _plotter->data->output_model = PL_OUTPUT_VIA_CUSTOM_ROUTINES;
  68. /* initialize data members specific to this derived class */
  69. _plotter->n_portable_output = false;
  70. /* initialize certain data members from device driver parameters */
  71. /* determine version of PBM/PGM/PPM format (binary or ascii) */
  72. {
  73. const char *portable_s;
  74. portable_s = (const char *)_get_plot_param (_plotter->data, "PNM_PORTABLE");
  75. if (strcasecmp (portable_s, "yes") == 0)
  76. _plotter->n_portable_output = true;
  77. else
  78. _plotter->n_portable_output = false; /* default value */
  79. }
  80. }
  81. /* The private `terminate' method, which is invoked when a Plotter is
  82. deleted. It may do such things as write to an output stream from
  83. internal storage, deallocate storage, etc. When this is invoked,
  84. _plotter points (temporarily) to the Plotter that is about to be
  85. deleted. */
  86. void
  87. _pl_n_terminate (S___(Plotter *_plotter))
  88. {
  89. #ifndef LIBPLOTTER
  90. /* in libplot, manually invoke superclass termination method */
  91. _pl_b_terminate (S___(_plotter));
  92. #endif
  93. }
  94. #ifdef LIBPLOTTER
  95. PNMPlotter::PNMPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  96. : BitmapPlotter (infile, outfile, errfile)
  97. {
  98. _pl_n_initialize ();
  99. }
  100. PNMPlotter::PNMPlotter (FILE *outfile)
  101. : BitmapPlotter (outfile)
  102. {
  103. _pl_n_initialize ();
  104. }
  105. PNMPlotter::PNMPlotter (istream& in, ostream& out, ostream& err)
  106. : BitmapPlotter (in, out, err)
  107. {
  108. _pl_n_initialize ();
  109. }
  110. PNMPlotter::PNMPlotter (ostream& out)
  111. : BitmapPlotter (out)
  112. {
  113. _pl_n_initialize ();
  114. }
  115. PNMPlotter::PNMPlotter ()
  116. {
  117. _pl_n_initialize ();
  118. }
  119. PNMPlotter::PNMPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  120. : BitmapPlotter (infile, outfile, errfile, parameters)
  121. {
  122. _pl_n_initialize ();
  123. }
  124. PNMPlotter::PNMPlotter (FILE *outfile, PlotterParams &parameters)
  125. : BitmapPlotter (outfile, parameters)
  126. {
  127. _pl_n_initialize ();
  128. }
  129. PNMPlotter::PNMPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  130. : BitmapPlotter (in, out, err, parameters)
  131. {
  132. _pl_n_initialize ();
  133. }
  134. PNMPlotter::PNMPlotter (ostream& out, PlotterParams &parameters)
  135. : BitmapPlotter (out, parameters)
  136. {
  137. _pl_n_initialize ();
  138. }
  139. PNMPlotter::PNMPlotter (PlotterParams &parameters)
  140. : BitmapPlotter (parameters)
  141. {
  142. _pl_n_initialize ();
  143. }
  144. PNMPlotter::~PNMPlotter ()
  145. {
  146. _pl_n_terminate ();
  147. }
  148. #endif