h_defplot.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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 initializations for HPGLPlotter and PCLPlotter
  16. objects including both private data and public methods. There is a
  17. one-to-one correspondence between public methods and user-callable
  18. functions in the C API. */
  19. /* Originally, the only differences between the two types of Plotter were
  20. the PCL5 control codes that must be emitted to switch a PCL5 printer
  21. into HP-GL/2 mode, and back out of it.
  22. More recently, the two types of Plotter are distinguished by their
  23. viewport positioning. A PCL Plotter positions its viewport on the page
  24. in the same position that a PS, AI, or Fig Plotter does, i.e. it centers
  25. it. But a pure HPGL[/2] Plotter doesn't know where on the page the
  26. origin of the device coordinate system lies. (Though it's probably
  27. close to a corner.) Nor does can it set programmatically whether it's
  28. plotting in portrait or landscape mode. (It can flip between them, but
  29. it doesn't know which is which.)
  30. So HPGL Plotters use a viewport of the same default size as PCL, PS, AI,
  31. and Fig Plotters. But they don't position it: the lower left corner of
  32. the viewport is chosen to be the origin of the device coordinate system:
  33. what in HP-GL[/2] jargon is called "scaling point P1".
  34. For this to look reasonably good, the viewport needs to have a size
  35. appropriate for an HP-GL[/2] device. And in fact, that's what
  36. determines our choice of default viewport size -- for all Plotters, not
  37. just HPGLPlotters. See comments in g_pagetype.h. */
  38. #include "sys-defines.h"
  39. #include "extern.h"
  40. #define MAX_COLOR_NAME_LEN 32 /* long enough for all known colors */
  41. #ifndef LIBPLOTTER
  42. /* In libplot, this is the initialization for the function-pointer part of
  43. a HPGLPlotter struct. */
  44. const Plotter _pl_h_default_plotter =
  45. {
  46. /* initialization (after creation) and termination (before deletion) */
  47. _pl_h_initialize, _pl_h_terminate,
  48. /* page manipulation */
  49. _pl_h_begin_page, _pl_h_erase_page, _pl_h_end_page,
  50. /* drawing state manipulation */
  51. _pl_g_push_state, _pl_g_pop_state,
  52. /* internal path-painting methods (endpath() is a wrapper for the first) */
  53. _pl_h_paint_path, _pl_h_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
  54. /* internal methods for drawing of markers and points */
  55. _pl_g_paint_marker, _pl_h_paint_point,
  56. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  57. _pl_g_paint_text_string_with_escapes, _pl_h_paint_text_string,
  58. _pl_g_get_text_width,
  59. /* private low-level `retrieve font' method */
  60. _pl_g_retrieve_font,
  61. /* `flush output' method, called only if Plotter handles its own output */
  62. _pl_g_flush_output,
  63. /* error handlers */
  64. _pl_g_warning,
  65. _pl_g_error,
  66. };
  67. #endif /* not LIBPLOTTER */
  68. #ifndef LIBPLOTTER
  69. /* In libplot, this is the initialization for the function-pointer part of
  70. a PCLPlotter struct. It is the same as the above except for the
  71. different initialization and termination routines. */
  72. const Plotter _pl_q_default_plotter =
  73. {
  74. /* initialization (after creation) and termination (before deletion) */
  75. _pl_q_initialize, _pl_q_terminate,
  76. /* page manipulation */
  77. _pl_h_begin_page, _pl_h_erase_page, _pl_h_end_page,
  78. /* drawing state manipulation */
  79. _pl_g_push_state, _pl_g_pop_state,
  80. /* internal path-painting methods (endpath() is a wrapper for the first) */
  81. _pl_h_paint_path, _pl_h_paint_paths, _pl_g_path_is_flushable, _pl_g_maybe_prepaint_segments,
  82. /* internal methods for drawing of markers and points */
  83. _pl_g_paint_marker, _pl_h_paint_point,
  84. /* internal methods that plot strings in Hershey, non-Hershey fonts */
  85. _pl_g_paint_text_string_with_escapes, _pl_h_paint_text_string,
  86. _pl_g_get_text_width,
  87. /* private low-level `retrieve font' method */
  88. _pl_g_retrieve_font,
  89. /* `flush output' method, called only if Plotter handles its own output */
  90. _pl_g_flush_output,
  91. /* error handlers */
  92. _pl_g_warning,
  93. _pl_g_error,
  94. };
  95. #endif /* not LIBPLOTTER */
  96. /* The private `initialize' method, which is invoked when a Plotter is
  97. created. It is used for such things as initializing capability flags
  98. from the values of class variables, allocating storage, etc. When this
  99. is invoked, _plotter points to the Plotter that has just been
  100. created. */
  101. /* The initializations for HPGL and PCL Plotters are similar.
  102. For HPGL Plotters, we determine the HP-GL version from the environment
  103. variable HPGL_VERSION ("1", "1.5", or "2", meaning generic HP-GL,
  104. HP7550A, and modern HP-GL/2 respectively), and determine the page size
  105. and the location on the page of the viewport, so that we'll be able to
  106. work out the map from user coordinates to device coordinates in
  107. g_space.c.
  108. We allow the user to shift the location of the viewport by specifying an
  109. offset vector, since the origin of the HP-GL coordinate system and the
  110. size of the `hard-clip region' within which graphics can be drawn are
  111. not known. (There are so many HP-GL and HP-GL/2 devices.)
  112. We also work out which pens are available, and whether the device, if an
  113. HP-GL/2 device, supports the Palette Extension so that new logical pens
  114. can be defined as RGB triples. The HPGL_PENS and HPGL_ASSIGN_COLORS
  115. environment variables are used for this. (The default is for a generic
  116. HP-GL device to have exactly 1 pen, #1, and for an HP7550A or HP-GL/2
  117. device to have 7 pens, #1 through #7, with colors equal to the seven
  118. non-white vertices of the RGB color cube. We allow the user to specify
  119. up to 31 pens, #1 through #31, via HPGL_PENS. */
  120. void
  121. _pl_h_initialize (S___(Plotter *_plotter))
  122. {
  123. int i;
  124. #ifndef LIBPLOTTER
  125. /* in libplot, manually invoke superclass initialization method */
  126. _pl_g_initialize (S___(_plotter));
  127. #endif
  128. /* override generic initializations (which are appropriate to the base
  129. Plotter class), as necessary */
  130. #ifndef LIBPLOTTER
  131. /* tag field, differs in derived classes */
  132. _plotter->data->type = PL_HPGL;
  133. #endif
  134. /* output model */
  135. _plotter->data->output_model = PL_OUTPUT_ONE_PAGE_AT_A_TIME;
  136. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  137. _plotter->data->have_wide_lines = 1;
  138. _plotter->data->have_dash_array = 1;
  139. _plotter->data->have_solid_fill = 1;
  140. _plotter->data->have_odd_winding_fill = 1;
  141. _plotter->data->have_nonzero_winding_fill = 1;
  142. _plotter->data->have_settable_bg = 0;
  143. _plotter->data->have_escaped_string_support = 0;
  144. #ifdef USE_PS_FONTS_IN_PCL
  145. _plotter->data->have_ps_fonts = 1;
  146. #else
  147. _plotter->data->have_ps_fonts = 0;
  148. #endif
  149. _plotter->data->have_pcl_fonts = 1;
  150. _plotter->data->have_stick_fonts = 1;
  151. _plotter->data->have_extra_stick_fonts = 1;
  152. _plotter->data->have_other_fonts = 0;
  153. /* text and font-related parameters (internal, not queryable by user) */
  154. _plotter->data->default_font_type = PL_F_HERSHEY;
  155. _plotter->data->pcl_before_ps = true;
  156. _plotter->data->have_horizontal_justification = false;
  157. _plotter->data->have_vertical_justification = false;
  158. _plotter->data->kern_stick_fonts = true;
  159. _plotter->data->issue_font_warning = true;
  160. /* path-related parameters (also internal); note that we
  161. don't set max_unfilled_path_length, because it was set by the
  162. superclass initialization */
  163. _plotter->data->have_mixed_paths = true;
  164. _plotter->data->allowed_arc_scaling = AS_UNIFORM;
  165. _plotter->data->allowed_ellarc_scaling = AS_NONE;
  166. _plotter->data->allowed_quad_scaling = AS_NONE;
  167. _plotter->data->allowed_cubic_scaling = AS_NONE;
  168. _plotter->data->allowed_box_scaling = AS_AXES_PRESERVED;
  169. _plotter->data->allowed_circle_scaling = AS_UNIFORM;
  170. _plotter->data->allowed_ellipse_scaling = AS_NONE;
  171. /* dimensions */
  172. _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
  173. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI;
  174. _plotter->data->flipped_y = false;
  175. _plotter->data->imin = 0;
  176. _plotter->data->imax = 0;
  177. _plotter->data->jmin = 0;
  178. _plotter->data->jmax = 0;
  179. _plotter->data->xmin = HPGL_SCALED_DEVICE_LEFT;
  180. _plotter->data->xmax = HPGL_SCALED_DEVICE_RIGHT;
  181. _plotter->data->ymin = HPGL_SCALED_DEVICE_BOTTOM;
  182. _plotter->data->ymax = HPGL_SCALED_DEVICE_TOP;
  183. _plotter->data->page_data = (plPageData *)NULL;
  184. /* compute the NDC to device-frame affine map, set it in Plotter */
  185. _compute_ndc_to_device_map (_plotter->data);
  186. /* initialize data members specific to this derived class */
  187. /* parameters */
  188. _plotter->hpgl_version = 2;
  189. _plotter->hpgl_rotation = 0;
  190. _plotter->hpgl_p1.x = 0.0;
  191. _plotter->hpgl_p1.y = 8128.0;
  192. _plotter->hpgl_p2.x = 0.0;
  193. _plotter->hpgl_p2.y = 8128.0;
  194. _plotter->hpgl_plot_length = 10668.0;
  195. _plotter->hpgl_have_screened_vectors = false;
  196. _plotter->hpgl_have_char_fill = false;
  197. _plotter->hpgl_can_assign_colors = false;
  198. _plotter->hpgl_use_opaque_mode = true;
  199. /* dynamic variables */
  200. /* pen_color[] and pen_defined[] arrays also used */
  201. _plotter->hpgl_pen = 1;
  202. _plotter->hpgl_free_pen = 2;
  203. _plotter->hpgl_bad_pen = false;
  204. _plotter->hpgl_pendown = false;
  205. _plotter->hpgl_pen_width = 0.001;
  206. _plotter->hpgl_line_type = HPGL_L_SOLID;
  207. _plotter->hpgl_cap_style = HPGL_CAP_BUTT;
  208. _plotter->hpgl_join_style = HPGL_JOIN_MITER;
  209. _plotter->hpgl_miter_limit = 5.0; /* default HP-GL/2 value */
  210. _plotter->hpgl_pen_type = HPGL_PEN_SOLID;
  211. _plotter->hpgl_pen_option1 = 0.0;
  212. _plotter->hpgl_pen_option2 = 0.0;
  213. _plotter->hpgl_fill_type = HPGL_FILL_SOLID_BI;
  214. _plotter->hpgl_fill_option1 = 0.0;
  215. _plotter->hpgl_fill_option2 = 0.0;
  216. _plotter->hpgl_char_rendering_type = HPGL_CHAR_FILL_SOLID_AND_MAYBE_EDGE;
  217. _plotter->hpgl_symbol_set = PCL_ROMAN_8;
  218. _plotter->hpgl_spacing = 0;
  219. _plotter->hpgl_posture = 0;
  220. _plotter->hpgl_stroke_weight = 0;
  221. _plotter->hpgl_pcl_typeface = PCL_STICK_TYPEFACE;
  222. _plotter->hpgl_charset_lower = HPGL_CHARSET_ASCII;
  223. _plotter->hpgl_charset_upper = HPGL_CHARSET_ASCII;
  224. _plotter->hpgl_rel_char_height = 0.0;
  225. _plotter->hpgl_rel_char_width = 0.0;
  226. _plotter->hpgl_rel_label_rise = 0.0;
  227. _plotter->hpgl_rel_label_run = 0.0;
  228. _plotter->hpgl_tan_char_slant = 0.0;
  229. _plotter->hpgl_position_is_unknown = true;
  230. _plotter->hpgl_pos.x = 0;
  231. _plotter->hpgl_pos.y = 0;
  232. /* note: this driver also uses pen_color[], pen_defined[] arrays;
  233. see initializations below */
  234. /* initialize certain data members from device driver parameters */
  235. /* determine HP-GL version */
  236. {
  237. const char *version_s;
  238. version_s = (const char *)_get_plot_param (_plotter->data, "HPGL_VERSION");
  239. /* there are three subcases: "1", "1.5", and "2" (default, see above) */
  240. if (strcmp (version_s, "1") == 0) /* generic HP-GL, HP7220 or HP7475A */
  241. {
  242. _plotter->hpgl_version = 0;
  243. _plotter->data->have_wide_lines = 0;
  244. _plotter->data->have_dash_array = 0;
  245. _plotter->data->have_solid_fill = 0;
  246. _plotter->data->have_odd_winding_fill = 1;
  247. _plotter->data->have_nonzero_winding_fill = 0;
  248. _plotter->data->have_ps_fonts = 0;
  249. _plotter->data->have_pcl_fonts = 0;
  250. _plotter->data->have_stick_fonts = 1;
  251. _plotter->data->have_extra_stick_fonts = 0;
  252. _plotter->data->kern_stick_fonts = true;
  253. _plotter->data->have_other_fonts = 0;
  254. }
  255. else if (strcmp (version_s, "1.5") == 0) /* HP7550A */
  256. {
  257. _plotter->hpgl_version = 1;
  258. _plotter->data->have_wide_lines = 0;
  259. _plotter->data->have_dash_array = 0;
  260. _plotter->data->have_solid_fill = 1;
  261. _plotter->data->have_odd_winding_fill = 1;
  262. _plotter->data->have_nonzero_winding_fill = 0;
  263. _plotter->data->have_ps_fonts = 0;
  264. _plotter->data->have_pcl_fonts = 0;
  265. _plotter->data->have_stick_fonts = 1;
  266. _plotter->data->have_extra_stick_fonts = 1;
  267. _plotter->data->kern_stick_fonts = true;
  268. _plotter->data->have_other_fonts = 0;
  269. }
  270. }
  271. /* Determine range of device coordinates over which the viewport will
  272. extend (and hence the transformation from user to device coordinates;
  273. see g_space.c). */
  274. /* NOTE: HP-GL Plotters, unlike PCL Plotters, ignore the xorigin and
  275. yorigin fields of the PAGESIZE parameter. That's because the device
  276. coordinate system isn't well specified. However, the viewport can be
  277. shifted relative to its default location, as usual, by specifying the
  278. xoffset and yoffset fields. */
  279. /* We use the corners of the viewport, in device coordinates, as our
  280. `scaling points' P1 and P2 (see h_openpl.c). The coordinates we use
  281. in our output file will be normalized device coordinates, not physical
  282. device coordinates (for the map from the former to the latter, which
  283. is accomplished by the HP-GL `SC' instruction, see h_openpl.c). */
  284. {
  285. /* determine page type, and viewport size and location */
  286. _set_page_type (_plotter->data);
  287. /* by default, viewport lower left corner is (0,0) in HP-GL
  288. coordinates; if a user wishes to change this, the xoffset and
  289. yoffset parameters should be added to PAGESIZE */
  290. _plotter->hpgl_p1.x = (HPGL_UNITS_PER_INCH
  291. * (0.0
  292. + _plotter->data->viewport_xoffset));
  293. _plotter->hpgl_p2.x = (HPGL_UNITS_PER_INCH
  294. * (0.0
  295. + _plotter->data->viewport_xoffset
  296. + _plotter->data->viewport_xsize));
  297. _plotter->hpgl_p1.y = (HPGL_UNITS_PER_INCH
  298. * (0.0
  299. + _plotter->data->viewport_yoffset));
  300. _plotter->hpgl_p2.y = (HPGL_UNITS_PER_INCH
  301. * (0.0
  302. + _plotter->data->viewport_yoffset
  303. + _plotter->data->viewport_ysize));
  304. _plotter->data->xmin = HPGL_SCALED_DEVICE_LEFT;
  305. _plotter->data->xmax = HPGL_SCALED_DEVICE_RIGHT;
  306. _plotter->data->ymin = HPGL_SCALED_DEVICE_BOTTOM;
  307. _plotter->data->ymax = HPGL_SCALED_DEVICE_TOP;
  308. /* plot length (to be emitted in an HP-GL/2 `PS' instruction, important
  309. mostly for roll plotters; see h_openpl.c) */
  310. _plotter->hpgl_plot_length =
  311. _plotter->data->page_data->hpgl2_plot_length * HPGL_UNITS_PER_INCH;
  312. }
  313. /* determine whether to rotate the figure (e.g. horizontal instead of
  314. vertical, see h_openpl.c) */
  315. {
  316. const char *rotate_s;
  317. rotate_s = (const char *)_get_plot_param (_plotter->data, "HPGL_ROTATE");
  318. /* four subcases: 0 (default), 90, 180, 270 (latter two only if "2") */
  319. if (strcasecmp (rotate_s, "yes") == 0
  320. || strcmp (rotate_s, "90") == 0)
  321. _plotter->hpgl_rotation = 90;
  322. else if (strcmp (rotate_s, "180") == 0 && _plotter->hpgl_version == 2)
  323. _plotter->hpgl_rotation = 180;
  324. else if (strcmp (rotate_s, "270") == 0 && _plotter->hpgl_version == 2)
  325. _plotter->hpgl_rotation = 270;
  326. else
  327. _plotter->hpgl_rotation = 0;
  328. }
  329. /* Should we avoid emitting the `white is opaque' HP-GL/2 instruction?
  330. (HP-GL/2 pen plotters may not like it) */
  331. {
  332. const char *transparent_s;
  333. transparent_s = (const char *)_get_plot_param (_plotter->data, "HPGL_OPAQUE_MODE" );
  334. if (strcasecmp (transparent_s, "no") == 0)
  335. _plotter->hpgl_use_opaque_mode = false;
  336. }
  337. /* do we support the HP-GL/2 palette extension, i.e. can we define new
  338. logical pens as RGB triples? (user must request this with
  339. HPGL_ASSIGN_COLORS) */
  340. if (_plotter->hpgl_version == 2)
  341. {
  342. const char *palette_s;
  343. palette_s = (const char *)_get_plot_param (_plotter->data, "HPGL_ASSIGN_COLORS");
  344. if (strcasecmp (palette_s, "yes") == 0)
  345. _plotter->hpgl_can_assign_colors = true;
  346. }
  347. /* initialize pen color array, typically 0..31 */
  348. for (i = 0; i < HPGL2_MAX_NUM_PENS; i++)
  349. _plotter->hpgl_pen_defined[i] = 0; /* pen absent, or at least undefined */
  350. /* pen #0 (white pen, RGB=255,255,255) is always defined */
  351. _plotter->hpgl_pen_color[0].red = 255;
  352. _plotter->hpgl_pen_color[0].green = 255;
  353. _plotter->hpgl_pen_color[0].blue = 255;
  354. _plotter->hpgl_pen_defined[0] = 2; /* i.e. hard-defined */
  355. /* determine initial palette, i.e. available pens in 1..31 range */
  356. {
  357. const char *pen_s;
  358. pen_s = (const char *)_get_plot_param (_plotter->data, "HPGL_PENS");
  359. if (pen_s == NULL
  360. || _pl_h_parse_pen_string (R___(_plotter) pen_s) == false
  361. || (_plotter->hpgl_can_assign_colors == false
  362. && _plotter->hpgl_pen_defined[1] == 0))
  363. /* Either user didn't assign a value, or it was bad; use default.
  364. Note that if no logical pens, we insist on pen #1 being present
  365. (for backward compatibility?). */
  366. {
  367. if (_plotter->hpgl_version == 0) /* i.e. generic HP-GL */
  368. pen_s = HPGL_DEFAULT_PEN_STRING;
  369. else
  370. pen_s = HPGL2_DEFAULT_PEN_STRING;
  371. _pl_h_parse_pen_string (R___(_plotter) pen_s); /* default is guaranteed to parse */
  372. }
  373. }
  374. /* Examine presence or absence of hard-defined pens in 2..31 range.
  375. 0 = undefined, 1 = soft-defined (not yet), 2 = hard-defined. */
  376. {
  377. bool undefined_pen_seen = false;
  378. for (i = 2; i < HPGL2_MAX_NUM_PENS; i++)
  379. {
  380. if (_plotter->hpgl_pen_defined[i] == 0)
  381. /* at least one pen with number > 1 is not yet defined */
  382. {
  383. /* record which such was encountered first */
  384. _plotter->hpgl_free_pen = i;
  385. undefined_pen_seen = true;
  386. break;
  387. }
  388. }
  389. if (!undefined_pen_seen)
  390. /* too many pens specified, can't soft-define colors */
  391. _plotter->hpgl_can_assign_colors = false;
  392. }
  393. }
  394. /* Initialization for the PCLPlotter class, which is subclassed from the
  395. HPGLPlotter class. */
  396. void
  397. _pl_q_initialize (S___(Plotter *_plotter))
  398. {
  399. int i;
  400. #ifndef LIBPLOTTER
  401. /* in libplot, manually invoke superclass initialization method */
  402. _pl_h_initialize (S___(_plotter));
  403. #endif
  404. /* Superclass initialization (i.e., of an HPGLPlotter) may well have
  405. screwed things up, since e.g. for a PCLPlotter, hpgl_version should
  406. always be equal to 2, irrespective of what HPGL_VERSION is; also the
  407. viewport positioning is different. So we redo a large part of the
  408. initialization, most of which is redundant (FIXME). */
  409. #ifndef LIBPLOTTER
  410. /* tag field, differs in derived classes */
  411. _plotter->data->type = PL_PCL;
  412. #endif
  413. /* output model */
  414. _plotter->data->output_model = PL_OUTPUT_ONE_PAGE_AT_A_TIME;
  415. /* user-queryable capabilities: 0/1/2 = no/yes/maybe */
  416. _plotter->data->have_wide_lines = 1;
  417. _plotter->data->have_dash_array = 1;
  418. _plotter->data->have_solid_fill = 1;
  419. _plotter->data->have_odd_winding_fill = 1;
  420. _plotter->data->have_nonzero_winding_fill = 1;
  421. _plotter->data->have_settable_bg = 0;
  422. _plotter->data->have_escaped_string_support = 0;
  423. #ifdef USE_PS_FONTS_IN_PCL
  424. _plotter->data->have_ps_fonts = 1;
  425. #else
  426. _plotter->data->have_ps_fonts = 0;
  427. #endif
  428. _plotter->data->have_pcl_fonts = 1;
  429. _plotter->data->have_stick_fonts = 1;
  430. _plotter->data->have_extra_stick_fonts = 0;
  431. _plotter->data->have_other_fonts = 0;
  432. /* text and font-related parameters (internal, not queryable by user) */
  433. _plotter->data->default_font_type = PL_F_PCL;
  434. _plotter->data->pcl_before_ps = true;
  435. _plotter->data->have_horizontal_justification = false;
  436. _plotter->data->have_vertical_justification = false;
  437. _plotter->data->kern_stick_fonts = false; /* in PCL5 printers' HP-GL/2 emulation */
  438. _plotter->data->issue_font_warning = true;
  439. /* path-related parameters (also internal); note that we
  440. don't set max_unfilled_path_length, because it was set by the
  441. superclass initialization */
  442. _plotter->data->have_mixed_paths = true;
  443. _plotter->data->allowed_arc_scaling = AS_UNIFORM;
  444. _plotter->data->allowed_ellarc_scaling = AS_NONE;
  445. _plotter->data->allowed_quad_scaling = AS_NONE;
  446. _plotter->data->allowed_cubic_scaling = AS_ANY;
  447. _plotter->data->allowed_box_scaling = AS_AXES_PRESERVED;
  448. _plotter->data->allowed_circle_scaling = AS_UNIFORM;
  449. _plotter->data->allowed_ellipse_scaling = AS_NONE;
  450. /* dimensions, differ in derived classes */
  451. _plotter->data->display_model_type = (int)DISP_MODEL_PHYSICAL;
  452. _plotter->data->display_coors_type = (int)DISP_DEVICE_COORS_INTEGER_NON_LIBXMI;
  453. _plotter->data->flipped_y = false;
  454. _plotter->data->imin = 0;
  455. _plotter->data->imax = 0;
  456. _plotter->data->jmin = 0;
  457. _plotter->data->jmax = 0;
  458. _plotter->data->xmin = HPGL_SCALED_DEVICE_LEFT;
  459. _plotter->data->xmax = HPGL_SCALED_DEVICE_RIGHT;
  460. _plotter->data->ymin = HPGL_SCALED_DEVICE_BOTTOM;
  461. _plotter->data->ymax = HPGL_SCALED_DEVICE_TOP;
  462. _plotter->data->page_data = (plPageData *)NULL;
  463. /* compute the NDC to device-frame affine map, set it in Plotter */
  464. _compute_ndc_to_device_map (_plotter->data);
  465. /* initialize data members specific to this derived class */
  466. /* parameters */
  467. _plotter->hpgl_version = 2;
  468. _plotter->hpgl_rotation = 0;
  469. _plotter->hpgl_p1.x = 0.0;
  470. _plotter->hpgl_p1.y = 8128.0;
  471. _plotter->hpgl_p2.x = 0.0;
  472. _plotter->hpgl_p2.y = 8128.0;
  473. _plotter->hpgl_plot_length = 10668.0;
  474. _plotter->hpgl_have_screened_vectors = true; /* different from HPGLPlotter */
  475. _plotter->hpgl_have_char_fill = true; /* different from HPGLPlotter */
  476. _plotter->hpgl_can_assign_colors = false;
  477. _plotter->hpgl_use_opaque_mode = true;
  478. /* dynamic variables */
  479. /* pen_color[] and pen_defined[] arrays also used */
  480. _plotter->hpgl_pen = 1;
  481. _plotter->hpgl_free_pen = 2;
  482. _plotter->hpgl_bad_pen = false;
  483. _plotter->hpgl_pendown = false;
  484. _plotter->hpgl_pen_width = 0.001;
  485. _plotter->hpgl_line_type = HPGL_L_SOLID;
  486. _plotter->hpgl_cap_style = HPGL_CAP_BUTT;
  487. _plotter->hpgl_join_style = HPGL_JOIN_MITER;
  488. /* Maximum value the cosecant of the half-angle between any two line
  489. segments can have, if the join is to be mitered rather than beveled.
  490. Default HP-GL/2 value is 5.0. */
  491. _plotter->hpgl_miter_limit = 5.0;
  492. _plotter->hpgl_pen_type = HPGL_PEN_SOLID;
  493. _plotter->hpgl_pen_option1 = 0.0;
  494. _plotter->hpgl_pen_option2 = 0.0;
  495. _plotter->hpgl_fill_type = HPGL_FILL_SOLID_BI;
  496. _plotter->hpgl_fill_option1 = 0.0;
  497. _plotter->hpgl_fill_option2 = 0.0;
  498. _plotter->hpgl_char_rendering_type = HPGL_CHAR_FILL_SOLID_AND_MAYBE_EDGE;
  499. _plotter->hpgl_symbol_set = PCL_ROMAN_8;
  500. _plotter->hpgl_spacing = 0;
  501. _plotter->hpgl_posture = 0;
  502. _plotter->hpgl_stroke_weight = 0;
  503. _plotter->hpgl_pcl_typeface = PCL_STICK_TYPEFACE;
  504. _plotter->hpgl_charset_lower = HPGL_CHARSET_ASCII;
  505. _plotter->hpgl_charset_upper = HPGL_CHARSET_ASCII;
  506. _plotter->hpgl_rel_char_height = 0.0;
  507. _plotter->hpgl_rel_char_width = 0.0;
  508. _plotter->hpgl_rel_label_rise = 0.0;
  509. _plotter->hpgl_rel_label_run = 0.0;
  510. _plotter->hpgl_tan_char_slant = 0.0;
  511. /* note: this driver also uses pen_color[], pen_defined[] arrays;
  512. see initializations below */
  513. /* initialize certain data members from device driver parameters */
  514. /* Determine range of device coordinates over which the viewport will
  515. extend (and hence the transformation from user to device coordinates;
  516. see g_space.c). */
  517. /* We use the corners of the viewport, in device coordinates, as our
  518. `scaling points' P1 and P2 (see h_openpl.c). The coordinates we use
  519. in our output file will be normalized device coordinates, not physical
  520. device coordinates (for the map from the former to the latter, which
  521. is accomplished by the HP-GL `SC' instruction, see h_openpl.c). */
  522. {
  523. /* determine page type, viewport size and location */
  524. _set_page_type (_plotter->data);
  525. /* convert viewport size-and-location data (in terms of inches) to
  526. device coordinates (i.e. HP-GL units) */
  527. /* NOTE: origin of HP-GL/2 coordinate system used by a PCL5 device is
  528. not at lower left corner of page; must compensate by subtracting the
  529. `pcl_hpgl2_?origin' quantities. */
  530. _plotter->hpgl_p1.x = (HPGL_UNITS_PER_INCH
  531. * (_plotter->data->viewport_xorigin
  532. + _plotter->data->viewport_xoffset
  533. - _plotter->data->page_data->pcl_hpgl2_xorigin));
  534. _plotter->hpgl_p2.x = (HPGL_UNITS_PER_INCH
  535. * (_plotter->data->viewport_xorigin
  536. + _plotter->data->viewport_xoffset
  537. + _plotter->data->viewport_xsize
  538. - _plotter->data->page_data->pcl_hpgl2_xorigin));
  539. _plotter->hpgl_p1.y = (HPGL_UNITS_PER_INCH
  540. * (_plotter->data->viewport_yorigin
  541. + _plotter->data->viewport_yoffset
  542. - _plotter->data->page_data->pcl_hpgl2_yorigin));
  543. _plotter->hpgl_p2.y = (HPGL_UNITS_PER_INCH
  544. * (_plotter->data->viewport_yorigin
  545. + _plotter->data->viewport_yoffset
  546. + _plotter->data->viewport_ysize
  547. - _plotter->data->page_data->pcl_hpgl2_yorigin));
  548. /* plot length (to be emitted in an HP-GL/2 `PS' instruction, important
  549. mostly for roll plotters; see h_openpl.c) */
  550. _plotter->hpgl_plot_length =
  551. _plotter->data->page_data->hpgl2_plot_length * HPGL_UNITS_PER_INCH;
  552. }
  553. /* don't make use of HP-GL/2's plotting-area rotation facility; if we
  554. wish to switch between portrait and landscape modes we'll do so from
  555. within PCL5 */
  556. _plotter->hpgl_rotation = 0;
  557. /* do we support the HP-GL/2 palette extension, i.e. can we define new
  558. logical pens as RGB triples? (user must request this with
  559. PCL_ASSIGN_COLORS) */
  560. _plotter->hpgl_can_assign_colors = false;
  561. {
  562. const char *palette_s;
  563. palette_s = (const char *)_get_plot_param (_plotter->data, "PCL_ASSIGN_COLORS");
  564. if (strcasecmp (palette_s, "yes") == 0)
  565. _plotter->hpgl_can_assign_colors = true;
  566. }
  567. /* do we use the HP-GL/2 `BZ' instruction for drawing Beziers? (the
  568. LaserJet III did not support it) */
  569. {
  570. const char *bezier_s;
  571. bezier_s = (const char *)_get_plot_param (_plotter->data, "PCL_BEZIERS");
  572. if (strcasecmp (bezier_s, "yes") != 0)
  573. _plotter->data->allowed_cubic_scaling = AS_NONE;
  574. }
  575. /* initialize pen color array, typically 0..31 */
  576. for (i = 0; i < HPGL2_MAX_NUM_PENS; i++)
  577. _plotter->hpgl_pen_defined[i] = 0; /* pen absent, or at least undefined */
  578. /* pen #0 (white pen, RGB=255,255,255) is always defined */
  579. _plotter->hpgl_pen_color[0].red = 255;
  580. _plotter->hpgl_pen_color[0].green = 255;
  581. _plotter->hpgl_pen_color[0].blue = 255;
  582. _plotter->hpgl_pen_defined[0] = 2; /* i.e. hard-defined */
  583. /* determine initial palette, i.e. available pens in 1..31 range; for a
  584. PCLPlotter we use the default HP-GL/2 pen string */
  585. {
  586. const char *pen_s;
  587. pen_s = HPGL2_DEFAULT_PEN_STRING;
  588. _pl_h_parse_pen_string (R___(_plotter) pen_s); /* default is guaranteed to parse */
  589. }
  590. /* Examine presence or absence of hard-defined pens in 2..31 range.
  591. 0 = undefined, 1 = soft-defined (not yet), 2 = hard-defined. */
  592. {
  593. bool undefined_pen_seen = false;
  594. for (i = 2; i < HPGL2_MAX_NUM_PENS; i++)
  595. {
  596. if (_plotter->hpgl_pen_defined[i] == 0)
  597. /* at least one pen with number > 1 is not yet defined */
  598. {
  599. /* record which such was encountered first */
  600. _plotter->hpgl_free_pen = i;
  601. undefined_pen_seen = true;
  602. break;
  603. }
  604. }
  605. if (!undefined_pen_seen)
  606. /* too many pens specified, can't soft-define colors */
  607. _plotter->hpgl_can_assign_colors = false;
  608. }
  609. }
  610. /* Parse a pen string, e.g. a user-specified HPGL_PENS environment
  611. variable, specifying which pens are available. Result is stored in the
  612. Plotter. More pens (logical pens) may be added later to the array of
  613. available pens, if the plotter is an HP-GL/2 device and supports the
  614. palette extension. User specifies this by setting the
  615. HPGL_ASSIGN_COLORS environment variable to "yes"; see above. */
  616. bool
  617. _pl_h_parse_pen_string (R___(Plotter *_plotter) const char *pen_s)
  618. {
  619. const char *charp;
  620. char name[MAX_COLOR_NAME_LEN];
  621. int i;
  622. charp = pen_s;
  623. while (*charp)
  624. {
  625. int pen_num;
  626. bool got_digit;
  627. const char *tmp;
  628. plColor color;
  629. if (*charp == ':') /* skip any ':' */
  630. {
  631. charp++;
  632. continue; /* back to top of while loop */
  633. }
  634. pen_num = 0;
  635. got_digit = false;
  636. while (*charp >= '0' && *charp <= '9')
  637. {
  638. pen_num = 10 * pen_num + (int)*charp - (int)'0';
  639. got_digit = true;
  640. charp++;
  641. }
  642. if (!got_digit || pen_num < 1 || pen_num >= HPGL2_MAX_NUM_PENS)
  643. return false;
  644. if (*charp != '=')
  645. return false;
  646. charp++;
  647. for (tmp = charp, i = 0; i < MAX_COLOR_NAME_LEN; tmp++, i++)
  648. {
  649. if (*tmp == ':') /* end of color name string */
  650. {
  651. name[i] = '\0';
  652. charp = tmp + 1;
  653. break;
  654. }
  655. else if (*tmp == '\0') /* end of name string and env var also */
  656. {
  657. name[i] = '\0';
  658. charp = tmp;
  659. break;
  660. }
  661. else
  662. name[i] = *tmp;
  663. }
  664. /* got color name string, parse it */
  665. if (_string_to_color (name, &color, _plotter->data->color_name_cache))
  666. {
  667. _plotter->hpgl_pen_color[pen_num] = color;
  668. _plotter->hpgl_pen_defined[pen_num] = 2; /* hard-defined */
  669. }
  670. else /* couldn't match color name string */
  671. return false;
  672. }
  673. return true;
  674. }
  675. /* The private `terminate' method, which is invoked when a Plotter is
  676. deleted. It may do such things as write to an output stream from
  677. internal storage, deallocate storage, etc. When this is invoked,
  678. _plotter points to the Plotter that is about to be deleted. */
  679. void
  680. _pl_h_terminate (S___(Plotter *_plotter))
  681. {
  682. #ifndef LIBPLOTTER
  683. /* in libplot, manually invoke superclass termination method */
  684. _pl_g_terminate (S___(_plotter));
  685. #endif
  686. }
  687. void
  688. _pl_q_terminate (S___(Plotter *_plotter))
  689. {
  690. #ifndef LIBPLOTTER
  691. /* in libplot, manually invoke superclass termination method */
  692. _pl_h_terminate (S___(_plotter));
  693. #endif
  694. }
  695. #ifdef LIBPLOTTER
  696. HPGLPlotter::HPGLPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  697. :Plotter (infile, outfile, errfile)
  698. {
  699. _pl_h_initialize ();
  700. }
  701. HPGLPlotter::HPGLPlotter (FILE *outfile)
  702. :Plotter (outfile)
  703. {
  704. _pl_h_initialize ();
  705. }
  706. HPGLPlotter::HPGLPlotter (istream& in, ostream& out, ostream& err)
  707. : Plotter (in, out, err)
  708. {
  709. _pl_h_initialize ();
  710. }
  711. HPGLPlotter::HPGLPlotter (ostream& out)
  712. : Plotter (out)
  713. {
  714. _pl_h_initialize ();
  715. }
  716. HPGLPlotter::HPGLPlotter ()
  717. {
  718. _pl_h_initialize ();
  719. }
  720. HPGLPlotter::HPGLPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  721. :Plotter (infile, outfile, errfile, parameters)
  722. {
  723. _pl_h_initialize ();
  724. }
  725. HPGLPlotter::HPGLPlotter (FILE *outfile, PlotterParams &parameters)
  726. :Plotter (outfile, parameters)
  727. {
  728. _pl_h_initialize ();
  729. }
  730. HPGLPlotter::HPGLPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  731. : Plotter (in, out, err, parameters)
  732. {
  733. _pl_h_initialize ();
  734. }
  735. HPGLPlotter::HPGLPlotter (ostream& out, PlotterParams &parameters)
  736. : Plotter (out, parameters)
  737. {
  738. _pl_h_initialize ();
  739. }
  740. HPGLPlotter::HPGLPlotter (PlotterParams &parameters)
  741. : Plotter (parameters)
  742. {
  743. _pl_h_initialize ();
  744. }
  745. HPGLPlotter::~HPGLPlotter ()
  746. {
  747. /* if luser left the Plotter open, close it */
  748. if (_plotter->data->open)
  749. _API_closepl ();
  750. _pl_h_terminate ();
  751. }
  752. #endif
  753. #ifdef LIBPLOTTER
  754. PCLPlotter::PCLPlotter (FILE *infile, FILE *outfile, FILE *errfile)
  755. :HPGLPlotter (infile, outfile, errfile)
  756. {
  757. _pl_q_initialize ();
  758. }
  759. PCLPlotter::PCLPlotter (FILE *outfile)
  760. :HPGLPlotter (outfile)
  761. {
  762. _pl_q_initialize ();
  763. }
  764. PCLPlotter::PCLPlotter (istream& in, ostream& out, ostream& err)
  765. : HPGLPlotter (in, out, err)
  766. {
  767. _pl_q_initialize ();
  768. }
  769. PCLPlotter::PCLPlotter (ostream& out)
  770. : HPGLPlotter (out)
  771. {
  772. _pl_q_initialize ();
  773. }
  774. PCLPlotter::PCLPlotter ()
  775. {
  776. _pl_q_initialize ();
  777. }
  778. PCLPlotter::PCLPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams &parameters)
  779. :HPGLPlotter (infile, outfile, errfile, parameters)
  780. {
  781. _pl_q_initialize ();
  782. }
  783. PCLPlotter::PCLPlotter (FILE *outfile, PlotterParams &parameters)
  784. :HPGLPlotter (outfile, parameters)
  785. {
  786. _pl_q_initialize ();
  787. }
  788. PCLPlotter::PCLPlotter (istream& in, ostream& out, ostream& err, PlotterParams &parameters)
  789. : HPGLPlotter (in, out, err, parameters)
  790. {
  791. _pl_q_initialize ();
  792. }
  793. PCLPlotter::PCLPlotter (ostream& out, PlotterParams &parameters)
  794. : HPGLPlotter (out, parameters)
  795. {
  796. _pl_q_initialize ();
  797. }
  798. PCLPlotter::PCLPlotter (PlotterParams &parameters)
  799. : HPGLPlotter (parameters)
  800. {
  801. _pl_q_initialize ();
  802. }
  803. PCLPlotter::~PCLPlotter ()
  804. {
  805. /* if luser left the Plotter open, close it */
  806. if (_plotter->data->open)
  807. _API_closepl ();
  808. _pl_q_terminate ();
  809. }
  810. #endif
  811. #ifndef LIBPLOTTER
  812. /* The following forwarding functions provide special support in libplot
  813. for deriving the PCLPlotter class from the HPGLPlotter class. In
  814. libplotter, forwarding is implemented by a virtual function; see
  815. plotter.h. */
  816. /* Two forwarding functions called by any HPGLPlotter/PCLPlotter in
  817. begin_page() and end_page(), respectively. See h_openpl.c and
  818. h_closepl.c for the forwarded-to functions _pl_h_maybe_switch_to_hpgl(),
  819. _pl_q_maybe_switch_to_hpgl(), _pl_h_maybe_switch_from_hpgl(),
  820. _pl_q_maybe_switch_from_hpgl(). The HPGLPlotter versions are no-ops, but
  821. the PCLPlotter versions switch the printer to HP-GL/2 mode from PCL 5
  822. mode, and back to PCL 5 mode from HP-GL/2 mode. */
  823. /* Eject page (if page number > 1) and switch from PCL 5 mode to HP-GL/2
  824. mode, if a PCL 5 printer (otherwise it's a no-op). Invoked by
  825. begin_page(). */
  826. void
  827. _maybe_switch_to_hpgl (Plotter *_plotter)
  828. {
  829. switch ((int)(_plotter->data->type))
  830. {
  831. case (int)PL_HPGL:
  832. default:
  833. _pl_h_maybe_switch_to_hpgl (_plotter); /* no-op */
  834. break;
  835. case (int)PL_PCL:
  836. _pl_q_maybe_switch_to_hpgl (_plotter);
  837. break;
  838. }
  839. }
  840. /* Switch back to PCL 5 mode from HP-GL/2 mode, if a PCL 5 printer
  841. (otherwise it's a no-op). Invoked by end_page(). */
  842. void
  843. _maybe_switch_from_hpgl (Plotter *_plotter)
  844. {
  845. switch ((int)(_plotter->data->type))
  846. {
  847. case (int)PL_HPGL:
  848. default:
  849. _pl_h_maybe_switch_from_hpgl (_plotter); /* no-op */
  850. break;
  851. case (int)PL_PCL:
  852. _pl_q_maybe_switch_from_hpgl (_plotter);
  853. break;
  854. }
  855. }
  856. #endif /* not LIBPLOTTER */