Tizen 2.0 Release
[framework/graphics/cairo.git] / src / win32 / cairo-win32-private.h
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
41 #include "cairoint.h"
42
43 #include "cairo-device-private.h"
44 #include "cairo-surface-clipper-private.h"
45 #include "cairo-surface-private.h"
46
47 #ifndef SHADEBLENDCAPS
48 #define SHADEBLENDCAPS 120
49 #endif
50 #ifndef SB_NONE
51 #define SB_NONE 0
52 #endif
53
54 #define WIN32_FONT_LOGICAL_SCALE 32
55
56 /* Surface DC flag values */
57 enum {
58     /* If this is a surface created for printing or not */
59     CAIRO_WIN32_SURFACE_FOR_PRINTING = (1<<0),
60
61     /* Whether the DC is a display DC or not */
62     CAIRO_WIN32_SURFACE_IS_DISPLAY = (1<<1),
63
64     /* Whether we can use BitBlt with this surface */
65     CAIRO_WIN32_SURFACE_CAN_BITBLT = (1<<2),
66
67     /* Whether we can use AlphaBlend with this surface */
68     CAIRO_WIN32_SURFACE_CAN_ALPHABLEND = (1<<3),
69
70     /* Whether we can use StretchBlt with this surface */
71     CAIRO_WIN32_SURFACE_CAN_STRETCHBLT = (1<<4),
72
73     /* Whether we can use StretchDIBits with this surface */
74     CAIRO_WIN32_SURFACE_CAN_STRETCHDIB = (1<<5),
75
76     /* Whether we can use GradientFill rectangles with this surface */
77     CAIRO_WIN32_SURFACE_CAN_RECT_GRADIENT = (1<<6),
78
79     /* Whether we can use the CHECKJPEGFORMAT escape function */
80     CAIRO_WIN32_SURFACE_CAN_CHECK_JPEG = (1<<7),
81
82     /* Whether we can use the CHECKJPEGFORMAT escape function */
83     CAIRO_WIN32_SURFACE_CAN_CHECK_PNG = (1<<8),
84 };
85
86 typedef struct _cairo_win32_surface {
87     cairo_surface_t base;
88
89     cairo_format_t format;
90     HDC dc;
91
92     /* Surface DC flags */
93     unsigned flags;
94
95     /* We use the x and y parts of extents for situations where
96      * we're not supposed to draw to the entire surface.
97      * For example, during a paint event a program will get
98      * a DC that has been clipped to the dirty region.
99      * A cairo surface constructed for that DC will have extents
100      * that match bounds of the clipped region.
101      */
102     cairo_rectangle_int_t extents;
103 } cairo_win32_surface_t;
104 #define to_win32_surface(S) ((cairo_win32_surface_t *)(S))
105
106 typedef struct _cairo_win32_display_surface {
107     cairo_win32_surface_t win32;
108
109     /* We create off-screen surfaces as DIBs or DDBs, based on what we created
110      * originally*/
111     HBITMAP bitmap;
112     cairo_bool_t is_dib;
113
114     /* Used to save the initial 1x1 monochrome bitmap for the DC to
115      * select back into the DC before deleting the DC and our
116      * bitmap. For Windows XP, this doesn't seem to be necessary
117      * ... we can just delete the DC and that automatically unselects
118      * out bitmap. But it's standard practice so apparently is needed
119      * on some versions of Windows.
120      */
121     HBITMAP saved_dc_bitmap;
122     cairo_surface_t *image;
123     cairo_surface_t *fallback;
124
125     HRGN initial_clip_rgn;
126     cairo_bool_t had_simple_clip;
127 } cairo_win32_display_surface_t;
128 #define to_win32_display_surface(S) ((cairo_win32_display_surface_t *)(S))
129
130 typedef struct _cairo_win32_printing_surface {
131     cairo_win32_surface_t win32;
132
133     cairo_surface_clipper_t clipper;
134
135     cairo_paginated_mode_t paginated_mode;
136     cairo_content_t content;
137     cairo_bool_t path_empty;
138     cairo_bool_t has_ctm;
139     cairo_matrix_t ctm;
140     cairo_bool_t has_gdi_ctm;
141     cairo_matrix_t gdi_ctm;
142     HBRUSH brush, old_brush;
143     cairo_scaled_font_subsets_t *font_subsets;
144 } cairo_win32_printing_surface_t;
145 #define to_win32_printing_surface(S) ((cairo_win32_printing_surface_t *)(S))
146
147 typedef BOOL (WINAPI *cairo_win32_alpha_blend_func_t) (HDC hdcDest,
148                                                        int nXOriginDest,
149                                                        int nYOriginDest,
150                                                        int nWidthDest,
151                                                        int hHeightDest,
152                                                        HDC hdcSrc,
153                                                        int nXOriginSrc,
154                                                        int nYOriginSrc,
155                                                        int nWidthSrc,
156                                                        int nHeightSrc,
157                                                        BLENDFUNCTION blendFunction);
158
159 typedef struct _cairo_win32_device {
160     cairo_device_t base;
161
162     HMODULE msimg32_dll;
163
164     const cairo_compositor_t *compositor;
165
166     cairo_win32_alpha_blend_func_t alpha_blend;
167 } cairo_win32_device_t;
168 #define to_win32_device(D) ((cairo_win32_device_t *)(D))
169 #define to_win32_device_from_surface(S) to_win32_device(((cairo_surface_t *)(S))->device)
170
171 cairo_private cairo_device_t *
172 _cairo_win32_device_get (void);
173
174 const cairo_compositor_t *
175 _cairo_win32_gdi_compositor_get (void);
176
177 cairo_status_t
178 _cairo_win32_print_gdi_error (const char *context);
179
180 cairo_private void
181 _cairo_win32_display_surface_discard_fallback (cairo_win32_display_surface_t *surface);
182
183 cairo_bool_t
184 _cairo_win32_surface_get_extents (void                    *abstract_surface,
185                                   cairo_rectangle_int_t   *rectangle);
186
187 uint32_t
188 _cairo_win32_flags_for_dc (HDC dc);
189
190 cairo_int_status_t
191 _cairo_win32_surface_emit_glyphs (cairo_win32_surface_t *dst,
192                                   const cairo_pattern_t *source,
193                                   cairo_glyph_t  *glyphs,
194                                   int                     num_glyphs,
195                                   cairo_scaled_font_t    *scaled_font,
196                                   cairo_bool_t            glyph_indexing);
197
198 static inline void
199 _cairo_matrix_to_win32_xform (const cairo_matrix_t *m,
200                               XFORM *xform)
201 {
202     xform->eM11 = (FLOAT) m->xx;
203     xform->eM21 = (FLOAT) m->xy;
204     xform->eM12 = (FLOAT) m->yx;
205     xform->eM22 = (FLOAT) m->yy;
206     xform->eDx = (FLOAT) m->x0;
207     xform->eDy = (FLOAT) m->y0;
208 }
209
210 cairo_status_t
211 _cairo_win32_display_surface_set_clip (cairo_win32_display_surface_t *surface,
212                                        cairo_clip_t *clip);
213
214 void
215 _cairo_win32_display_surface_unset_clip (cairo_win32_display_surface_t *surface);
216
217 void
218 _cairo_win32_debug_dump_hrgn (HRGN rgn, char *header);
219
220 cairo_bool_t
221 _cairo_win32_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font);
222
223 cairo_bool_t
224 _cairo_win32_scaled_font_is_bitmap (cairo_scaled_font_t *scaled_font);
225
226 #endif /* CAIRO_WIN32_PRIVATE_H */