1 /* Copyright (C) 2001-2019 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, 13 CA 94945, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Definitions for X Windows drivers */ 18 /* Requires gxdevice.h and x_.h */ 19 20 #ifndef gdevx_INCLUDED 21 # define gdevx_INCLUDED 22 23 #include "gdevbbox.h" 24 #include "gdevxcmp.h" 25 26 /* Declare the X resource tables compiled separately in gdevxres.c. */ 27 extern XtResource gdev_x_resources[]; 28 extern const int gdev_x_resource_count; 29 extern String gdev_x_fallback_resources[]; 30 31 /* Define the X Windows device */ 32 typedef struct gx_device_X_s { 33 gx_device_bbox_common; /* if target != 0, is image buffer */ 34 /* 35 * Normally, an X device has an image buffer iff target != 0. However, 36 * the bbox device sometimes sets target to NULL temporarily, so we need 37 * a separate flag to record whether this device is buffered. 38 */ 39 bool is_buffered; 40 bool IsPageDevice; 41 byte *buffer; /* full-window image */ 42 long buffer_size; 43 gx_device_color_info orig_color_info; 44 45 /* An XImage object for writing bitmap images to the screen */ 46 XImage image; 47 48 /* Global X state */ 49 Display *dpy; 50 Screen *scr; 51 XVisualInfo *vinfo; 52 Colormap cmap; 53 Window win; 54 GC gc; 55 56 /* An optional Window ID supplied as a device parameter */ 57 Window pwin; 58 59 /* A backing pixmap so X will handle exposure automatically */ 60 Pixmap bpixmap; /* 0 if useBackingPixmap is false, */ 61 /* or if it can't be allocated */ 62 int ghostview; /* flag to tell if ghostview is in control */ 63 Window mwin; /* window to receive ghostview messages */ 64 gs_matrix initial_matrix; /* the initial transformation */ 65 Atom NEXT, PAGE, DONE; /* Atoms used to talk to ghostview */ 66 struct { 67 gs_int_rect box; /* region needing updating */ 68 long area; /* total area of update */ 69 long total; /* total of individual area updates */ 70 int count; /* # of updates since flush */ 71 } update; 72 Pixmap dest; /* bpixmap if non-0, else use win */ 73 x_pixel colors_or; /* 'or' of all device colors used so far */ 74 x_pixel colors_and; /* 'and' ditto */ 75 76 /* An intermediate pixmap for the stencil case of copy_mono */ 77 struct { 78 Pixmap pixmap; 79 GC gc; 80 int raster, height; 81 } cp; 82 83 /* Structure for dealing with the halftone tile. */ 84 /* Later this might become a multi-element cache. */ 85 struct { 86 Pixmap pixmap; 87 Pixmap no_pixmap; /* kludge to get around X bug */ 88 gx_bitmap_id id; 89 int width, height, raster; 90 x_pixel fore_c, back_c; 91 } ht; 92 93 /* Cache the function and fill style from the GC */ 94 int function; 95 int fill_style; 96 Font fid; 97 98 #define X_SET_FILL_STYLE(xdev, style)\ 99 BEGIN\ 100 if (xdev->fill_style != (style))\ 101 XSetFillStyle(xdev->dpy, xdev->gc, (xdev->fill_style = (style)));\ 102 END 103 #define X_SET_FUNCTION(xdev, func)\ 104 BEGIN\ 105 if (xdev->function != (func))\ 106 XSetFunction(xdev->dpy, xdev->gc, (xdev->function = (func)));\ 107 END 108 #define X_SET_FONT(xdev, font)\ 109 BEGIN\ 110 if (xdev->fid != (font))\ 111 XSetFont(xdev->dpy, xdev->gc, (xdev->fid = (font)));\ 112 END 113 114 x_pixel back_color, fore_color; 115 116 Pixel background, foreground; 117 118 /* 119 * The color management structure is defined in gdevxcmp.h and is 120 * managed by the code in gdevxcmp.c. 121 */ 122 x11_cman_t cman; 123 124 #define NOTE_COLOR(xdev, pixel)\ 125 (xdev->colors_or |= (pixel),\ 126 xdev->colors_and &= (pixel)) 127 #define X_SET_BACK_COLOR(xdev, pixel)\ 128 BEGIN\ 129 if (xdev->back_color != (pixel)) {\ 130 xdev->back_color = (pixel);\ 131 NOTE_COLOR(xdev, pixel);\ 132 XSetBackground(xdev->dpy, xdev->gc, (pixel));\ 133 }\ 134 END 135 #define X_SET_FORE_COLOR(xdev, pixel)\ 136 BEGIN\ 137 if (xdev->fore_color != (pixel)) {\ 138 xdev->fore_color = (pixel);\ 139 NOTE_COLOR(xdev, pixel);\ 140 XSetForeground(xdev->dpy, xdev->gc, (pixel));\ 141 }\ 142 END 143 144 /* Defaults set by resources */ 145 Pixel borderColor; 146 Dimension borderWidth; 147 String geometry; 148 int maxGrayRamp, maxRGBRamp; 149 String palette; 150 float xResolution, yResolution; 151 152 /* Flags work around various X server problems. */ 153 Boolean useBackingPixmap; 154 Boolean useXPutImage; 155 Boolean useXSetTile; 156 157 /* 158 * Parameters for the screen update algorithms. 159 */ 160 161 /* 162 * Define whether to update after every write, for debugging. 163 * Note that one can obtain the same effect by setting any of 164 */ 165 bool AlwaysUpdate; 166 /* 167 * Define the maximum size of the temporary pixmap for copy_mono 168 * that we are willing to leave lying around in the server 169 * between uses. 170 */ 171 int MaxTempPixmap; 172 /* 173 * Define the maximum size of the temporary image created in memory 174 * for get_bits_rectangle. 175 */ 176 int MaxTempImage; 177 178 /* 179 * Buffered text awaiting display. 180 */ 181 struct { 182 int item_count; 183 #define IN_TEXT(xdev) ((xdev)->text.item_count != 0) 184 int char_count; 185 gs_int_point origin; 186 int x; /* after last buffered char */ 187 #define MAX_TEXT_ITEMS 12 188 XTextItem items[MAX_TEXT_ITEMS]; 189 #define MAX_TEXT_CHARS 25 190 char chars[MAX_TEXT_CHARS]; 191 } text; 192 /* 193 * All the GC parameters are set correctly when we buffer the first 194 * character: we must call DRAW_TEXT before resetting any of them. 195 * DRAW_TEXT assumes xdev->text.{item,char}_count > 0. 196 */ 197 #define DRAW_TEXT(xdev)\ 198 XDrawText(xdev->dpy, xdev->dest, xdev->gc, xdev->text.origin.x,\ 199 xdev->text.origin.y, xdev->text.items, xdev->text.item_count) 200 201 } gx_device_X; 202 #define private_st_device_X() /* in gdevx.c */\ 203 gs_public_st_suffix_add1_final(st_device_X, gx_device_X,\ 204 "gx_device_X", device_x_enum_ptrs, device_x_reloc_ptrs,\ 205 gx_device_finalize, st_device_bbox, buffer) 206 207 /* Send an event to the Ghostview process */ 208 void gdev_x_send_event(gx_device_X *xdev, Atom msg); 209 210 /* function to keep track of screen updates */ 211 void x_update_add(gx_device_X *, int, int, int, int); 212 void gdev_x_clear_window(gx_device_X *); 213 int x_catch_free_colors(Display *, XErrorEvent *); 214 215 /* Number used to distinguish when resolution was set from the command line */ 216 #define FAKE_RES (16*72) 217 218 /* ------ Inter-module procedures ------ */ 219 220 /* Exported by gdevxcmp.c for gdevxini.c */ 221 int gdev_x_setup_colors(gx_device_X *); 222 void gdev_x_free_colors(gx_device_X *); 223 void gdev_x_free_dynamic_colors(gx_device_X *); 224 225 /* Exported by gdevxini.c for gdevx.c */ 226 int gdev_x_open(gx_device_X *); 227 int gdev_x_close(gx_device_X *); 228 229 /* Driver procedures exported for gdevx.c */ 230 dev_proc_map_rgb_color(gdev_x_map_rgb_color); /* gdevxcmp.c */ 231 dev_proc_map_color_rgb(gdev_x_map_color_rgb); /* gdevxcmp.c */ 232 dev_proc_get_params(gdev_x_get_params); /* gdevxini.c */ 233 dev_proc_put_params(gdev_x_put_params); /* gdevxini.c */ 234 dev_proc_finish_copydevice(gdev_x_finish_copydevice); /* gdevxini.c */ 235 236 #endif /* gdevx_INCLUDED */ 237