1 /* cairo - a vector graphics library with display and print output
2 *
3 * Copyright © 2005 Red Hat, Inc
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it either under the terms of the GNU Lesser General Public
7 * License version 2.1 as published by the Free Software Foundation
8 * (the "LGPL") or, at your option, under the terms of the Mozilla
9 * Public License Version 1.1 (the "MPL"). If you do not alter this
10 * notice, a recipient may use your version of this file under either
11 * the MPL or the LGPL.
12 *
13 * You should have received a copy of the LGPL along with this library
14 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
18 *
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License at
22 * http://www.mozilla.org/MPL/
23 *
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26 * the specific language governing rights and limitations.
27 *
28 * The Original Code is the cairo graphics library.
29 *
30 * The Initial Developer of the Original Code is Red Hat, Inc.
31 *
32 * Contributor(s):
33 * Owen Taylor <otaylor@redhat.com>
34 */
35
36 #ifndef CAIRO_WIN32_PRIVATE_H
37 #define CAIRO_WIN32_PRIVATE_H
38
39 #include "cairo-win32.h"
40 #include "cairoint.h"
41 #include "cairo-surface-clipper-private.h"
42
43 #ifndef SHADEBLENDCAPS
44 #define SHADEBLENDCAPS 120
45 #endif
46 #ifndef SB_NONE
47 #define SB_NONE 0
48 #endif
49
50 #define WIN32_FONT_LOGICAL_SCALE 1
51
52
53 CAIRO_BEGIN_DECLS
54
55 typedef struct _cairo_win32_surface {
56 cairo_surface_t base;
57
58 cairo_format_t format;
59
60 HDC dc;
61
62 struct IDirect3DSurface9 *d3d9surface;
63
64 /* We create off-screen surfaces as DIBs or DDBs, based on what we created
65 * originally*/
66 HBITMAP bitmap;
67 cairo_bool_t is_dib;
68
69 /* Used to save the initial 1x1 monochrome bitmap for the DC to
70 * select back into the DC before deleting the DC and our
71 * bitmap. For Windows XP, this doesn't seem to be necessary
72 * ... we can just delete the DC and that automatically unselects
73 * out bitmap. But it's standard practice so apparently is needed
74 * on some versions of Windows.
75 */
76 HBITMAP saved_dc_bitmap;
77
78 cairo_surface_t *image;
79
80 cairo_rectangle_int_t extents;
81
82 /* Initial clip bits
83 * We need these kept around so that we maintain
84 * whatever clip was set on the original DC at creation
85 * time when cairo is asked to reset the surface clip.
86 */
87 cairo_rectangle_int_t clip_rect;
88 HRGN initial_clip_rgn;
89 cairo_bool_t had_simple_clip;
90 cairo_region_t *clip_region;
91
92 /* For path clipping to the printing-surface */
93 cairo_surface_clipper_t clipper;
94
95 /* Surface DC flags */
96 uint32_t flags;
97
98 /* printing surface bits */
99 cairo_paginated_mode_t paginated_mode;
100 cairo_content_t content;
101 cairo_bool_t path_empty;
102 cairo_bool_t has_ctm;
103 cairo_matrix_t ctm;
104 cairo_bool_t has_gdi_ctm;
105 cairo_matrix_t gdi_ctm;
106 HBRUSH brush, old_brush;
107 cairo_scaled_font_subsets_t *font_subsets;
108 } cairo_win32_surface_t;
109
110 /* Surface DC flag values */
111 enum {
112 /* If this is a surface created for printing or not */
113 CAIRO_WIN32_SURFACE_FOR_PRINTING = (1<<0),
114
115 /* Whether the DC is a display DC or not */
116 CAIRO_WIN32_SURFACE_IS_DISPLAY = (1<<1),
117
118 /* Whether we can use BitBlt with this surface */
119 CAIRO_WIN32_SURFACE_CAN_BITBLT = (1<<2),
120
121 /* Whether we can use AlphaBlend with this surface */
122 CAIRO_WIN32_SURFACE_CAN_ALPHABLEND = (1<<3),
123
124 /* Whether we can use StretchBlt with this surface */
125 CAIRO_WIN32_SURFACE_CAN_STRETCHBLT = (1<<4),
126
127 /* Whether we can use StretchDIBits with this surface */
128 CAIRO_WIN32_SURFACE_CAN_STRETCHDIB = (1<<5),
129
130 /* Whether we can use GradientFill rectangles with this surface */
131 CAIRO_WIN32_SURFACE_CAN_RECT_GRADIENT = (1<<6),
132
133 /* Whether we can use the CHECKJPEGFORMAT escape function */
134 CAIRO_WIN32_SURFACE_CAN_CHECK_JPEG = (1<<7),
135
136 /* Whether we can use the CHECKJPEGFORMAT escape function */
137 CAIRO_WIN32_SURFACE_CAN_CHECK_PNG = (1<<8),
138
139 /* if this DDB surface can be converted to a DIB if necessary */
140 CAIRO_WIN32_SURFACE_CAN_CONVERT_TO_DIB = (1<<9),
141 };
142
143 cairo_status_t
144 _cairo_win32_print_gdi_error (const char *context);
145
146 cairo_bool_t
147 _cairo_surface_is_win32 (cairo_surface_t *surface);
148
149 cairo_bool_t
150 _cairo_surface_is_win32_printing (cairo_surface_t *surface);
151
152 cairo_status_t
153 _cairo_win32_surface_finish (void *abstract_surface);
154
155 cairo_bool_t
156 _cairo_win32_surface_get_extents (void *abstract_surface,
157 cairo_rectangle_int_t *rectangle);
158
159 uint32_t
160 _cairo_win32_flags_for_dc (HDC dc);
161
162 cairo_status_t
163 _cairo_win32_surface_set_clip_region (void *abstract_surface,
164 cairo_region_t *region);
165
166 cairo_int_status_t
167 _cairo_win32_surface_show_glyphs_internal (void *surface,
168 cairo_operator_t op,
169 const cairo_pattern_t *source,
170 cairo_glyph_t *glyphs,
171 int num_glyphs,
172 cairo_scaled_font_t *scaled_font,
173 cairo_clip_t *clip,
174 int *remaining_glyphs,
175 cairo_bool_t glyph_indices);
176
177 cairo_int_status_t
178 _cairo_win32_surface_show_glyphs (void *surface,
179 cairo_operator_t op,
180 const cairo_pattern_t *source,
181 cairo_glyph_t *glyphs,
182 int num_glyphs,
183 cairo_scaled_font_t *scaled_font,
184 cairo_clip_t *clip,
185 int *remaining_glyphs);
186
187 cairo_surface_t *
188 _cairo_win32_surface_create_similar (void *abstract_src,
189 cairo_content_t content,
190 int width,
191 int height);
192
193 cairo_status_t
194 _cairo_win32_surface_clone_similar (void *abstract_surface,
195 cairo_surface_t *src,
196 cairo_content_t content,
197 int src_x,
198 int src_y,
199 int width,
200 int height,
201 int *clone_offset_x,
202 int *clone_offset_y,
203 cairo_surface_t **clone_out);
204
205 static inline void
_cairo_matrix_to_win32_xform(const cairo_matrix_t * m,XFORM * xform)206 _cairo_matrix_to_win32_xform (const cairo_matrix_t *m,
207 XFORM *xform)
208 {
209 xform->eM11 = (FLOAT) m->xx;
210 xform->eM21 = (FLOAT) m->xy;
211 xform->eM12 = (FLOAT) m->yx;
212 xform->eM22 = (FLOAT) m->yy;
213 xform->eDx = (FLOAT) m->x0;
214 xform->eDy = (FLOAT) m->y0;
215 }
216
217 cairo_int_status_t
218 _cairo_win32_save_initial_clip (HDC dc, cairo_win32_surface_t *surface);
219
220 cairo_int_status_t
221 _cairo_win32_restore_initial_clip (cairo_win32_surface_t *surface);
222
223 void
224 _cairo_win32_debug_dump_hrgn (HRGN rgn, char *header);
225
226 cairo_bool_t
227 _cairo_win32_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font);
228
229 cairo_bool_t
230 _cairo_win32_scaled_font_is_bitmap (cairo_scaled_font_t *scaled_font);
231
232 #ifdef CAIRO_HAS_DWRITE_FONT
233
234 cairo_int_status_t
235 _cairo_dwrite_show_glyphs_on_surface(void *surface,
236 cairo_operator_t op,
237 const cairo_pattern_t *source,
238 cairo_glyph_t *glyphs,
239 int num_glyphs,
240 cairo_scaled_font_t *scaled_font,
241 cairo_clip_t *clip);
242
243 cairo_int_status_t
244 _cairo_dwrite_scaled_font_create_win32_scaled_font(cairo_scaled_font_t *scaled_font,
245 cairo_scaled_font_t **new_font);
246
247 #endif /* CAIRO_HAS_DWRITE_FONT */
248 CAIRO_END_DECLS
249 #endif /* CAIRO_WIN32_PRIVATE_H */
250