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 32
51 
52 typedef struct _cairo_win32_surface {
53     cairo_surface_t base;
54 
55     cairo_format_t format;
56 
57     HDC dc;
58 
59     /* We create off-screen surfaces as DIBs or DDBs, based on what we created
60      * originally*/
61     HBITMAP bitmap;
62     cairo_bool_t is_dib;
63 
64     /* Used to save the initial 1x1 monochrome bitmap for the DC to
65      * select back into the DC before deleting the DC and our
66      * bitmap. For Windows XP, this doesn't seem to be necessary
67      * ... we can just delete the DC and that automatically unselects
68      * out bitmap. But it's standard practice so apparently is needed
69      * on some versions of Windows.
70      */
71     HBITMAP saved_dc_bitmap;
72 
73     cairo_surface_t *image;
74 
75     cairo_rectangle_int_t extents;
76 
77     /* Initial clip bits
78      * We need these kept around so that we maintain
79      * whatever clip was set on the original DC at creation
80      * time when cairo is asked to reset the surface clip.
81      */
82     cairo_rectangle_int_t clip_rect;
83     HRGN initial_clip_rgn;
84     cairo_bool_t had_simple_clip;
85     cairo_region_t *clip_region;
86 
87     /* For path clipping to the printing-surface */
88     cairo_surface_clipper_t clipper;
89 
90     /* Surface DC flags */
91     uint32_t flags;
92 
93     /* printing surface bits */
94     cairo_paginated_mode_t paginated_mode;
95     cairo_content_t content;
96     cairo_bool_t path_empty;
97     cairo_bool_t has_ctm;
98     cairo_matrix_t ctm;
99     cairo_bool_t has_gdi_ctm;
100     cairo_matrix_t gdi_ctm;
101     HBRUSH brush, old_brush;
102     cairo_scaled_font_subsets_t *font_subsets;
103 } cairo_win32_surface_t;
104 
105 /* Surface DC flag values */
106 enum {
107     /* If this is a surface created for printing or not */
108     CAIRO_WIN32_SURFACE_FOR_PRINTING = (1<<0),
109 
110     /* Whether the DC is a display DC or not */
111     CAIRO_WIN32_SURFACE_IS_DISPLAY = (1<<1),
112 
113     /* Whether we can use BitBlt with this surface */
114     CAIRO_WIN32_SURFACE_CAN_BITBLT = (1<<2),
115 
116     /* Whether we can use AlphaBlend with this surface */
117     CAIRO_WIN32_SURFACE_CAN_ALPHABLEND = (1<<3),
118 
119     /* Whether we can use StretchBlt with this surface */
120     CAIRO_WIN32_SURFACE_CAN_STRETCHBLT = (1<<4),
121 
122     /* Whether we can use StretchDIBits with this surface */
123     CAIRO_WIN32_SURFACE_CAN_STRETCHDIB = (1<<5),
124 
125     /* Whether we can use GradientFill rectangles with this surface */
126     CAIRO_WIN32_SURFACE_CAN_RECT_GRADIENT = (1<<6),
127 
128     /* Whether we can use the CHECKJPEGFORMAT escape function */
129     CAIRO_WIN32_SURFACE_CAN_CHECK_JPEG = (1<<7),
130 
131     /* Whether we can use the CHECKJPEGFORMAT escape function */
132     CAIRO_WIN32_SURFACE_CAN_CHECK_PNG = (1<<8),
133 };
134 
135 cairo_status_t
136 _cairo_win32_print_gdi_error (const char *context);
137 
138 cairo_bool_t
139 _cairo_surface_is_win32 (cairo_surface_t *surface);
140 
141 cairo_bool_t
142 _cairo_surface_is_win32_printing (cairo_surface_t *surface);
143 
144 cairo_status_t
145 _cairo_win32_surface_finish (void *abstract_surface);
146 
147 cairo_bool_t
148 _cairo_win32_surface_get_extents (void		          *abstract_surface,
149 				  cairo_rectangle_int_t   *rectangle);
150 
151 uint32_t
152 _cairo_win32_flags_for_dc (HDC dc);
153 
154 cairo_status_t
155 _cairo_win32_surface_set_clip_region (void           *abstract_surface,
156 				      cairo_region_t *region);
157 
158 cairo_int_status_t
159 _cairo_win32_surface_show_glyphs (void			*surface,
160 				  cairo_operator_t	 op,
161 				  const cairo_pattern_t	*source,
162 				  cairo_glyph_t		*glyphs,
163 				  int			 num_glyphs,
164 				  cairo_scaled_font_t	*scaled_font,
165 				  cairo_clip_t		*clip,
166 				  int			*remaining_glyphs);
167 
168 cairo_surface_t *
169 _cairo_win32_surface_create_similar (void	    *abstract_src,
170 				     cairo_content_t content,
171 				     int	     width,
172 				     int	     height);
173 
174 cairo_status_t
175 _cairo_win32_surface_clone_similar (void *abstract_surface,
176 				    cairo_surface_t *src,
177 				    cairo_content_t content,
178 				    int src_x,
179 				    int src_y,
180 				    int width,
181 				    int height,
182 				    int *clone_offset_x,
183 				    int *clone_offset_y,
184 				    cairo_surface_t **clone_out);
185 
186 static inline void
_cairo_matrix_to_win32_xform(const cairo_matrix_t * m,XFORM * xform)187 _cairo_matrix_to_win32_xform (const cairo_matrix_t *m,
188                               XFORM *xform)
189 {
190     xform->eM11 = (FLOAT) m->xx;
191     xform->eM21 = (FLOAT) m->xy;
192     xform->eM12 = (FLOAT) m->yx;
193     xform->eM22 = (FLOAT) m->yy;
194     xform->eDx = (FLOAT) m->x0;
195     xform->eDy = (FLOAT) m->y0;
196 }
197 
198 cairo_int_status_t
199 _cairo_win32_save_initial_clip (HDC dc, cairo_win32_surface_t *surface);
200 
201 cairo_int_status_t
202 _cairo_win32_restore_initial_clip (cairo_win32_surface_t *surface);
203 
204 void
205 _cairo_win32_debug_dump_hrgn (HRGN rgn, char *header);
206 
207 cairo_bool_t
208 _cairo_win32_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font);
209 
210 cairo_bool_t
211 _cairo_win32_scaled_font_is_bitmap (cairo_scaled_font_t *scaled_font);
212 
213 #endif /* CAIRO_WIN32_PRIVATE_H */
214