1 /* Copyright (C) 1996, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. 2 3 This file is part of AFPL Ghostscript. 4 5 AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or 6 distributor accepts any responsibility for the consequences of using it, or 7 for whether it serves any particular purpose or works at all, unless he or 8 she says so in writing. Refer to the Aladdin Free Public License (the 9 "License") for full details. 10 11 Every copy of AFPL Ghostscript must include a copy of the License, normally 12 in a plain ASCII text file named PUBLIC. The License grants you the right 13 to copy, modify and redistribute AFPL Ghostscript, but only under certain 14 conditions described in the License. Among other things, the License 15 requires that the copyright notice and this notice be preserved on all 16 copies. 17 */ 18 19 /*$Id: gdevbbox.h,v 1.2 2000/09/19 19:00:11 lpd Exp $ */ 20 /* Definitions and interface for bbox (bounding box accumulator) device */ 21 /* Requires gxdevice.h */ 22 23 #ifndef gdevbbox_INCLUDED 24 # define gdevbbox_INCLUDED 25 26 /* 27 * This device keeps track of the per-page bounding box, and also optionally 28 * forwards all drawing commands to a target. It can be used either as a 29 * free-standing device or as a component (e.g., by the EPS writer). 30 * 31 * One way to use a bounding box device is simply to include bbox.dev in the 32 * value of DEVICE_DEVSn in the makefile. This produces a free-standing 33 * device named 'bbox' that can be selected in the usual way (-sDEVICE=bbox) 34 * and that prints out the bounding box at each showpage or copypage without 35 * doing any drawing. 36 * 37 * The other way to use a bounding box device is from C code as a component 38 * in a device pipeline. To set up a bounding box device that doesn't do 39 * any drawing: 40 * gx_device_bbox *bdev = 41 * gs_alloc_struct_immovable(some_memory, 42 * gx_device_bbox, &st_device_bbox, 43 * "some identifying string for debugging"); 44 * gx_device_bbox_init(bdev, NULL); 45 * Non-drawing bounding box devices have an "infinite" page size. 46 * 47 * To set up a bounding box device that draws to another device tdev: 48 * gx_device_bbox *bdev = 49 * gs_alloc_struct_immovable(some_memory, 50 * gx_device_bbox, &st_device_bbox, 51 * "some identifying string for debugging"); 52 * gx_device_bbox_init(bdev, tdev); 53 * Bounding box devices that draw to a real device appear to have the 54 * same page size as that device. 55 * 56 * To intercept the end-of-page to call a routine eop of your own, after 57 * setting up the device: 58 * dev_proc_output_page(eop); -- declare a prototype for eop 59 * ... 60 * set_dev_proc(bdev, output_page, eop); 61 * ... 62 * int eop(gx_device *dev, int num_copies, int flush) 63 * { gs_rect bbox; 64 * gx_device_bbox_bbox((gx_device_bbox *)dev, &bbox); 65 * << do whatever you want >> 66 * return gx_forward_output_page(dev, num_copies, flush); 67 * } 68 * 69 * Note that bounding box devices, unlike almost all other forwarding 70 * devices, conditionally propagate the open_device and close_device 71 * calls to their target. By default, they do propagate these calls: 72 * use gx_device_bbox_fwd_open_close to change this if you want. 73 */ 74 /* 75 * Define virtual procedures for managing the accumulated bounding box. 76 * These may be redefined by subclasses, and are also used for compositors. 77 */ 78 typedef struct gx_device_bbox_procs_s { 79 80 #define dev_bbox_proc_init_box(proc)\ 81 bool proc(P1(void *proc_data)) 82 dev_bbox_proc_init_box((*init_box)); 83 84 #define dev_bbox_proc_get_box(proc)\ 85 void proc(P2(const void *proc_data, gs_fixed_rect *pbox)) 86 dev_bbox_proc_get_box((*get_box)); 87 88 #define dev_bbox_proc_add_rect(proc)\ 89 void proc(P5(void *proc_data, fixed x0, fixed y0, fixed x1, fixed y1)) 90 dev_bbox_proc_add_rect((*add_rect)); 91 92 #define dev_bbox_proc_in_rect(proc)\ 93 bool proc(P2(const void *proc_data, const gs_fixed_rect *pbox)) 94 dev_bbox_proc_in_rect((*in_rect)); 95 96 } gx_device_bbox_procs_t; 97 /* Default implementations */ 98 dev_bbox_proc_init_box(bbox_default_init_box); 99 dev_bbox_proc_get_box(bbox_default_get_box); 100 dev_bbox_proc_add_rect(bbox_default_add_rect); 101 dev_bbox_proc_in_rect(bbox_default_in_rect); 102 103 #define gx_device_bbox_common\ 104 gx_device_forward_common;\ 105 bool free_standing;\ 106 bool forward_open_close;\ 107 gx_device_bbox_procs_t box_procs;\ 108 void *box_proc_data;\ 109 bool white_is_opaque;\ 110 /* The following are updated dynamically. */\ 111 gs_fixed_rect bbox;\ 112 gx_color_index black, white;\ 113 gx_color_index transparent /* white or gx_no_color_index */ 114 typedef struct gx_device_bbox_s gx_device_bbox; 115 #define gx_device_bbox_common_initial(fs, foc, wio)\ 116 0 /* target */,\ 117 fs, foc, {0}, 0, wio,\ 118 {{0, 0}, {0, 0}}, gx_no_color_index, gx_no_color_index, gx_no_color_index 119 struct gx_device_bbox_s { 120 gx_device_bbox_common; 121 }; 122 123 extern_st(st_device_bbox); 124 #define public_st_device_bbox() /* in gdevbbox.c */\ 125 gs_public_st_suffix_add1_final(st_device_bbox, gx_device_bbox,\ 126 "gx_device_bbox", device_bbox_enum_ptrs, device_bbox_reloc_ptrs,\ 127 gx_device_finalize, st_device_forward, box_proc_data) 128 129 /* Initialize a bounding box device. */ 130 void gx_device_bbox_init(P2(gx_device_bbox * dev, gx_device * target)); 131 132 /* Set whether a bounding box device propagates open/close to its target. */ 133 void gx_device_bbox_fwd_open_close(P2(gx_device_bbox * dev, 134 bool forward_open_close)); 135 136 /* Set whether a bounding box device considers white to be opaque. */ 137 void gx_device_bbox_set_white_opaque(P2(gx_device_bbox *dev, 138 bool white_is_opaque)); 139 140 /* Read back the bounding box in 1/72" units. */ 141 void gx_device_bbox_bbox(P2(gx_device_bbox * dev, gs_rect * pbbox)); 142 143 /* Release a bounding box device. */ 144 void gx_device_bbox_release(P1(gx_device_bbox *dev)); 145 146 #endif /* gdevbbox_INCLUDED */ 147