summaryrefslogtreecommitdiff
path: root/gs/src/gdevx.h
blob: b0606b569902d8404409db2087b568d9dba6ec22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* Copyright (C) 1989, 1995, 1997, 1998 Aladdin Enterprises.  All rights reserved.

   This file is part of Aladdin Ghostscript.

   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
   or distributor accepts any responsibility for the consequences of using it,
   or for whether it serves any particular purpose or works at all, unless he
   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
   License (the "License") for full details.

   Every copy of Aladdin Ghostscript must include a copy of the License,
   normally in a plain ASCII text file named PUBLIC.  The License grants you
   the right to copy, modify and redistribute Aladdin Ghostscript, but only
   under certain conditions described in the License.  Among other things, the
   License requires that the copyright notice and this notice be preserved on
   all copies.
 */


/* Requires gxdevice.h and x_.h */

#ifndef gdevx_INCLUDED
#  define gdevx_INCLUDED

/* Define the type of an X pixel. */
typedef unsigned long x_pixel;

/* Define a rectangle structure for update bookkeeping */
typedef struct rect_s {
    int xo, yo, xe, ye;
} rect;

/* Define dynamic color hash table structure */
struct x11color_s;
typedef struct x11color_s x11color;
struct x11color_s {
    XColor color;
    x11color *next;
};

/* Define PostScript to X11 font name mapping */
struct x11fontmap_s;
typedef struct x11fontmap_s x11fontmap;
struct x11fontmap_s {
    char *ps_name;
    char *x11_name;
    char **std_names;
    char **iso_names;
    int std_count, iso_count;
    x11fontmap *next;
};

/* Define pixel value to RGB mapping */
typedef struct x11_rgb_s {
    gx_color_value rgb[3];
    bool defined;
} x11_rgb_t;

/* Define the X Windows device */
typedef struct gx_device_X_s {
    gx_device_common;
    bool IsPageDevice;

    /* An XImage object for writing bitmap images to the screen */
    XImage image;

    /* Global X state */
    Display *dpy;
    Screen *scr;
    XVisualInfo *vinfo;
    Colormap cmap;
    Window win;
    GC gc;

    /* An optional Window ID supplied as a device parameter */
    Window pwin;

    /* A backing pixmap so X will handle exposure automatically */
    Pixmap bpixmap;		/* 0 if useBackingPixmap is false, */
    /* or if it can't be allocated */
    int ghostview;		/* flag to tell if ghostview is in control */
    Window mwin;		/* window to receive ghostview messages */
/* Don't include standard colormap stuff for X11R3 and earlier */
#if HaveStdCMap
    XStandardColormap *std_cmap;	/* standard color map if available */
#endif
    gs_matrix initial_matrix;	/* the initial transformation */
    Atom NEXT, PAGE, DONE;	/* Atoms used to talk to ghostview */
    rect update;		/* region needing updating */
    long up_area;		/* total area of update */
    /* (always 0 if no backing pixmap) */
    int up_count;		/* # of updates since flush */
    Pixmap dest;		/* bpixmap if non-0, else win */
    x_pixel colors_or;		/* 'or' of all device colors used so far */
    x_pixel colors_and;		/* 'and' ditto */

    /* An intermediate pixmap for the stencil case of copy_mono */
    struct {
	Pixmap pixmap;
	GC gc;
	int raster, height;
    } cp;

    /* Structure for dealing with the halftone tile. */
    /* Later this might become a multi-element cache. */
    struct {
	Pixmap pixmap;
	Pixmap no_pixmap;	/* kludge to get around X bug */
	gx_bitmap_id id;
	int width, height, raster;
	x_pixel fore_c, back_c;
    } ht;

    /* Cache the function and fill style from the GC */
    int function;
    int fill_style;
    Font fid;

#define set_fill_style(style)\
  if ( xdev->fill_style != style )\
    XSetFillStyle(xdev->dpy, xdev->gc, (xdev->fill_style = style))
#define set_function(func)\
  if ( xdev->function != func )\
    XSetFunction(xdev->dpy, xdev->gc, (xdev->function = func))
#define set_font(font)\
  if ( xdev->fid != font )\
    XSetFont(xdev->dpy, xdev->gc, (xdev->fid = font))

    x_pixel back_color, fore_color;

    Pixel background, foreground;
#define X_max_color_value 0xffff
#define cube_index(r,g,b) (((r) * xdev->color_info.dither_colors + (g)) * \
				  xdev->color_info.dither_colors + (b))
    x_pixel *dither_colors;
    ushort color_mask;
    int num_rgb;
    x11color *(*dynamic_colors)[];
    int max_dynamic_colors, dynamic_size, dynamic_allocs;
    x11_rgb_t *color_to_rgb;	/* [256] */
    int color_to_rgb_size;

#define note_color(pixel)\
  xdev->colors_or |= pixel,\
  xdev->colors_and &= pixel
#define set_back_color(pixel)\
  if ( xdev->back_color != pixel )\
   { xdev->back_color = pixel;\
     note_color(pixel);\
     XSetBackground(xdev->dpy, xdev->gc, pixel);\
   }
#define set_fore_color(pixel)\
  if ( xdev->fore_color != pixel )\
   { xdev->fore_color = pixel;\
     note_color(pixel);\
     XSetForeground(xdev->dpy, xdev->gc, pixel);\
   }

    /* Defaults set by resources */
    Pixel borderColor;
    Dimension borderWidth;
    String geometry;
    int maxGrayRamp, maxRGBRamp;
    String palette;
    String regularFonts;
    String symbolFonts;
    String dingbatFonts;
    x11fontmap *regular_fonts;
    x11fontmap *symbol_fonts;
    x11fontmap *dingbat_fonts;
    Boolean useXFonts, useFontExtensions, useScalableFonts, logXFonts;
    float xResolution, yResolution;

    /* Flags work around various X server problems. */
    Boolean useBackingPixmap;
    Boolean useXPutImage;
    Boolean useXSetTile;

    /* Buffered text awaiting display */
    struct {
	int item_count;
#define IN_TEXT(xdev) ((xdev)->text.item_count != 0)
	int char_count;
	gs_int_point origin;
	int x;			/* after last buffered char */
#define MAX_TEXT_ITEMS 12
	XTextItem items[MAX_TEXT_ITEMS];
#define MAX_TEXT_CHARS 25
	char chars[MAX_TEXT_CHARS];
    } text;
/*
 * All the GC parameters are set correctly when we buffer the first
 * character: we must call DRAW_TEXT before resetting any of them.
 * DRAW_TEXT assumes xdev->text.{item,char}_count > 0.
 */
#define DRAW_TEXT(xdev)\
   XDrawText(xdev->dpy, xdev->dest, xdev->gc, xdev->text.origin.x,\
	     xdev->text.origin.y, xdev->text.items, xdev->text.item_count)

} gx_device_X;

/* function to keep track of screen updates */
void x_update_add(P5(gx_device *, int, int, int, int));
void gdev_x_clear_window(P1(gx_device_X *));
int x_catch_free_colors(P2(Display *, XErrorEvent *));

/* Number used to distinguish when resolution was set from the command line */
#define FAKE_RES (16*72)

#endif /* gdevx_INCLUDED */