gdevprn.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /* Copyright (C) 1989, 1995, 1996, 1997, 1998, 1999, 2000 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: gdevprn.h,v 1.6 2000/09/19 19:00:21 lpd Exp $ */
  16. /* Common header file for memory-buffered printers */
  17. #ifndef gdevprn_INCLUDED
  18. # define gdevprn_INCLUDED
  19. #include "memory_.h"
  20. #include "string_.h"
  21. #include "gx.h"
  22. #include "gp.h" /* for gp_file_name_sizeof */
  23. #include "gserrors.h"
  24. #include "gsmatrix.h" /* for gxdevice.h */
  25. #include "gsutil.h" /* for memflip8x8 */
  26. #include "gxdevice.h"
  27. #include "gxdevmem.h"
  28. #include "gxclist.h"
  29. #include "gxrplane.h"
  30. #include "gsparam.h"
  31. /*
  32. * Define the parameters for the printer rendering method.
  33. * If the entire bitmap fits in PRN_MAX_BITMAP, and there is at least
  34. * PRN_MIN_MEMORY_LEFT memory left after allocating it, render in RAM,
  35. * otherwise use a command list with a size of PRN_BUFFER_SPACE.
  36. * (These are parameters that can be changed by a client program.)
  37. */
  38. /* Define parameters for machines with little dinky RAMs.... */
  39. #define PRN_MAX_BITMAP_SMALL 32000
  40. #define PRN_BUFFER_SPACE_SMALL 25000
  41. #define PRN_MIN_MEMORY_LEFT_SMALL 32000
  42. /* Define parameters for machines with great big hulking RAMs.... */
  43. #define PRN_MAX_BITMAP_LARGE 10000000L
  44. #define PRN_BUFFER_SPACE_LARGE 4000000L
  45. #define PRN_MIN_MEMORY_LEFT_LARGE 500000L
  46. /* Define parameters valid on all machines. */
  47. #define PRN_MIN_BUFFER_SPACE 10000 /* give up if less than this */
  48. /* Now define conditional parameters. */
  49. #if arch_small_memory
  50. # define PRN_MAX_BITMAP PRN_MAX_BITMAP_SMALL
  51. # define PRN_BUFFER_SPACE PRN_BUFFER_SPACE_SMALL
  52. # define PRN_MIN_MEMORY_LEFT PRN_MIN_MEMORY_LEFT_SMALL
  53. #else
  54. /****** These should really be conditional on gs_debug_c('.') if
  55. ****** DEBUG is defined, but they're used in static initializers,
  56. ****** so we can't do it.
  57. ******/
  58. # if 0 /****** # ifdef DEBUG ***** */
  59. # define PRN_MAX_BITMAP\
  60. (gs_debug_c('.') ? PRN_MAX_BITMAP_SMALL : PRN_MAX_BITMAP_LARGE)
  61. # define PRN_BUFFER_SPACE\
  62. (gs_debug_c('.') ? PRN_BUFFER_SPACE_SMALL : PRN_BUFFER_SPACE_LARGE)
  63. # define PRN_MIN_MEMORY_LEFT\
  64. (gs_debug_c('.') ? PRN_MIN_MEMORY_LEFT_SMALL : PRN_MIN_MEMORY_LEFT_LARGE)
  65. # else
  66. # define PRN_MAX_BITMAP PRN_MAX_BITMAP_LARGE
  67. # define PRN_BUFFER_SPACE PRN_BUFFER_SPACE_LARGE
  68. # define PRN_MIN_MEMORY_LEFT PRN_MIN_MEMORY_LEFT_LARGE
  69. # endif
  70. #endif
  71. /* Define the abstract type for a printer device. */
  72. #ifndef gx_device_printer_DEFINED
  73. # define gx_device_printer_DEFINED
  74. typedef struct gx_device_printer_s gx_device_printer;
  75. #endif
  76. /* Define the abstract type for some band device procedures' arguments. */
  77. typedef struct gdev_prn_start_render_params_s gdev_prn_start_render_params;
  78. /* Define the abstract type for a page queue for async rendering. */
  79. #ifndef gx_page_queue_DEFINED
  80. # define gx_page_queue_DEFINED
  81. typedef struct gx_page_queue_s gx_page_queue_t;
  82. #endif
  83. /* Define the abstract type for parameters describing buffer space. */
  84. #ifndef gdev_prn_space_params_DEFINED
  85. # define gdev_prn_space_params_DEFINED
  86. typedef struct gdev_prn_space_params_s gdev_prn_space_params;
  87. #endif
  88. /*
  89. * Define the special procedures for band devices.
  90. */
  91. typedef struct gx_printer_device_procs_s {
  92. /*
  93. * Print the page on the output file. Required only for devices
  94. * where output_page is gdev_prn_output_page; ignored for other
  95. * devices.
  96. */
  97. #define prn_dev_proc_print_page(proc)\
  98. int proc(P2(gx_device_printer *, FILE *))
  99. prn_dev_proc_print_page((*print_page));
  100. /* BACKWARD COMPATIBILITY */
  101. #define dev_proc_print_page(proc) prn_dev_proc_print_page(proc)
  102. /* Print the page on the output file, with a given # of copies. */
  103. #define prn_dev_proc_print_page_copies(proc)\
  104. int proc(P3(gx_device_printer *, FILE *, int))
  105. prn_dev_proc_print_page_copies((*print_page_copies));
  106. /* BACKWARD COMPATIBILITY */
  107. #define dev_proc_print_page_copies(proc) prn_dev_proc_print_page_copies(proc)
  108. /*
  109. * Define buffer device management procedures.
  110. * See gxdevcli.h for the definitions.
  111. */
  112. gx_device_buf_procs_t buf_procs;
  113. /*
  114. * Compute effective space params. These results effectively override
  115. * the space_params in the device, but does not replace them; that is to
  116. * say that computed space params are temps used for computation.
  117. * Procedure must fill in only those space_params that it wishes to
  118. * override, using curr width, height, margins, etc.
  119. *
  120. * Caller is gdevprn.open & gdevprn.put_params, calls driver or
  121. * default.
  122. */
  123. #define prn_dev_proc_get_space_params(proc)\
  124. void proc(P2(const gx_device_printer *, gdev_prn_space_params *))
  125. prn_dev_proc_get_space_params((*get_space_params));
  126. /*
  127. * Only for gx_device_printer devices that overlap interpreting and
  128. * rasterizing. Since there are 2 instances of the device (1 for writing
  129. * the cmd list & 1 for rasterizing it), and each device is associated
  130. * with an different thread, this function is called to start the
  131. * rasterizer's thread. Once started, the rasterizer thread must call
  132. * down to gdev_prn_asnyc_render_thread, which will only return after
  133. * device closes.
  134. *
  135. * Caller is gdevprna.open, calls driver implementation or default.
  136. */
  137. #define prn_dev_proc_start_render_thread(proc)\
  138. int proc(P1(gdev_prn_start_render_params *))
  139. prn_dev_proc_start_render_thread((*start_render_thread));
  140. /*
  141. * Only for gx_device_printer devices that overlap interpreting and
  142. * rasterizing. Since there are 2 instances of the device (1 for writing
  143. * the cmd list & 1 for rasterizing it), these fns are called to
  144. * open/close the rasterizer's instance, once the writer's instance has
  145. * been created & init'd. These procs must cascade down to
  146. * gdev_prn_async_render_open/close.
  147. *
  148. * Caller is gdevprna, calls driver implementation or default.
  149. */
  150. #define prn_dev_proc_open_render_device(proc)\
  151. int proc(P1(gx_device_printer *))
  152. prn_dev_proc_open_render_device((*open_render_device));
  153. #define prn_dev_proc_close_render_device(proc)\
  154. int proc(P1(gx_device_printer *))
  155. prn_dev_proc_close_render_device((*close_render_device));
  156. /*
  157. * Buffer a page on the output device. A page may or may not have been
  158. * fully rendered, but the rasterizer needs to realize the page to free
  159. * up resources or support copypage. Printing a page may involve zero or
  160. * more buffer_pages. All buffer_page output is overlaid in the buffer
  161. * until a terminating print_page or print_page_copies clears the
  162. * buffer. Note that, after the first buffer_page, the driver must call
  163. * the lower-level gdev_prn_render_lines procedure instead of
  164. * get_bits. The difference is that gdev_prn_render_lines requires the
  165. * caller to supply the same buffered bitmap that was computed as a
  166. * result of a previous buffer_page, so that gdev_prn_render_lines can
  167. * add further marks to the existing buffered image. NB that output must
  168. * be accumulated in buffer even if num_copies == 0.
  169. *
  170. * Caller is expected to be gdevprn, calls driver implementation or
  171. * default. */
  172. #define prn_dev_proc_buffer_page(proc)\
  173. int proc(P3(gx_device_printer *, FILE *, int))
  174. prn_dev_proc_buffer_page((*buffer_page));
  175. } gx_printer_device_procs;
  176. /* ------ Printer device definition ------ */
  177. /* Structure for generic printer devices. */
  178. /* This must be preceded by gx_device_common. */
  179. /* Printer devices are actually a union of a memory device */
  180. /* and a clist device, plus some additional state. */
  181. #define prn_fname_sizeof gp_file_name_sizeof
  182. typedef enum {
  183. BandingAuto = 0,
  184. BandingAlways,
  185. BandingNever
  186. } gdev_prn_banding_type;
  187. struct gdev_prn_space_params_s {
  188. long MaxBitmap; /* max size of non-buffered bitmap */
  189. long BufferSpace; /* space to use for buffer */
  190. gx_band_params_t band; /* see gxclist.h */
  191. bool params_are_read_only; /* true if put_params may not modify this struct */
  192. gdev_prn_banding_type banding_type; /* used to force banding or bitmap */
  193. };
  194. #define gx_prn_device_common\
  195. byte skip[max(sizeof(gx_device_memory), sizeof(gx_device_clist)) -\
  196. sizeof(gx_device) + sizeof(double) /* padding */];\
  197. gx_printer_device_procs printer_procs;\
  198. /* ------ Device parameters that must be set ------ */\
  199. /* ------ before calling the device open routine. ------ */\
  200. gdev_prn_space_params space_params;\
  201. char fname[prn_fname_sizeof]; /* OutputFile */\
  202. /* ------ Other device parameters ------ */\
  203. bool OpenOutputFile;\
  204. bool ReopenPerPage;\
  205. bool Duplex;\
  206. int Duplex_set; /* -1 = not supported */\
  207. /* ------ End of parameters ------ */\
  208. bool file_is_new; /* true iff file just opened */\
  209. FILE *file; /* output file */\
  210. long buffer_space; /* amount of space for clist buffer, */\
  211. /* 0 means not using clist */\
  212. byte *buf; /* buffer for rendering */\
  213. /* ---- Begin async rendering support --- */\
  214. gs_memory_t *buffer_memory; /* allocator for command list */\
  215. gs_memory_t *bandlist_memory; /* allocator for bandlist files */\
  216. proc_free_up_bandlist_memory((*free_up_bandlist_memory)); /* if nz, proc to free some bandlist memory */\
  217. gx_page_queue_t *page_queue; /* if <> 0,page queue for gdevprna NOT GC'd */\
  218. bool is_async_renderer; /* device is only the rendering part of async device */\
  219. gx_device_printer *async_renderer; /* in async writer, pointer to async renderer */\
  220. uint clist_disable_mask; /* mask of clist options to disable */\
  221. /* ---- End async rendering support --- */\
  222. gx_device_procs orig_procs /* original (std_)procs */
  223. /* The device descriptor */
  224. struct gx_device_printer_s {
  225. gx_device_common;
  226. gx_prn_device_common;
  227. };
  228. extern_st(st_device_printer);
  229. #define public_st_device_printer() /* in gdevprn.c */\
  230. gs_public_st_complex_only(st_device_printer, gx_device_printer,\
  231. "gx_device_printer", 0, device_printer_enum_ptrs,\
  232. device_printer_reloc_ptrs, gx_device_finalize)
  233. /* Define a typedef for the sake of ansi2knr. */
  234. typedef dev_proc_print_page((*dev_proc_print_page_t));
  235. /* Standard device procedures for printers */
  236. dev_proc_open_device(gdev_prn_open);
  237. dev_proc_output_page(gdev_prn_output_page);
  238. dev_proc_close_device(gdev_prn_close);
  239. #define gdev_prn_map_rgb_color gx_default_b_w_map_rgb_color
  240. #define gdev_prn_map_color_rgb gx_default_b_w_map_color_rgb
  241. dev_proc_get_params(gdev_prn_get_params);
  242. dev_proc_put_params(gdev_prn_put_params);
  243. /* Default printer-specific procedures */
  244. /* VMS limits procedure names to 31 characters. */
  245. prn_dev_proc_get_space_params(gx_default_get_space_params);
  246. /* BACKWARD COMPATIBILITY */
  247. #define gdev_prn_default_get_space_params gx_default_get_space_params
  248. prn_dev_proc_start_render_thread(gx_default_start_render_thread); /* for async rendering only, see gdevprna.c */
  249. prn_dev_proc_open_render_device(gx_default_open_render_device);
  250. prn_dev_proc_close_render_device(gx_default_close_render_device);
  251. prn_dev_proc_buffer_page(gx_default_buffer_page); /* returns an error */
  252. /* Macro for generating procedure table */
  253. #define prn_procs(p_open, p_output_page, p_close)\
  254. prn_color_procs(p_open, p_output_page, p_close, gdev_prn_map_rgb_color, gdev_prn_map_color_rgb)
  255. #define prn_params_procs(p_open, p_output_page, p_close, p_get_params, p_put_params)\
  256. prn_color_params_procs(p_open, p_output_page, p_close, gdev_prn_map_rgb_color, gdev_prn_map_color_rgb, p_get_params, p_put_params)
  257. #define prn_color_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb)\
  258. prn_color_params_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb, gdev_prn_get_params, gdev_prn_put_params)
  259. /* See gdev_prn_open for explanation of the NULLs below. */
  260. #define prn_color_params_procs(p_open, p_output_page, p_close, p_map_rgb_color, p_map_color_rgb, p_get_params, p_put_params) {\
  261. p_open,\
  262. NULL, /* get_initial_matrix */\
  263. NULL, /* sync_output */\
  264. p_output_page,\
  265. p_close,\
  266. p_map_rgb_color,\
  267. p_map_color_rgb,\
  268. NULL, /* fill_rectangle */\
  269. NULL, /* tile_rectangle */\
  270. NULL, /* copy_mono */\
  271. NULL, /* copy_color */\
  272. NULL, /* draw_line */\
  273. NULL, /* get_bits */\
  274. p_get_params,\
  275. p_put_params,\
  276. NULL, /* map_cmyk_color */\
  277. NULL, /* get_xfont_procs */\
  278. NULL, /* get_xfont_device */\
  279. NULL, /* map_rgb_alpha_color */\
  280. gx_page_device_get_page_device,\
  281. NULL, /* get_alpha_bits */\
  282. NULL, /* copy_alpha */\
  283. NULL, /* get_band */\
  284. NULL, /* copy_rop */\
  285. NULL, /* fill_path */\
  286. NULL, /* stroke_path */\
  287. NULL, /* fill_mask */\
  288. NULL, /* fill_trapezoid */\
  289. NULL, /* fill_parallelogram */\
  290. NULL, /* fill_triangle */\
  291. NULL, /* draw_thin_line */\
  292. NULL, /* begin_image */\
  293. NULL, /* image_data */\
  294. NULL, /* end_image */\
  295. NULL, /* strip_tile_rectangle */\
  296. NULL, /* strip_copy_rop, */\
  297. NULL, /* get_clipping_box */\
  298. NULL, /* begin_typed_image */\
  299. NULL, /* map_color_rgb_alpha */\
  300. NULL, /* create_compositor */\
  301. NULL, /* get_hardware_params */\
  302. NULL, /* text_begin */\
  303. NULL /* finish_copydevice */\
  304. }
  305. /* The standard printer device procedures */
  306. /* (using gdev_prn_open/output_page/close). */
  307. extern const gx_device_procs prn_std_procs;
  308. /*
  309. * Define macros for generating the device structure,
  310. * analogous to the std_device_body macros in gxdevice.h
  311. * Note that the macros are broken up so as to be usable for devices that
  312. * add further initialized state to the printer device.
  313. *
  314. * The 'margin' values provided here specify the unimageable region
  315. * around the edges of the page (in inches), and the left and top margins
  316. * also specify the displacement of the device (0,0) point from the
  317. * upper left corner. We should provide macros that allow specifying
  318. * all 6 values independently, but we don't yet.
  319. *
  320. * Note that print_page and print_page_copies must not both be defaulted.
  321. */
  322. #define prn_device_body_rest2_(print_page, print_page_copies)\
  323. { 0 }, /* std_procs */\
  324. { 0 }, /* skip */\
  325. { print_page,\
  326. print_page_copies,\
  327. { gx_default_create_buf_device,\
  328. gx_default_size_buf_device,\
  329. gx_default_setup_buf_device,\
  330. gx_default_destroy_buf_device\
  331. },\
  332. gdev_prn_default_get_space_params,\
  333. gx_default_start_render_thread,\
  334. gx_default_open_render_device,\
  335. gx_default_close_render_device,\
  336. gx_default_buffer_page\
  337. },\
  338. { PRN_MAX_BITMAP, PRN_BUFFER_SPACE,\
  339. { BAND_PARAMS_INITIAL_VALUES },\
  340. 0/*false*/, /* params_are_read_only */\
  341. BandingAuto /* banding_type */\
  342. },\
  343. { 0 }, /* fname */\
  344. 0/*false*/, /* OpenOutputFile */\
  345. 0/*false*/, /* ReopenPerPage */\
  346. 0/*false*/, -1, /* Duplex[_set] */\
  347. 0/*false*/, 0, 0, 0, /* file_is_new ... buf */\
  348. 0, 0, 0, 0, 0/*false*/, 0, 0, /* buffer_memory ... clist_dis'_mask */\
  349. { 0 } /* ... orig_procs */
  350. #define prn_device_body_rest_(print_page)\
  351. prn_device_body_rest2_(print_page, gx_default_print_page_copies)
  352. #define prn_device_body_copies_rest_(print_page_copies)\
  353. prn_device_body_rest2_(gx_print_page_single_copy, print_page_copies)
  354. /* The Sun cc compiler won't allow \ within a macro argument list. */
  355. /* This accounts for the short parameter names here and below. */
  356. #define prn_device_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)\
  357. std_device_full_body_type(dtype, &procs, dname, &st_device_printer,\
  358. (int)((long)(w10) * (xdpi) / 10),\
  359. (int)((long)(h10) * (ydpi) / 10),\
  360. xdpi, ydpi,\
  361. ncomp, depth, mg, mc, dg, dc,\
  362. -(lo) * (xdpi), -(to) * (ydpi),\
  363. (lm) * 72.0, (bm) * 72.0,\
  364. (rm) * 72.0, (tm) * 72.0\
  365. ),\
  366. prn_device_body_rest_(print_page)
  367. #define prn_device_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)\
  368. prn_device_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  369. lm, tm, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page)
  370. #define prn_device_std_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  371. std_device_std_color_full_body_type(dtype, &procs, dname, &st_device_printer,\
  372. (int)((long)(w10) * (xdpi) / 10),\
  373. (int)((long)(h10) * (ydpi) / 10),\
  374. xdpi, ydpi, color_bits,\
  375. -(lo) * (xdpi), -(to) * (ydpi),\
  376. (lm) * 72.0, (bm) * 72.0,\
  377. (rm) * 72.0, (tm) * 72.0\
  378. ),\
  379. prn_device_body_rest_(print_page)
  380. #define prn_device_std_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page)\
  381. prn_device_std_margins_body(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  382. lm, tm, lm, bm, rm, tm, color_bits, print_page)
  383. #define prn_device_std_margins_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page_copies)\
  384. std_device_std_color_full_body_type(dtype, &procs, dname, &st_device_printer,\
  385. (int)((long)(w10) * (xdpi) / 10),\
  386. (int)((long)(h10) * (ydpi) / 10),\
  387. xdpi, ydpi, color_bits,\
  388. -(lo) * (xdpi), -(to) * (ydpi),\
  389. (lm) * 72.0, (bm) * 72.0,\
  390. (rm) * 72.0, (tm) * 72.0\
  391. ),\
  392. prn_device_body_copies_rest_(print_page_copies)
  393. #define prn_device_std_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page_copies)\
  394. prn_device_std_margins_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi,\
  395. lm, tm, lm, bm, rm, tm, color_bits, print_page_copies)
  396. /* Note that the following macros add { } around the data. */
  397. #define prn_device_margins(procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  398. { prn_device_std_margins_body(gx_device_printer, procs, dname,\
  399. w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page)\
  400. }
  401. #define prn_device(procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page)\
  402. prn_device_margins(procs, dname, w10, h10, xdpi, ydpi,\
  403. lm, tm, lm, bm, rm, tm, color_bits, print_page)
  404. #define prn_device_margins_copies(procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page_copies)\
  405. { prn_device_std_margins_body_copies(gx_device_printer, procs, dname,\
  406. w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, color_bits, print_page_copies)\
  407. }
  408. #define prn_device_copies(procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, color_bits, print_page_copies)\
  409. prn_device_margins_copies(procs, dname, w10, h10, xdpi, ydpi,\
  410. lm, tm, lm, bm, rm, tm, color_bits, print_page_copies)
  411. /* ------ Utilities ------ */
  412. /* These are defined in gdevprn.c. */
  413. /*
  414. * Open the printer's output file if necessary.
  415. */
  416. /* VMS limits procedure names to 31 characters. */
  417. int gdev_prn_open_printer_seekable(P3(gx_device *dev, bool binary_mode,
  418. bool seekable));
  419. /* BACKWARD COMPATIBILITY */
  420. #define gdev_prn_open_printer_positionable gdev_prn_open_printer_seekable
  421. /* open_printer defaults positionable = false */
  422. int gdev_prn_open_printer(P2(gx_device * dev, bool binary_mode));
  423. /*
  424. * Test whether the printer's output file was just opened, i.e., whether
  425. * this is the first page being written to this file. This is only valid
  426. * at the entry to a driver's print_page procedure.
  427. */
  428. bool gdev_prn_file_is_new(P1(const gx_device_printer *pdev));
  429. /*
  430. * Determine the number of bytes required for one scan line of output to
  431. * a printer device, without any padding.
  432. */
  433. #define gdev_prn_raster(pdev) gx_device_raster((gx_device *)(pdev), 0)
  434. /*
  435. * Determine (conservatively) what colors are used in a given range of scan
  436. * lines, and return the actual range of scan lines to which the result
  437. * applies. (Currently, the result will always actually apply to one or
  438. * more full bands.) In the non-banded case, this information is currently
  439. * not available, so we return all-1s (i.e., any color may appear) as the
  440. * 'or', and the entire page as the range; we may improve this someday.
  441. *
  442. * The return value is like get_band: the first Y value of the actual range
  443. * is stored in *range_start, and the height of the range is returned.
  444. * If the parameters are invalid, the procedure returns -1.
  445. */
  446. int gdev_prn_colors_used(P5(gx_device *dev, int y, int height,
  447. gx_colors_used_t *colors_used,
  448. int *range_start));
  449. /*
  450. * Determine the colors used in a saved page. We still need the device
  451. * in order to know the total page height.
  452. */
  453. int gx_page_info_colors_used(P6(const gx_device *dev,
  454. const gx_band_page_info_t *page_info,
  455. int y, int height,
  456. gx_colors_used_t *colors_used,
  457. int *range_start));
  458. /*
  459. * Render a subrectangle of the page into a target device provided by the
  460. * caller, optionally clearing the device before rendering. The rectangle
  461. * need not coincide exactly with band boundaries, but it will be most
  462. * efficient if they do, since it is necessary to render every band that
  463. * even partly falls within the rectangle. This is the lowest-level
  464. * rendering procedure: the other procedures for reading rasterized lines,
  465. * defined below, ultimately call this one.
  466. *
  467. * render_plane is used only for internal cache bookkeeping: it doesn't
  468. * affect what is passed to the buffer device. It is the client's
  469. * responsibility to set up a plane extraction device, if required, to
  470. * select an individual plane for rendering.
  471. *
  472. * Note that it may be necessary to render more than one plane even if the
  473. * caller only requests a single plane. Currently this only occurs for
  474. * non-trivial RasterOps on CMYK devices. If this is the case, it is the
  475. * client's responsibility to provide a target device that accumulates full
  476. * pixels rather than a single plane: if the plane extraction device is
  477. * asked to execute an operation that requires full pixels, it will return
  478. * an error.
  479. */
  480. int gdev_prn_render_rectangle(P5(gx_device_printer *pdev,
  481. const gs_int_rect *prect,
  482. gx_device *target,
  483. const gx_render_plane_t *render_plane,
  484. bool clear));
  485. /*
  486. * Read one or more rasterized scan lines for printing.
  487. * The procedure either copies the scan lines into the buffer and
  488. * sets *actual_buffer = buffer and *actual_bytes_per_line = bytes_per_line,
  489. * or sets *actual_buffer and *actual_bytes_per_line to reference
  490. * already-rasterized scan lines.
  491. *
  492. * For non-banded devices, copying is never necessary. For banded devices,
  493. * if the client's buffer is at least as large as the single preallocated
  494. * one (if any), the band will be rasterized directly into the client's
  495. * buffer, again avoiding copying. Alternatively, if there is a
  496. * preallocated buffer and the call asks for no more data than will fit
  497. * in that buffer, buffer may be NULL: any necessary rasterizing will
  498. * occur in the preallocated buffer, and a pointer into the buffer will be
  499. * returned.
  500. */
  501. int gdev_prn_get_lines(P8(gx_device_printer *pdev, int y, int height,
  502. byte *buffer, uint bytes_per_line,
  503. byte **actual_buffer, uint *actual_bytes_per_line,
  504. const gx_render_plane_t *render_plane));
  505. /*
  506. * Read a rasterized scan line for sending to the printer.
  507. * This is essentially a simplified form of gdev_prn_get_lines,
  508. * except that it also calls gdev_prn_clear_trailing_bits.
  509. */
  510. int gdev_prn_get_bits(P4(gx_device_printer *pdev, int y, byte *buffer,
  511. byte **actual_buffer));
  512. /*
  513. * Copy scan lines to send to the printer. This is now DEPRECATED,
  514. * because it copies the data even if the data are already available in
  515. * the right form in the rasterizer buffer. Use gdev_prn_get_bits
  516. * instead. For documentation, see the implementation in gdevprn.c.
  517. */
  518. int gdev_prn_copy_scan_lines(P4(gx_device_printer *, int, byte *, uint));
  519. /*
  520. * Clear any trailing bits in the last byte of one or more scan lines
  521. * returned from the calls for reading out rasterized data. Note that
  522. * the device is only used to get the width and depth, and need not be
  523. * a printer device.
  524. */
  525. void gdev_prn_clear_trailing_bits(P4(byte *data, uint raster, int height,
  526. const gx_device *dev));
  527. /*
  528. * Close the printer's output file.
  529. */
  530. int gdev_prn_close_printer(P1(gx_device *));
  531. /* Print a single copy of a page by calling print_page_copies. */
  532. prn_dev_proc_print_page(gx_print_page_single_copy);
  533. /*
  534. * Define a default print_page_copies procedure just calls print_page
  535. * the given number of times.
  536. */
  537. prn_dev_proc_print_page_copies(gx_default_print_page_copies);
  538. /*
  539. * Determine the number of scan lines that should actually be passed
  540. * to the device.
  541. */
  542. int gdev_prn_print_scan_lines(P1(gx_device *));
  543. /* Allocate / reallocate / free printer memory. */
  544. int gdev_prn_allocate_memory(P4(gx_device *pdev,
  545. gdev_prn_space_params *space,
  546. int new_width, int new_height));
  547. int gdev_prn_reallocate_memory(P4(gx_device *pdev,
  548. gdev_prn_space_params *space,
  549. int new_width, int new_height));
  550. int gdev_prn_free_memory(P1(gx_device *pdev));
  551. /*
  552. * Create the buffer device for a printer device. Clients should always
  553. * call this, and never call the device procedure directly. The actual
  554. * create_buf_device procedure is passed as an argument because the banding
  555. * code needs this: normally it is dev_proc(some_dev, create_buf_device).
  556. */
  557. typedef dev_proc_create_buf_device((*create_buf_device_proc_t));
  558. int gdev_create_buf_device(P6(create_buf_device_proc_t cbd_proc,
  559. gx_device **pbdev, gx_device *target,
  560. const gx_render_plane_t *render_plane,
  561. gs_memory_t *mem, bool for_band));
  562. /* BACKWARD COMPATIBILITY */
  563. #define dev_print_scan_lines(dev)\
  564. gdev_prn_print_scan_lines((gx_device *)(dev))
  565. #define gdev_mem_bytes_per_scan_line(dev)\
  566. gdev_prn_raster((gx_device_printer *)(dev))
  567. #define gdev_prn_transpose_8x8(inp,ils,outp,ols)\
  568. memflip8x8(inp,ils,outp,ols)
  569. /* ------ Printer device types ------ */
  570. /**************** THE FOLLOWING CODE IS NOT USED YET. ****************/
  571. #if 0 /**************** VMS linker gets upset *************** */
  572. #endif
  573. int gdev_prn_initialize(P3(gx_device *, const char *, dev_proc_print_page((*))));
  574. void gdev_prn_init_color(P4(gx_device *, int, dev_proc_map_rgb_color((*)), dev_proc_map_color_rgb((*))));
  575. #define prn_device_type(dtname, initproc, pageproc)\
  576. private dev_proc_print_page(pageproc);\
  577. device_type(dtname, st_prn_device, initproc)
  578. /****** FOLLOWING SHOULD CHECK __PROTOTYPES__ ******/
  579. #define prn_device_type_mono(dtname, dname, initproc, pageproc)\
  580. private dev_proc_print_page(pageproc);\
  581. private int \
  582. initproc(gx_device *dev)\
  583. { return gdev_prn_initialize(dev, dname, pageproc);\
  584. }\
  585. device_type(dtname, st_prn_device, initproc)
  586. /****** DITTO ******/
  587. #define prn_device_type_color(dtname, dname, depth, initproc, pageproc, rcproc, crproc)\
  588. private dev_proc_print_page(pageproc);\
  589. private int \
  590. initproc(gx_device *dev)\
  591. { int code = gdev_prn_initialize(dev, dname, pageproc);\
  592. gdev_prn_init_color(dev, depth, rcproc, crproc);\
  593. return code;\
  594. }\
  595. device_type(dtname, st_prn_device, initproc)
  596. #endif /* gdevprn_INCLUDED */