1 /* Copyright (C) 1997, 1998, 1999, 2000 Aladdin Enterprises. All rights reserved. 2 3 This software is provided AS-IS with no warranty, either express or 4 implied. 5 6 This software is distributed under license and may not be copied, 7 modified or distributed except as expressly authorized under the terms 8 of the license contained in the file LICENSE in this distribution. 9 10 For more information about licensing, please refer to 11 http://www.ghostscript.com/licensing/. For information on 12 commercial licensing, go to http://www.artifex.com/licensing/ or 13 contact Artifex Software, Inc., 101 Lucas Valley Road #110, 14 San Rafael, CA 94903, U.S.A., +1(415)492-9861. 15 */ 16 17 /* $Id: gxdevice.h,v 1.21 2005/03/14 18:08:36 dan Exp $ */ 18 /* Definitions for device implementors */ 19 20 #ifndef gxdevice_INCLUDED 21 # define gxdevice_INCLUDED 22 23 #include "stdio_.h" /* for FILE */ 24 #include "gxdevcli.h" 25 #include "gsfname.h" 26 #include "gsparam.h" 27 /* 28 * Many drivers still use gs_malloc and gs_free, so include the interface 29 * for these. (Eventually they should go away.) 30 */ 31 #include "gsmalloc.h" 32 /* 33 * Similarly, quite a few drivers reference stdout and/or stderr. 34 * (Eventually these references must go away.) 35 */ 36 #include "gxstdio.h" 37 38 /* 39 * NOTE: if you write code that creates device instances (either with 40 * gs_copydevice or by allocating them explicitly), allocates device 41 * instances as either local or static variables (actual instances, not 42 * pointers to instances), or sets the target of forwarding devices, please 43 * read the documentation in gxdevcli.h about memory management for devices. 44 * The rules for doing these things changed substantially in release 5.68, 45 * in a non-backward-compatible way, and unfortunately we could not find a 46 * way to make the compiler give an error at places that need changing. 47 */ 48 49 /* ---------------- Auxiliary types and structures ---------------- */ 50 51 /* Define default pages sizes. */ 52 /* U.S. letter paper (8.5" x 11"). */ 53 #define DEFAULT_WIDTH_10THS_US_LETTER 85 54 #define DEFAULT_HEIGHT_10THS_US_LETTER 110 55 /* A4 paper (210mm x 297mm), we use 595pt x 842pt. */ 56 #define DEFAULT_WIDTH_10THS_A4 82.6389 57 #define DEFAULT_HEIGHT_10THS_A4 116.9444 58 /* Choose a default. A4 may be set in the makefile. */ 59 #ifdef A4 60 # define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_A4 61 # define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_A4 62 #else 63 # define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_US_LETTER 64 # define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_US_LETTER 65 #endif 66 67 /* ---------------- Device structure ---------------- */ 68 69 /* 70 * To insulate statically defined device templates from the 71 * consequences of changes in the device structure, the following macros 72 * must be used for generating initialized device structures. 73 * 74 * The computations of page width and height in pixels should really be 75 * ((int)(page_width_inches*x_dpi)) 76 * but some compilers (the Ultrix 3.X pcc compiler and the HPUX compiler) 77 * can't cast a computed float to an int. That's why we specify 78 * the page width and height in inches/10 instead of inches. 79 * This has been now been changed to use floats. 80 * 81 * Note that the macro is broken up so as to be usable for devices that 82 * add further initialized state to the generic device. 83 * Note also that the macro does not initialize procs, which is 84 * the next element of the structure. 85 */ 86 #define std_device_part1_(devtype, ptr_procs, dev_name, stype, open_init)\ 87 sizeof(devtype), ptr_procs, dev_name,\ 88 0 /*memory*/, stype, 0 /*stype_is_dynamic*/, 0 /*finalize*/,\ 89 { 0 } /*rc*/, 0 /*retained*/, open_init() /*is_open, max_fill_band*/ 90 /* color_info goes here */ 91 /* 92 * The MetroWerks compiler has some bizarre bug that produces a spurious 93 * error message if the width and/or height are defined as 0 below, 94 * unless we use the +/- workaround in the next macro. 95 */ 96 #define std_device_part2_(width, height, x_dpi, y_dpi)\ 97 { gx_no_color_index, gx_no_color_index },\ 98 width, height, 0/*TrayOrientation*/,\ 99 { (float)((((width) * 72.0 + 0.5) - 0.5) / (x_dpi))/*MediaSize[0]*/,\ 100 (float)((((height) * 72.0 + 0.5) - 0.5) / (y_dpi))/*MediaSize[1]*/},\ 101 { 0, 0, 0, 0 }/*ImagingBBox*/, 0/*ImagingBBox_set*/,\ 102 { x_dpi, y_dpi }/*HWResolution*/, { x_dpi, y_dpi }/*MarginsHWResolution*/ 103 104 /* offsets and margins go here */ 105 #define std_device_part3_()\ 106 0/*PageCount*/, 0/*ShowpageCount*/, 1/*NumCopies*/, 0/*NumCopies_set*/,\ 107 0/*IgnoreNumCopies*/, 0/*UseCIEColor*/, 0/*LockSafetyParams*/,\ 108 { gx_default_install, gx_default_begin_page, gx_default_end_page } 109 /* 110 * We need a number of different variants of the std_device_ macro simply 111 * because we can't pass the color_info or offsets/margins 112 * as macro arguments, which in turn is because of the early macro 113 * expansion issue noted in stdpre.h. The basic variants are: 114 * ...body_with_macros_, which uses 0-argument macros to supply 115 * open_init, color_info, and offsets/margins; 116 * ...full_body, which takes 12 values (6 for dci_values, 117 * 6 for offsets/margins); 118 * ...color_full_body, which takes 9 values (3 for dci_color, 119 * 6 for margins/offset). 120 * ...std_color_full_body, which takes 7 values (1 for dci_std_color, 121 * 6 for margins/offset). 122 * 123 */ 124 #define std_device_body_with_macros_(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, open_init, dci_macro, margins_macro)\ 125 std_device_part1_(dtype, pprocs, dname, stype, open_init),\ 126 dci_macro(),\ 127 std_device_part2_(w, h, xdpi, ydpi),\ 128 margins_macro(),\ 129 std_device_part3_() 130 131 #define std_device_std_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi)\ 132 std_device_body_with_macros_(dtype, pprocs, dname, stype,\ 133 w, h, xdpi, ydpi,\ 134 open_init_closed, dci_black_and_white_, no_margins_) 135 136 #define std_device_std_body(dtype, pprocs, dname, w, h, xdpi, ydpi)\ 137 std_device_std_body_type(dtype, pprocs, dname, 0, w, h, xdpi, ydpi) 138 139 #define std_device_std_body_type_open(dtype, pprocs, dname, stype, w, h, xdpi, ydpi)\ 140 std_device_body_with_macros_(dtype, pprocs, dname, stype,\ 141 w, h, xdpi, ydpi,\ 142 open_init_open, dci_black_and_white_, no_margins_) 143 144 #define std_device_std_body_open(dtype, pprocs, dname, w, h, xdpi, ydpi)\ 145 std_device_std_body_type_open(dtype, pprocs, dname, 0, w, h, xdpi, ydpi) 146 147 #define std_device_full_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)\ 148 std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\ 149 dci_values(ncomp, depth, mg, mc, dg, dc),\ 150 std_device_part2_(w, h, xdpi, ydpi),\ 151 offset_margin_values(xoff, yoff, lm, bm, rm, tm),\ 152 std_device_part3_() 153 154 #define std_device_full_body_type_extended(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, mcomp, ncomp, pol, depth, gi, mg, mc, dg, dc, ef, cn, xoff, yoff, lm, bm, rm, tm)\ 155 std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\ 156 dci_extended_alpha_values(mcomp, ncomp, pol, depth, gi, mg, mc, dg, dc, 1, 1, ef, cn), \ 157 std_device_part2_(w, h, xdpi, ydpi),\ 158 offset_margin_values(xoff, yoff, lm, bm, rm, tm),\ 159 std_device_part3_() 160 161 #define std_device_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)\ 162 std_device_full_body_type(dtype, pprocs, dname, 0, w, h, xdpi, ydpi,\ 163 ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm) 164 165 #define std_device_dci_alpha_type_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, ta, ga)\ 166 std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\ 167 dci_alpha_values(ncomp, depth, mg, mc, dg, dc, ta, ga),\ 168 std_device_part2_(w, h, xdpi, ydpi),\ 169 offset_margin_values(0, 0, 0, 0, 0, 0),\ 170 std_device_part3_() 171 172 #define std_device_dci_type_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)\ 173 std_device_dci_alpha_type_body(dtype, pprocs, dname, stype, w, h,\ 174 xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, 1, 1) 175 176 #define std_device_dci_body(dtype, pprocs, dname, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)\ 177 std_device_dci_type_body(dtype, pprocs, dname, 0,\ 178 w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc) 179 180 #define std_device_color_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, max_value, dither, xoff, yoff, lm, bm, rm, tm)\ 181 std_device_part1_(dtype, pprocs, dname, 0, open_init_closed),\ 182 dci_color(depth, max_value, dither),\ 183 std_device_part2_(w, h, xdpi, ydpi),\ 184 offset_margin_values(xoff, yoff, lm, bm, rm, tm),\ 185 std_device_part3_() 186 187 #define std_device_color_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, max_value, dither)\ 188 std_device_color_full_body(dtype, pprocs, dname,\ 189 w, h, xdpi, ydpi,\ 190 depth, max_value, dither,\ 191 0, 0, 0, 0, 0, 0) 192 193 #define std_device_color_stype_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, depth, max_value, dither)\ 194 std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\ 195 dci_color(depth, max_value, dither),\ 196 std_device_part2_(w, h, xdpi, ydpi),\ 197 offset_margin_values(0, 0, 0, 0, 0, 0),\ 198 std_device_part3_() 199 200 #define std_device_std_color_full_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)\ 201 std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\ 202 dci_std_color(depth),\ 203 std_device_part2_(w, h, xdpi, ydpi),\ 204 offset_margin_values(xoff, yoff, lm, bm, rm, tm),\ 205 std_device_part3_() 206 207 #define std_device_std_color_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)\ 208 std_device_std_color_full_body_type(dtype, pprocs, dname, 0,\ 209 w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm) 210 211 /* ---------------- Default implementations ---------------- */ 212 213 /* Default implementations of optional procedures. */ 214 /* Note that the default map_xxx_color routines assume white_on_black. */ 215 dev_proc_open_device(gx_default_open_device); 216 dev_proc_get_initial_matrix(gx_default_get_initial_matrix); 217 dev_proc_get_initial_matrix(gx_upright_get_initial_matrix); 218 dev_proc_sync_output(gx_default_sync_output); 219 dev_proc_output_page(gx_default_output_page); 220 dev_proc_close_device(gx_default_close_device); 221 dev_proc_map_rgb_color(gx_default_w_b_map_rgb_color); 222 dev_proc_map_color_rgb(gx_default_w_b_map_color_rgb); 223 #define gx_default_map_rgb_color gx_default_w_b_map_rgb_color 224 #define gx_default_map_color_rgb gx_default_w_b_map_color_rgb 225 dev_proc_tile_rectangle(gx_default_tile_rectangle); 226 dev_proc_copy_mono(gx_default_copy_mono); 227 dev_proc_copy_color(gx_default_copy_color); 228 dev_proc_draw_line(gx_default_draw_line); 229 dev_proc_get_bits(gx_no_get_bits); /* gives error */ 230 dev_proc_get_bits(gx_default_get_bits); 231 dev_proc_get_params(gx_default_get_params); 232 dev_proc_put_params(gx_default_put_params); 233 dev_proc_map_cmyk_color(gx_default_map_cmyk_color); 234 dev_proc_get_xfont_procs(gx_default_get_xfont_procs); 235 dev_proc_get_xfont_device(gx_default_get_xfont_device); 236 dev_proc_map_rgb_alpha_color(gx_default_map_rgb_alpha_color); 237 dev_proc_get_page_device(gx_default_get_page_device); /* returns NULL */ 238 dev_proc_get_page_device(gx_page_device_get_page_device); /* returns dev */ 239 dev_proc_get_alpha_bits(gx_default_get_alpha_bits); 240 dev_proc_copy_alpha(gx_no_copy_alpha); /* gives error */ 241 dev_proc_copy_alpha(gx_default_copy_alpha); 242 dev_proc_get_band(gx_default_get_band); 243 dev_proc_copy_rop(gx_no_copy_rop); /* gives error */ 244 dev_proc_copy_rop(gx_default_copy_rop); 245 dev_proc_fill_path(gx_default_fill_path); 246 dev_proc_stroke_path(gx_default_stroke_path); 247 dev_proc_fill_mask(gx_default_fill_mask); 248 dev_proc_fill_trapezoid(gx_default_fill_trapezoid); 249 dev_proc_fill_parallelogram(gx_default_fill_parallelogram); 250 dev_proc_fill_triangle(gx_default_fill_triangle); 251 dev_proc_draw_thin_line(gx_default_draw_thin_line); 252 dev_proc_begin_image(gx_default_begin_image); 253 dev_proc_image_data(gx_default_image_data); 254 dev_proc_end_image(gx_default_end_image); 255 dev_proc_strip_tile_rectangle(gx_default_strip_tile_rectangle); 256 dev_proc_strip_copy_rop(gx_no_strip_copy_rop); /* gives error */ 257 dev_proc_strip_copy_rop(gx_default_strip_copy_rop); 258 dev_proc_get_clipping_box(gx_default_get_clipping_box); 259 dev_proc_get_clipping_box(gx_get_largest_clipping_box); 260 dev_proc_begin_typed_image(gx_default_begin_typed_image); 261 dev_proc_get_bits_rectangle(gx_no_get_bits_rectangle); /* gives error */ 262 dev_proc_get_bits_rectangle(gx_default_get_bits_rectangle); 263 dev_proc_map_color_rgb_alpha(gx_default_map_color_rgb_alpha); 264 dev_proc_create_compositor(gx_no_create_compositor); 265 /* default is for ordinary "leaf" devices, null is for */ 266 /* devices that only care about coverage and not contents. */ 267 dev_proc_create_compositor(gx_default_create_compositor); 268 dev_proc_create_compositor(gx_null_create_compositor); 269 dev_proc_get_hardware_params(gx_default_get_hardware_params); 270 dev_proc_text_begin(gx_default_text_begin); 271 dev_proc_finish_copydevice(gx_default_finish_copydevice); 272 dev_proc_pattern_manage(gx_default_pattern_manage); 273 dev_proc_fill_rectangle_hl_color(gx_default_fill_rectangle_hl_color); 274 dev_proc_include_color_space(gx_default_include_color_space); 275 dev_proc_fill_linear_color_scanline(gx_default_fill_linear_color_scanline); 276 dev_proc_fill_linear_color_trapezoid(gx_default_fill_linear_color_trapezoid); 277 dev_proc_fill_linear_color_triangle(gx_default_fill_linear_color_triangle); 278 dev_proc_update_spot_equivalent_colors(gx_default_update_spot_equivalent_colors); 279 /* BACKWARD COMPATIBILITY */ 280 #define gx_non_imaging_create_compositor gx_null_create_compositor 281 282 /* Color mapping routines for black-on-white, gray scale, true RGB, */ 283 /* true CMYK, and 1-bit CMYK color. */ 284 dev_proc_map_rgb_color(gx_default_b_w_map_rgb_color); 285 dev_proc_map_color_rgb(gx_default_b_w_map_color_rgb); 286 dev_proc_map_rgb_color(gx_default_gray_map_rgb_color); 287 dev_proc_map_color_rgb(gx_default_gray_map_color_rgb); 288 dev_proc_map_color_rgb(gx_default_rgb_map_color_rgb); 289 #define gx_default_cmyk_map_cmyk_color cmyk_8bit_map_cmyk_color /*see below*/ 290 /* 291 * The following are defined as "standard" color mapping procedures 292 * that can be propagated through device pipelines and that color 293 * processing code can test for. 294 */ 295 dev_proc_map_rgb_color(gx_default_rgb_map_rgb_color); 296 dev_proc_map_cmyk_color(cmyk_1bit_map_cmyk_color); 297 dev_proc_map_color_rgb(cmyk_1bit_map_color_rgb); 298 dev_proc_decode_color(cmyk_1bit_map_color_cmyk); 299 dev_proc_map_cmyk_color(cmyk_8bit_map_cmyk_color); 300 dev_proc_map_color_rgb(cmyk_8bit_map_color_rgb); 301 dev_proc_decode_color(cmyk_8bit_map_color_cmyk); 302 dev_proc_encode_color(gx_default_8bit_map_gray_color); 303 dev_proc_decode_color(gx_default_8bit_map_color_gray); 304 305 /* Default implementations for forwarding devices */ 306 dev_proc_close_device(gx_forward_close_device); 307 dev_proc_get_initial_matrix(gx_forward_get_initial_matrix); 308 dev_proc_sync_output(gx_forward_sync_output); 309 dev_proc_output_page(gx_forward_output_page); 310 dev_proc_map_rgb_color(gx_forward_map_rgb_color); 311 dev_proc_map_color_rgb(gx_forward_map_color_rgb); 312 dev_proc_fill_rectangle(gx_forward_fill_rectangle); 313 dev_proc_tile_rectangle(gx_forward_tile_rectangle); 314 dev_proc_copy_mono(gx_forward_copy_mono); 315 dev_proc_copy_color(gx_forward_copy_color); 316 dev_proc_get_bits(gx_forward_get_bits); 317 dev_proc_get_params(gx_forward_get_params); 318 dev_proc_put_params(gx_forward_put_params); 319 dev_proc_map_cmyk_color(gx_forward_map_cmyk_color); 320 dev_proc_get_xfont_procs(gx_forward_get_xfont_procs); 321 dev_proc_get_xfont_device(gx_forward_get_xfont_device); 322 dev_proc_map_rgb_alpha_color(gx_forward_map_rgb_alpha_color); 323 dev_proc_get_page_device(gx_forward_get_page_device); 324 #define gx_forward_get_alpha_bits gx_default_get_alpha_bits 325 dev_proc_copy_alpha(gx_forward_copy_alpha); 326 dev_proc_get_band(gx_forward_get_band); 327 dev_proc_copy_rop(gx_forward_copy_rop); 328 dev_proc_fill_path(gx_forward_fill_path); 329 dev_proc_stroke_path(gx_forward_stroke_path); 330 dev_proc_fill_mask(gx_forward_fill_mask); 331 dev_proc_fill_trapezoid(gx_forward_fill_trapezoid); 332 dev_proc_fill_parallelogram(gx_forward_fill_parallelogram); 333 dev_proc_fill_triangle(gx_forward_fill_triangle); 334 dev_proc_draw_thin_line(gx_forward_draw_thin_line); 335 dev_proc_begin_image(gx_forward_begin_image); 336 #define gx_forward_image_data gx_default_image_data 337 #define gx_forward_end_image gx_default_end_image 338 dev_proc_strip_tile_rectangle(gx_forward_strip_tile_rectangle); 339 dev_proc_strip_copy_rop(gx_forward_strip_copy_rop); 340 dev_proc_get_clipping_box(gx_forward_get_clipping_box); 341 dev_proc_begin_typed_image(gx_forward_begin_typed_image); 342 dev_proc_get_bits_rectangle(gx_forward_get_bits_rectangle); 343 dev_proc_map_color_rgb_alpha(gx_forward_map_color_rgb_alpha); 344 /* There is no forward_create_compositor (see Drivers.htm). */ 345 dev_proc_get_hardware_params(gx_forward_get_hardware_params); 346 dev_proc_text_begin(gx_forward_text_begin); 347 dev_proc_get_color_mapping_procs(gx_forward_get_color_mapping_procs); 348 dev_proc_get_color_comp_index(gx_forward_get_color_comp_index); 349 dev_proc_encode_color(gx_forward_encode_color); 350 dev_proc_decode_color(gx_forward_decode_color); 351 dev_proc_pattern_manage(gx_forward_pattern_manage); 352 dev_proc_fill_rectangle_hl_color(gx_forward_fill_rectangle_hl_color); 353 dev_proc_include_color_space(gx_forward_include_color_space); 354 dev_proc_fill_linear_color_scanline(gx_forward_fill_linear_color_scanline); 355 dev_proc_fill_linear_color_trapezoid(gx_forward_fill_linear_color_trapezoid); 356 dev_proc_fill_linear_color_triangle(gx_forward_fill_linear_color_triangle); 357 dev_proc_update_spot_equivalent_colors(gx_forward_update_spot_equivalent_colors); 358 359 /* ---------------- Implementation utilities ---------------- */ 360 361 /* Convert the device procedures to the proper form (see above). */ 362 void gx_device_set_procs(gx_device *); 363 364 /* Fill in defaulted procedures in a device procedure record. */ 365 void gx_device_fill_in_procs(gx_device *); 366 void gx_device_forward_fill_in_procs(gx_device_forward *); 367 368 /* Forward the color mapping procedures from a device to its target. */ 369 void gx_device_forward_color_procs(gx_device_forward *); 370 371 /* 372 * Check if the device's encode_color routine uses 'separable' bit encodings 373 * for each colorant. For more info see the routine's header. 374 */ 375 void check_device_separable(gx_device * dev); 376 /* 377 * If a device has a linear and separable encode color function then 378 * set up the comp_bits, comp_mask, and comp_shift fields. 379 */ 380 void set_linear_color_bits_mask_shift(gx_device * dev); 381 /* 382 * Copy the color mapping procedures from the target if they are 383 * standard ones (saving a level of procedure call at mapping time). 384 */ 385 void gx_device_copy_color_procs(gx_device *dev, const gx_device *target); 386 387 /* Get the black and white pixel values of a device. */ 388 gx_color_index gx_device_black(gx_device *dev); 389 #define gx_device_black_inline(dev)\ 390 ((dev)->cached_colors.black == gx_no_color_index ?\ 391 gx_device_black(dev) : (dev)->cached_colors.black) 392 gx_color_index gx_device_white(gx_device *dev); 393 #define gx_device_white_inline(dev)\ 394 ((dev)->cached_colors.white == gx_no_color_index ?\ 395 gx_device_white(dev) : (dev)->cached_colors.white) 396 397 /* Clear the black/white pixel cache. */ 398 void gx_device_decache_colors(gx_device *dev); 399 400 /* 401 * Copy the color-related device parameters back from the target: 402 * color_info and color mapping procedures. 403 */ 404 void gx_device_copy_color_params(gx_device *dev, const gx_device *target); 405 406 /* 407 * Copy device parameters back from a target. This copies all standard 408 * parameters related to page size and resolution, plus color_info 409 * and (if appropriate) color mapping procedures. 410 */ 411 void gx_device_copy_params(gx_device *dev, const gx_device *target); 412 413 /* 414 * Parse the output file name for a device, recognizing "-" and "|command", 415 * and also detecting and validating any %nnd format for inserting the 416 * page count. If a format is present, store a pointer to its last 417 * character in *pfmt, otherwise store 0 there. Note that an empty name 418 * is currently allowed. 419 */ 420 int gx_parse_output_file_name(gs_parsed_file_name_t *pfn, 421 const char **pfmt, const char *fname, 422 uint len); 423 424 /* 425 * Open the output file for a device. Note that if the file name is empty, 426 * it may be replaced with the name of a scratch file. 427 */ 428 int gx_device_open_output_file(const gx_device * dev, char *fname, 429 bool binary, bool positionable, 430 FILE ** pfile); 431 432 /* Close the output file for a device. */ 433 int gx_device_close_output_file(const gx_device * dev, const char *fname, 434 FILE *file); 435 436 /* 437 * Define the number of levels for a colorant above which we do not halftone. 438 */ 439 #define MIN_CONTONE_LEVELS 31 440 441 /* 442 * Determine whether a given device needs to halftone. Eventually this 443 * should take an imager state as an additional argument. 444 */ 445 #define gx_device_must_halftone(dev)\ 446 ((gx_device_has_color(dev) ? (dev)->color_info.max_color :\ 447 (dev)->color_info.max_gray) < MIN_CONTONE_LEVELS) 448 449 /* 450 * Do generic work for output_page. All output_page procedures must call 451 * this as the last thing they do, unless an error has occurred earlier. 452 */ 453 dev_proc_output_page(gx_finish_output_page); 454 455 /* 456 * Device procedures that draw into rectangles need to clip the coordinates 457 * to the rectangle ((0,0),(dev->width,dev->height)). The following macros 458 * do the clipping. They assume that the arguments of the procedure are 459 * named dev, x, y, w, and h, and may modify the arguments (other than dev). 460 * 461 * For procedures that fill a region, dev, x, y, w, and h are the only 462 * relevant arguments. For procedures that copy bitmaps, see below. 463 * 464 * The following group of macros for region-filling procedures clips 465 * specific edges of the supplied rectangle, as indicated by the macro name. 466 */ 467 #define fit_fill_xy(dev, x, y, w, h)\ 468 BEGIN\ 469 if ( (x | y) < 0 ) {\ 470 if ( x < 0 )\ 471 w += x, x = 0;\ 472 if ( y < 0 )\ 473 h += y, y = 0;\ 474 }\ 475 END 476 #define fit_fill_y(dev, y, h)\ 477 BEGIN\ 478 if ( y < 0 )\ 479 h += y, y = 0;\ 480 END 481 #define fit_fill_w(dev, x, w)\ 482 BEGIN\ 483 if ( w > (dev)->width - x )\ 484 w = (dev)->width - x;\ 485 END 486 #define fit_fill_h(dev, y, h)\ 487 BEGIN\ 488 if ( h > (dev)->height - y )\ 489 h = (dev)->height - y;\ 490 END 491 #define fit_fill_xywh(dev, x, y, w, h)\ 492 BEGIN\ 493 fit_fill_xy(dev, x, y, w, h);\ 494 fit_fill_w(dev, x, w);\ 495 fit_fill_h(dev, y, h);\ 496 END 497 /* 498 * Clip all edges, and return from the procedure if the result is empty. 499 */ 500 #define fit_fill(dev, x, y, w, h)\ 501 BEGIN\ 502 fit_fill_xywh(dev, x, y, w, h);\ 503 if ( w <= 0 || h <= 0 )\ 504 return 0;\ 505 END 506 507 /* 508 * For driver procedures that copy bitmaps (e.g., copy_mono, copy_color), 509 * clipping the destination region also may require adjusting the pointer to 510 * the source data. In addition to dev, x, y, w, and h, the clipping macros 511 * for these procedures reference data, data_x, raster, and id; they may 512 * modify the values of data, data_x, and id. 513 * 514 * Clip the edges indicated by the macro name. 515 */ 516 #define fit_copy_xyw(dev, data, data_x, raster, id, x, y, w, h)\ 517 BEGIN\ 518 if ( (x | y) < 0 ) {\ 519 if ( x < 0 )\ 520 w += x, data_x -= x, x = 0;\ 521 if ( y < 0 )\ 522 h += y, data -= y * raster, id = gx_no_bitmap_id, y = 0;\ 523 }\ 524 if ( w > (dev)->width - x )\ 525 w = (dev)->width - x;\ 526 END 527 /* 528 * Clip all edges, and return from the procedure if the result is empty. 529 */ 530 #define fit_copy(dev, data, data_x, raster, id, x, y, w, h)\ 531 BEGIN\ 532 fit_copy_xyw(dev, data, data_x, raster, id, x, y, w, h);\ 533 if ( h > (dev)->height - y )\ 534 h = (dev)->height - y;\ 535 if ( w <= 0 || h <= 0 )\ 536 return 0;\ 537 END 538 539 /* ---------------- Media parameters ---------------- */ 540 541 /* Define the InputAttributes and OutputAttributes of a device. */ 542 /* The device get_params procedure would call these. */ 543 544 typedef struct gdev_input_media_s { 545 float PageSize[4]; /* nota bene */ 546 const char *MediaColor; 547 float MediaWeight; 548 const char *MediaType; 549 } gdev_input_media_t; 550 551 #define gdev_input_media_default_values { 0, 0, 0, 0 }, 0, 0, 0 552 extern const gdev_input_media_t gdev_input_media_default; 553 554 void gdev_input_media_init(gdev_input_media_t * pim); 555 556 int gdev_begin_input_media(gs_param_list * mlist, gs_param_dict * pdict, 557 int count); 558 559 int gdev_write_input_page_size(int index, gs_param_dict * pdict, 560 floatp width_points, floatp height_points); 561 562 int gdev_write_input_media(int index, gs_param_dict * pdict, 563 const gdev_input_media_t * pim); 564 565 int gdev_end_input_media(gs_param_list * mlist, gs_param_dict * pdict); 566 567 typedef struct gdev_output_media_s { 568 const char *OutputType; 569 } gdev_output_media_t; 570 571 #define gdev_output_media_default_values 0 572 extern const gdev_output_media_t gdev_output_media_default; 573 574 int gdev_begin_output_media(gs_param_list * mlist, gs_param_dict * pdict, 575 int count); 576 577 int gdev_write_output_media(int index, gs_param_dict * pdict, 578 const gdev_output_media_t * pom); 579 580 int gdev_end_output_media(gs_param_list * mlist, gs_param_dict * pdict); 581 582 #endif /* gxdevice_INCLUDED */ 583