h_openpl.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include "sys-defines.h"
  16. #include "extern.h"
  17. bool
  18. _pl_h_begin_page (S___(Plotter *_plotter))
  19. {
  20. int i;
  21. /* With each call to openpl(), we reset our knowledge of the HP-GL
  22. internal state, i.e. the dynamic derived-class-specific data members
  23. of the HPGL or PCL Plotter. The values are the same as are used in
  24. initializing the Plotter (see h_defplot.c). */
  25. /* reset any soft-defined colors in the pen color array */
  26. for (i = 0; i < HPGL2_MAX_NUM_PENS; i++)
  27. if (_plotter->hpgl_pen_defined[i] == 1) /* i.e. soft-defined */
  28. _plotter->hpgl_pen_defined[i] = 0; /* i.e. undefined */
  29. /* reset current pen */
  30. _plotter->hpgl_pen = 1;
  31. /* if we can soft-define pen colors, reset free_pen data member by
  32. determining what the next free pen is */
  33. {
  34. bool undefined_pen_seen = false;
  35. if (_plotter->hpgl_can_assign_colors) /* can soft-define pen colors */
  36. for (i = 2; i < HPGL2_MAX_NUM_PENS; i++)
  37. {
  38. if (_plotter->hpgl_pen_defined[i] == 0)
  39. /* at least one pen with number > 1 is not yet defined */
  40. {
  41. /* record which such was encountered first */
  42. _plotter->hpgl_free_pen = i;
  43. undefined_pen_seen = true;
  44. break;
  45. }
  46. }
  47. if (!undefined_pen_seen)
  48. /* too many pens specified, can't soft-define colors */
  49. _plotter->hpgl_can_assign_colors = false;
  50. }
  51. /* reset additional data members of Plotter */
  52. _plotter->hpgl_bad_pen = false;
  53. _plotter->hpgl_pendown = false;
  54. _plotter->hpgl_pen_width = 0.001;
  55. _plotter->hpgl_line_type = HPGL_L_SOLID;
  56. _plotter->hpgl_cap_style = HPGL_CAP_BUTT;
  57. _plotter->hpgl_join_style = HPGL_JOIN_MITER;
  58. _plotter->hpgl_miter_limit = 5.0; /* default HP-GL/2 value */
  59. _plotter->hpgl_fill_type = HPGL_FILL_SOLID_BI;
  60. _plotter->hpgl_fill_option1 = 0.0;
  61. _plotter->hpgl_fill_option2 = 0.0;
  62. _plotter->hpgl_symbol_set = PCL_ROMAN_8;
  63. _plotter->hpgl_spacing = 0;
  64. _plotter->hpgl_posture = 0;
  65. _plotter->hpgl_stroke_weight = 0;
  66. _plotter->hpgl_pcl_typeface = PCL_STICK_TYPEFACE;
  67. _plotter->hpgl_charset_lower = HPGL_CHARSET_ASCII;
  68. _plotter->hpgl_charset_upper = HPGL_CHARSET_ASCII;
  69. _plotter->hpgl_rel_char_height = 0.0;
  70. _plotter->hpgl_rel_char_width = 0.0;
  71. _plotter->hpgl_rel_label_rise = 0.0;
  72. _plotter->hpgl_rel_label_run = 0.0;
  73. _plotter->hpgl_tan_char_slant = 0.0;
  74. _plotter->hpgl_position_is_unknown = true;
  75. _plotter->hpgl_pos.x = 0;
  76. _plotter->hpgl_pos.y = 0;
  77. /* if a PCL Plotter, switch from PCL mode to HP-GL/2 mode */
  78. _maybe_switch_to_hpgl (S___(_plotter));
  79. /* output HP-GL prologue */
  80. if (_plotter->hpgl_version == 2)
  81. {
  82. sprintf (_plotter->data->page->point, "BP;IN;");
  83. _update_buffer (_plotter->data->page);
  84. /* include HP-GL/2 `plot length' directive; important mostly for roll
  85. plotters */
  86. sprintf (_plotter->data->page->point, "PS%d;",
  87. IROUND(_plotter->hpgl_plot_length));
  88. _update_buffer (_plotter->data->page);
  89. }
  90. else
  91. {
  92. sprintf (_plotter->data->page->point, "IN;");
  93. _update_buffer (_plotter->data->page);
  94. }
  95. /* make use of HP-GL's plotting-area rotation capability, if requested by
  96. the HPGL_ROTATE parameter (this does not apply to PCL Plotters, for
  97. which rotation=0 always) */
  98. if (_plotter->hpgl_rotation != 0)
  99. {
  100. sprintf (_plotter->data->page->point, "RO%d;", _plotter->hpgl_rotation);
  101. _update_buffer (_plotter->data->page);
  102. }
  103. /* Set scaling points P1, P2 at lower left and upper right corners of our
  104. viewport; or more accurately, at the two points that (0,0) and (1,1),
  105. which are the lower right and upper right corners in NDC space, get
  106. mapped to. */
  107. sprintf (_plotter->data->page->point, "IP%d,%d,%d,%d;",
  108. IROUND(_plotter->hpgl_p1.x), IROUND(_plotter->hpgl_p1.y),
  109. IROUND(_plotter->hpgl_p2.x), IROUND(_plotter->hpgl_p2.y));
  110. _update_buffer (_plotter->data->page);
  111. /* Set up `scaled device coordinates' within the viewport. All
  112. coordinates in the output file will be scaled device coordinates, not
  113. physical device coordinates. The range of scaled coordinates will be
  114. independent of the viewport positioning, page size, etc.; see the
  115. definitions of xmin,xmax,ymin,ymax in h_defplot.c. */
  116. sprintf (_plotter->data->page->point, "SC%d,%d,%d,%d;",
  117. IROUND (_plotter->data->xmin), IROUND (_plotter->data->xmax),
  118. IROUND (_plotter->data->ymin), IROUND (_plotter->data->ymax));
  119. _update_buffer (_plotter->data->page);
  120. if (_plotter->hpgl_version == 2)
  121. {
  122. /* Begin to define a palette, by specifying a number of logical pens.
  123. (All HP-GL/2 devices should support the `NP' instruction, even
  124. though many support only a default palette.) */
  125. if (_plotter->hpgl_can_assign_colors)
  126. {
  127. sprintf (_plotter->data->page->point, "NP%d;", HPGL2_MAX_NUM_PENS);
  128. _update_buffer (_plotter->data->page);
  129. }
  130. /* use relative units for pen width */
  131. sprintf (_plotter->data->page->point, "WU1;");
  132. _update_buffer (_plotter->data->page);
  133. }
  134. /* select pen #1 (standard plotting convention) */
  135. sprintf (_plotter->data->page->point, "SP1;");
  136. _update_buffer (_plotter->data->page);
  137. /* For HP-GL/2 devices, set transparency mode to `opaque', if the user
  138. allows it. It should always be opaque to agree with libplot
  139. conventions, but on some HP-GL/2 devices (mostly pen plotters) the
  140. `TR' command allegedly does not NOP gracefully. */
  141. if (_plotter->hpgl_version == 2 && _plotter->hpgl_use_opaque_mode)
  142. {
  143. sprintf (_plotter->data->page->point, "TR0;");
  144. _update_buffer (_plotter->data->page);
  145. }
  146. /* freeze contents of output buffer, i.e. the initialization code we've
  147. just written to it, so that any later invocation of erase(), i.e.,
  148. erase_page(), won't remove it */
  149. _freeze_outbuf (_plotter->data->page);
  150. return true;
  151. }
  152. void
  153. _pl_h_maybe_switch_to_hpgl (S___(Plotter *_plotter))
  154. {
  155. }
  156. void
  157. _pl_q_maybe_switch_to_hpgl (S___(Plotter *_plotter))
  158. {
  159. if (_plotter->data->page_number > 1) /* not first page */
  160. /* eject previous page, by issuing PCL command */
  161. {
  162. strcpy (_plotter->data->page->point, "\f"); /* i.e. form feed */
  163. _update_buffer (_plotter->data->page);
  164. }
  165. /* switch from PCL 5 to HP-GL/2 mode */
  166. strcpy (_plotter->data->page->point, "\033%0B\n");
  167. _update_buffer (_plotter->data->page);
  168. }