gdevclj.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /* Copyright (C) 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /* $Id: gdevclj.c,v 1.2 2000/09/19 19:00:12 lpd Exp $ */
  16. /*
  17. * H-P Color LaserJet 5/5M device; based on the PaintJet.
  18. */
  19. #include "math_.h"
  20. #include "gx.h"
  21. #include "gsparam.h"
  22. #include "gdevprn.h"
  23. #include "gdevpcl.h"
  24. typedef struct gx_device_clj_s gx_device_clj;
  25. struct gx_device_clj_s {
  26. gx_device_common;
  27. gx_prn_device_common;
  28. bool rotated;
  29. };
  30. #define pclj ((gx_device_clj *)pdev)
  31. /*
  32. * The HP Color LaserJet 5/5M provides a rather unexpected speed/performance
  33. * tradeoff.
  34. *
  35. * When generating rasters, only the fixed (simple) color spaces provide
  36. * reasonable performance (in this case, reasonable != good). However, in
  37. * these modes, certain of the fully-saturated primary colors (cyan, blue,
  38. * green, and red) are rendered differently as rasters as opposed to colored
  39. * geometric objects. Hence, the color of the output will be other than what
  40. * is expected.
  41. *
  42. * Alternatively, the direct color, 1-bit per pixel scheme can be used. This
  43. * will produce the expected colors, but performance will deteriorate
  44. * significantly (observed printing time will be about 3 times longer than
  45. * when using the simple color mode).
  46. *
  47. * Note that when using the latter mode to view output from the PCL
  48. * interpreter, geometric objects and raster rendered with other than
  49. * geometric color spaces will have the same appearance as if sent directly
  50. * to the CLJ, but rasters generated from simple color spaces will have a
  51. * different appearance. To make the latter rasters match in appearance, the
  52. * faster printing mode must be used (in which the case the other objects
  53. * will not have the same appearance).
  54. */
  55. #define USE_FAST_MODE
  56. /* X_DPI and Y_DPI must be the same */
  57. #define X_DPI 300
  58. #define Y_DPI 300
  59. /*
  60. * Array of paper sizes, and the corresponding offsets.
  61. */
  62. typedef struct clj_paper_size_s {
  63. uint tag; /* paper type tag */
  64. int orient; /* logical page orientation to use */
  65. float width, height; /* in pts; +- 5 pts */
  66. gs_point offsets; /* offsets in the given orientation */
  67. } clj_paper_size;
  68. /*
  69. * The Color LaserJet prints page sizes up to 11.8" wide (A4 size) in
  70. * long-edge-feed (landscape) orientation. Only executive, letter, and
  71. * A4 size are supported for color, so we don't bother to list the others.
  72. */
  73. private const clj_paper_size clj_paper_sizes[] = {
  74. /* U.S. letter size comes first so it will be the default. */
  75. { 2, 1, 11.00 * 72.0, 8.50 * 72.0, { .200 * 72.0, 0.0 } },
  76. { 1, 1, 10.50 * 72.0, 7.25 * 72.0, { .200 * 72.0, 0.0 } },
  77. { 26, 1, 11.69 * 72.0, 8.27 * 72.0, { .197 * 72.0, 0.0 } }
  78. };
  79. /*
  80. * The supported set of resolutions.
  81. *
  82. * The Color LaserJet 5/5M is actually a pseudo-contone device, with hardware
  83. * capable of providing about 16 levels of intensity. The current code does
  84. * not take advantage of this feature, because it is not readily controllable
  85. * via PCL. Rather, the device is modeled as a bi-level device in each of
  86. * three color planes. The maximum supported resolution for such an arrangement
  87. * is 300 dpi.
  88. *
  89. * The CLJ does support raster scaling, but to invoke that scaling, even for
  90. * integral factors, involves a large performance penalty. Hence, only those
  91. * resolutions that can be supported without invoking raster scaling are
  92. * included here. These resolutions are always the same in the fast and slow
  93. * scan directions, so only a single value is listed here.
  94. *
  95. * All valuse are in dots per inch.
  96. */
  97. private const float supported_resolutions[] = { 75.0, 100.0, 150.0, 300.0 };
  98. /* indicate the maximum supported resolution and scan-line length (pts) */
  99. #define CLJ_MAX_RES 300.0
  100. #define CLJ_MAX_SCANLINE (12.0 * 72.0)
  101. /*
  102. * Determine a requested resolution pair is supported.
  103. */
  104. private bool
  105. is_supported_resolution(
  106. const float HWResolution[2]
  107. )
  108. {
  109. int i;
  110. for (i = 0; i < countof(supported_resolutions); i++) {
  111. if (HWResolution[0] == supported_resolutions[i])
  112. return HWResolution[0] == HWResolution[1];
  113. }
  114. return false;
  115. }
  116. /* ---------------- Standard driver ---------------- */
  117. /*
  118. * Find the paper size information corresponding to a given pair of dimensions.
  119. * If rotatep != 0, *rotatep is set to true if the page must be rotated 90
  120. * degrees to fit.
  121. *
  122. * A return value of 0 indicates the paper size is not supported.
  123. *
  124. * Note that for the standard driver, rotation is not allowed.
  125. */
  126. private const clj_paper_size *
  127. get_paper_size(
  128. const float MediaSize[2],
  129. bool * rotatep
  130. )
  131. {
  132. static const float tolerance = 5.0;
  133. float width = MediaSize[0];
  134. float height = MediaSize[1];
  135. const clj_paper_size * psize = 0;
  136. int i;
  137. for (i = 0, psize = clj_paper_sizes; i < countof(clj_paper_sizes); i++, psize++) {
  138. if ( (fabs(width - psize->width) <= tolerance) &&
  139. (fabs(height - psize->height) <= tolerance) ) {
  140. if (rotatep != 0)
  141. *rotatep = false;
  142. return psize;
  143. } else if ( (fabs(width - psize->height) <= tolerance) &&
  144. (fabs(height - psize->width) <= tolerance) ) {
  145. if (rotatep != 0)
  146. *rotatep = true;
  147. return psize;
  148. }
  149. }
  150. return 0;
  151. }
  152. /*
  153. * Get the (PostScript style) default matrix for the current page size.
  154. *
  155. * For all of the supported sizes, the page will be printed with long-edge
  156. * feed (the CLJ does support some additional sizes, but only for monochrome).
  157. * As will all HP laser printers, the printable region marin is 12 pts. from
  158. * the edge of the physical page.
  159. */
  160. private void
  161. clj_get_initial_matrix( gx_device *pdev, gs_matrix *pmat)
  162. {
  163. floatp fs_res = pdev->HWResolution[0] / 72.0;
  164. floatp ss_res = pdev->HWResolution[1] / 72.0;
  165. const clj_paper_size *psize;
  166. psize = get_paper_size(pdev->MediaSize, NULL);
  167. /* if the paper size is not recognized, not much can be done */
  168. /* This shouldn't be possible since clj_put_params rejects */
  169. /* unknown media sizes. */
  170. if (psize == 0) {
  171. pmat->xx = fs_res;
  172. pmat->xy = 0.0;
  173. pmat->yx = 0.0;
  174. pmat->yy = -ss_res;
  175. pmat->tx = 0.0;
  176. pmat->ty = pdev->MediaSize[1] * ss_res;
  177. return;
  178. }
  179. if (pclj->rotated) {
  180. pmat->xx = 0.0;
  181. pmat->xy = ss_res;
  182. pmat->yx = fs_res;
  183. pmat->yy = 0.0;
  184. pmat->tx = -psize->offsets.x * fs_res;
  185. pmat->ty = -psize->offsets.y * ss_res;
  186. } else {
  187. pmat->xx = fs_res;
  188. pmat->xy = 0.0;
  189. pmat->yx = 0.0;
  190. pmat->yy = -ss_res;
  191. pmat->tx = -psize->offsets.x * fs_res;
  192. pmat->ty = pdev->height + psize->offsets.y * ss_res;
  193. }
  194. }
  195. /*
  196. * Get parameters, including InputAttributes for all supported page sizes.
  197. * We associate each page size with a different "media source", since that
  198. * is currently the only way to register multiple page sizes.
  199. */
  200. private int
  201. clj_get_params(gx_device *pdev, gs_param_list *plist)
  202. {
  203. gs_param_dict mdict;
  204. int code = gdev_prn_get_params(pdev, plist);
  205. int ecode = code;
  206. int i;
  207. code = gdev_begin_input_media(plist, &mdict, countof(clj_paper_sizes));
  208. if (code < 0)
  209. ecode = code;
  210. else {
  211. for (i = 0; i < countof(clj_paper_sizes); ++i) {
  212. code = gdev_write_input_page_size(i, &mdict,
  213. clj_paper_sizes[i].width,
  214. clj_paper_sizes[i].height);
  215. if (code < 0)
  216. ecode = code;
  217. }
  218. code = gdev_end_input_media(plist, &mdict);
  219. if (code < 0)
  220. ecode = code;
  221. }
  222. return ecode;
  223. }
  224. /*
  225. * Get the media size being set by put_params, if any. Return 0 if no media
  226. * size is being set, 1 (and set mediasize[]) if the size is being set, <0
  227. * on error.
  228. */
  229. private int
  230. clj_media_size(float mediasize[2], gs_param_list *plist)
  231. {
  232. gs_param_float_array fres;
  233. gs_param_float_array fsize;
  234. gs_param_int_array hwsize;
  235. int have_pagesize = 0;
  236. if ( (param_read_float_array(plist, "HWResolution", &fres) == 0) &&
  237. !is_supported_resolution(fres.data) )
  238. return_error(gs_error_rangecheck);
  239. if ( (param_read_float_array(plist, "PageSize", &fsize) == 0) ||
  240. (param_read_float_array(plist, ".MediaSize", &fsize) == 0) ) {
  241. mediasize[0] = fsize.data[0];
  242. mediasize[1] = fsize.data[1];
  243. have_pagesize = 1;
  244. }
  245. if (param_read_int_array(plist, "HWSize", &hwsize) == 0) {
  246. mediasize[0] = ((float)hwsize.data[0]) / fres.data[0];
  247. mediasize[1] = ((float)hwsize.data[1]) / fres.data[1];
  248. have_pagesize = 1;
  249. }
  250. return have_pagesize;
  251. }
  252. /*
  253. * Special put_params routine, to make certain the desired MediaSize and
  254. * HWResolution are supported.
  255. */
  256. private int
  257. clj_put_params(
  258. gx_device * pdev,
  259. gs_param_list * plist
  260. )
  261. {
  262. float mediasize[2];
  263. bool rotate = false;
  264. int have_pagesize = clj_media_size(mediasize, plist);
  265. if (have_pagesize < 0)
  266. return have_pagesize;
  267. if (have_pagesize) {
  268. if (get_paper_size(mediasize, &rotate) == 0 || rotate)
  269. return_error(gs_error_rangecheck);
  270. }
  271. return gdev_prn_put_params(pdev, plist);
  272. }
  273. /*
  274. * Pack and then compress a scanline of data. Return the size of the compressed
  275. * data produced.
  276. *
  277. * Input is arranged with one byte per pixel, but only the three low-order bits
  278. * are used. These bits are in order ymc, with yellow being the highest order
  279. * bit.
  280. *
  281. * Output is arranged in three planes, with one bit per pixel per plane. The
  282. * Color LaserJet 5/5M does support more congenial pixel encodings, but use
  283. * of anything other than the fixed palettes seems to result in very poor
  284. * performance.
  285. *
  286. * Only compresion mode 2 is used. Compression mode 1 (pure run length) has
  287. * an advantage over compression mode 2 only in cases in which very long runs
  288. * occur (> 128 bytes). Since both methods provide good compression in that
  289. * case, it is not worth worrying about, and compression mode 2 provides much
  290. * better worst-case behavior. Compression mode 3 requires considerably more
  291. * effort to generate, so it is useful only when it is known a prior that
  292. * scanlines repeat frequently.
  293. */
  294. private void
  295. pack_and_compress_scanline(
  296. const byte * pin,
  297. int in_size,
  298. byte * pout[3],
  299. int out_size[3]
  300. )
  301. {
  302. #define BUFF_SIZE \
  303. ( ((int)(CLJ_MAX_RES * CLJ_MAX_SCANLINE / 72.0) + sizeof(ulong) - 1) \
  304. / sizeof(ulong) )
  305. ulong buff[3 * BUFF_SIZE];
  306. byte * p_c = (byte *)buff;
  307. byte * p_m = (byte *)(buff + BUFF_SIZE);
  308. byte * p_y = (byte *)(buff + 2 * BUFF_SIZE);
  309. ulong * ptrs[3];
  310. byte c_val = 0, m_val = 0, y_val = 0;
  311. ulong mask = 0x80;
  312. int i;
  313. /* pack the input for 4-bits per index */
  314. for (i = 0; i < in_size; i++) {
  315. uint ival = *pin++;
  316. if (ival != 0) {
  317. if ((ival & 0x4) != 0)
  318. y_val |= mask;
  319. if ((ival & 0x2) != 0)
  320. m_val |= mask;
  321. if ((ival & 0x1) != 0)
  322. c_val |= mask;
  323. }
  324. if ((mask >>= 1) == 0) {
  325. /* NB - write out in byte units */
  326. *p_c++ = c_val;
  327. c_val = 0L;
  328. *p_m++ = m_val;
  329. m_val = 0L;
  330. *p_y++ = y_val;
  331. y_val = 0L;
  332. mask = 0x80;
  333. }
  334. }
  335. if (mask != 0x80) {
  336. /* NB - write out in byte units */
  337. *p_c++ = c_val;
  338. *p_m++ = m_val;
  339. *p_y++ = y_val;
  340. }
  341. /* clear to up a longword boundary */
  342. while ((((ulong)p_c) & (sizeof(ulong) - 1)) != 0) {
  343. *p_c++ = 0;
  344. *p_m++ = 0;
  345. *p_y++ = 0;
  346. }
  347. ptrs[0] = (ulong *)p_c;
  348. ptrs[1] = (ulong *)p_m;
  349. ptrs[2] = (ulong *)p_y;
  350. for (i = 0; i < 3; i++) {
  351. ulong * p_start = buff + i * BUFF_SIZE;
  352. ulong * p_end = ptrs[i];
  353. /* eleminate trailing 0's */
  354. while ((p_end > p_start) && (p_end[-1] == 0))
  355. p_end--;
  356. if (p_start == p_end)
  357. out_size[i] = 0;
  358. else
  359. out_size[i] = gdev_pcl_mode2compress(p_start, p_end, pout[i]);
  360. }
  361. #undef BUFF_SIZE
  362. }
  363. /*
  364. * Send the page to the printer. Compress each scan line.
  365. */
  366. private int
  367. clj_print_page(
  368. gx_device_printer * pdev,
  369. FILE * prn_stream
  370. )
  371. {
  372. gs_memory_t *mem = pdev->memory;
  373. bool rotate;
  374. const clj_paper_size * psize = get_paper_size(pdev->MediaSize, &rotate);
  375. int lsize = pdev->width;
  376. int clsize = (lsize + (lsize + 255) / 128) / 8;
  377. byte * data = 0;
  378. byte * cdata[3];
  379. int blank_lines = 0;
  380. int i;
  381. floatp fs_res = pdev->HWResolution[0] / 72.0;
  382. floatp ss_res = pdev->HWResolution[1] / 72.0;
  383. int imageable_width, imageable_height;
  384. /* no paper size at this point is a serious error */
  385. if (psize == 0)
  386. return_error(gs_error_unregistered);
  387. /* allocate memory for the raw and compressed data */
  388. if ((data = gs_alloc_bytes(mem, lsize, "clj_print_page(data)")) == 0)
  389. return_error(gs_error_VMerror);
  390. if ((cdata[0] = gs_alloc_bytes(mem, 3 * clsize, "clj_print_page(cdata)")) == 0) {
  391. gs_free_object(mem, data, "clj_print_page(data)");
  392. return_error(gs_error_VMerror);
  393. }
  394. cdata[1] = cdata[0] + clsize;
  395. cdata[2] = cdata[1] + clsize;
  396. /* Imageable area is without the margins. Note that the actual rotation
  397. * of page size into pdev->width & height has been done. We just use
  398. * rotate to access the correct offsets. */
  399. if (pclj->rotated) {
  400. imageable_width = pdev->width - (2 * psize->offsets.x) * fs_res;
  401. imageable_height = pdev->height - (2 * psize->offsets.y) * ss_res;
  402. }
  403. else {
  404. imageable_width = pdev->width - (2 * psize->offsets.y) * ss_res;
  405. imageable_height = pdev->height - (2 * psize->offsets.x) * fs_res;
  406. }
  407. /* start the page. The pcl origin (0, 150 dots by default, y
  408. increasing down the long edge side of the page) needs to be
  409. offset such that it coincides with the offsets of the imageable
  410. area. This calculation should be independant of rotation but
  411. only the rotated case has been tested with a real device. */
  412. fprintf( prn_stream,
  413. "\033E\033&u300D\033&l%da1x%dO\033*p0x0y+50x-100Y\033*t%dR"
  414. #ifdef USE_FAST_MODE
  415. "\033*r-3U"
  416. #else
  417. "\033*v6W\001\002\003\001\001\001"
  418. #endif
  419. "\033*r0f%ds%dt1A\033*b2M",
  420. psize->tag,
  421. pclj->rotated,
  422. (int)(pdev->HWResolution[0]),
  423. imageable_width,
  424. imageable_height
  425. );
  426. /* process each scanline */
  427. for (i = 0; i < imageable_height; i++) {
  428. int clen[3];
  429. gdev_prn_copy_scan_lines(pdev, i, data, lsize);
  430. /* The 'lsize' bytes of data have the blank margin area at the end due */
  431. /* to the 'initial_matrix' offsets that are applied. */
  432. pack_and_compress_scanline(data, imageable_width, cdata, clen);
  433. if ((clen[0] == 0) && (clen[1] == 0) && (clen[2] == 0))
  434. ++blank_lines;
  435. else {
  436. if (blank_lines != 0) {
  437. fprintf(prn_stream, "\033*b%dY", blank_lines);
  438. blank_lines = 0;
  439. }
  440. fprintf(prn_stream, "\033*b%dV", clen[0]);
  441. fwrite(cdata[0], sizeof(byte), clen[0], prn_stream);
  442. fprintf(prn_stream, "\033*b%dV", clen[1]);
  443. fwrite(cdata[1], sizeof(byte), clen[1], prn_stream);
  444. fprintf(prn_stream, "\033*b%dW", clen[2]);
  445. fwrite(cdata[2], sizeof(byte), clen[2], prn_stream);
  446. }
  447. }
  448. /* PCL will take care of blank lines at the end */
  449. fputs("\033*rC\f", prn_stream);
  450. /* free the buffers used */
  451. gs_free_object(mem, cdata[0], "clj_print_page(cdata)");
  452. gs_free_object(mem, data, "clj_print_page(data)");
  453. return 0;
  454. }
  455. /* CLJ device methods */
  456. #define CLJ_PROCS(get_params, put_params)\
  457. gdev_prn_open, /* open_device */\
  458. clj_get_initial_matrix, /* get_initial matrix */\
  459. NULL, /* sync_output */\
  460. gdev_prn_output_page, /* output_page */\
  461. gdev_prn_close, /* close_device */\
  462. gdev_pcl_3bit_map_rgb_color, /* map_rgb_color */\
  463. gdev_pcl_3bit_map_color_rgb, /* map_color_rgb */\
  464. NULL, /* fill_rectangle */\
  465. NULL, /* tile_rectangle */\
  466. NULL, /* copy_mono */\
  467. NULL, /* copy_color */\
  468. NULL, /* obsolete draw_line */\
  469. NULL, /* get_bits */\
  470. get_params, /* get_params */\
  471. put_params, /* put_params */\
  472. NULL, /* map_cmyk_color */\
  473. NULL, /* get_xfont_procs */\
  474. NULL, /* get_xfont_device */\
  475. NULL, /* map_rgb_alpha_color */\
  476. gx_page_device_get_page_device /* get_page_device */
  477. private gx_device_procs cljet5_procs = {
  478. CLJ_PROCS(clj_get_params, clj_put_params)
  479. };
  480. /* CLJ device structure */
  481. #define CLJ_DEVICE_BODY(procs, dname, rotated)\
  482. prn_device_body(\
  483. gx_device_clj,\
  484. procs, /* procedures */\
  485. dname, /* device name */\
  486. 110, /* width - will be overridden subsequently */\
  487. 85, /* height - will be overridden subsequently */\
  488. X_DPI, Y_DPI, /* resolutions - current must be the same */\
  489. 0.167, 0.167, /* margins (left, bottom, right, top */\
  490. 0.167, 0.167,\
  491. 3, /* num_components - 3 colors, 1 bit per pixel */\
  492. 8, /* depth - pack into bytes */\
  493. 1, 1, /* max_gray=max_component=1 */\
  494. 2, 2, /* dithered_grays=dithered_components=2 */ \
  495. clj_print_page /* routine to output page */\
  496. ),\
  497. rotated /* rotated - may be overridden subsequently */
  498. gx_device_clj gs_cljet5_device = {
  499. CLJ_DEVICE_BODY(cljet5_procs, "cljet5", 0 /*false*/)
  500. };
  501. /* ---------------- Driver with page rotation ---------------- */
  502. /*
  503. * For use with certain PCL interpreters, which don't implement
  504. * setpagedevice, we provide a version of this driver that attempts to
  505. * handle page rotation at the driver level. This version breaks an
  506. * invariant that all drivers must obey, namely, that drivers are not
  507. * allowed to change the parameters passed by put_params (they can only
  508. * accept or reject them). Consequently, this driver must not be used in
  509. * any context other than these specific PCL interpreters. We support this
  510. * hack only because these PCL interpreters can't be changed to handle page
  511. * rotation properly.
  512. */
  513. /*
  514. * Special get_params routine, to fake MediaSize, width, and height if
  515. * we were in a 'rotated' state.
  516. */
  517. private int
  518. clj_pr_get_params( gx_device *pdev, gs_param_list *plist )
  519. {
  520. int code;
  521. /* First un-rotate the MediaSize, etc. if we were in a rotated mode */
  522. if (pclj->rotated) {
  523. float ftmp;
  524. int itmp;
  525. ftmp = pdev->MediaSize[0];
  526. pdev->MediaSize[0] = pdev->MediaSize[1];
  527. pdev->MediaSize[1] = ftmp;
  528. itmp = pdev->width;
  529. pdev->width = pdev->height;
  530. pdev->height = itmp;
  531. }
  532. /* process the parameter list */
  533. code = gdev_prn_get_params(pdev, plist);
  534. /* Now re-rotate the page size if needed */
  535. if (pclj->rotated) {
  536. float ftmp;
  537. int itmp;
  538. ftmp = pdev->MediaSize[0];
  539. pdev->MediaSize[0] = pdev->MediaSize[1];
  540. pdev->MediaSize[1] = ftmp;
  541. itmp = pdev->width;
  542. pdev->width = pdev->height;
  543. pdev->height = itmp;
  544. }
  545. return code;
  546. }
  547. /*
  548. * Special put_params routine, to intercept changes in the MediaSize, and to
  549. * make certain the desired MediaSize and HWResolution are supported.
  550. *
  551. * This function will rotate MediaSize if it is needed by the device in
  552. * order to print this size page.
  553. */
  554. private int
  555. clj_pr_put_params(
  556. gx_device * pdev,
  557. gs_param_list * plist
  558. )
  559. {
  560. float mediasize[2];
  561. int code = 0;
  562. bool rotate = false;
  563. int have_pagesize = clj_media_size(mediasize, plist);
  564. if (have_pagesize < 0)
  565. return have_pagesize;
  566. if (have_pagesize) {
  567. if (get_paper_size(mediasize, &rotate) == 0)
  568. return_error(gs_error_rangecheck);
  569. if (rotate) {
  570. /* We need to rotate the requested page size, so synthesize a new */
  571. /* parameter list in front of the requestor's list to force the */
  572. /* rotated page size. */
  573. gs_param_float_array pf_array;
  574. gs_c_param_list alist;
  575. float ftmp = mediasize[0];
  576. mediasize[0] = mediasize[1];
  577. mediasize[1] = ftmp;
  578. pf_array.data = mediasize;
  579. pf_array.size = 2;
  580. pf_array.persistent = false;
  581. gs_c_param_list_write(&alist, pdev->memory);
  582. code = param_write_float_array((gs_param_list *)&alist, ".MediaSize", &pf_array);
  583. gs_c_param_list_read(&alist);
  584. /* stick this synthesized parameter on the front of the existing list */
  585. gs_c_param_list_set_target(&alist, plist);
  586. if ((code = gdev_prn_put_params(pdev, (gs_param_list *)&alist)) >= 0)
  587. pclj->rotated = true;
  588. gs_c_param_list_release(&alist);
  589. } else {
  590. if ((code = gdev_prn_put_params(pdev, plist)) >= 0)
  591. pclj->rotated = false;
  592. }
  593. } else
  594. code = gdev_prn_put_params(pdev, plist);
  595. return code;
  596. }
  597. /* CLJ device methods -- se above for CLJ_PROCS */
  598. private gx_device_procs cljet5pr_procs = {
  599. CLJ_PROCS(clj_pr_get_params, clj_pr_put_params)
  600. };
  601. /* CLJ device structure -- see above for CLJ_DEVICE_BODY */
  602. gx_device_clj gs_cljet5pr_device = {
  603. CLJ_DEVICE_BODY(cljet5pr_procs, "cljet5pr", 1 /*true*/)
  604. };