1 commit 857df0583365228150b3319475efc43b22077d06
2 Author: Jeff Muizelaar <jmuizelaar@mozilla.com>
3 Date: Tue Apr 20 15:43:54 2010 -0400
7 diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
8 index df063bf..819e53e 100644
9 --- a/src/cairo-quartz-surface.c
10 +++ b/src/cairo-quartz-surface.c
13 #include "cairo-quartz-private.h"
14 #include "cairo-surface-clipper-private.h"
15 +#include "cairo-gstate-private.h"
16 +#include "cairo-private.h"
20 @@ -3095,6 +3097,61 @@ cairo_quartz_surface_get_cg_context (cairo_surface_t *surface)
21 return quartz->cgContext;
25 +cairo_quartz_get_cg_context_with_clip (cairo_t *cr)
28 + cairo_surface_t *surface = cr->gstate->target;
29 + cairo_clip_t *clip = &cr->gstate->clip;
30 + cairo_status_t status;
32 + cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
34 + if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
38 + if (clip->all_clipped) {
39 + /* Save the state before we set an empty clip rect so that
40 + * our previous clip will be restored */
41 + CGContextSaveGState (quartz->cgContext);
43 + /* _cairo_surface_clipper_set_clip doesn't deal with
44 + * clip->all_clipped because drawing is normally discarded earlier */
45 + CGRect empty = {{0,0}, {0,0}};
46 + CGContextClipToRect (quartz->cgContext, empty);
48 + return quartz->cgContext;
51 + /* an empty clip is represented by NULL */
55 + status = _cairo_surface_clipper_set_clip (&quartz->clipper, clip);
57 + /* Save the state after we set the clip so that it persists
58 + * after we restore */
59 + CGContextSaveGState (quartz->cgContext);
61 + if (unlikely (status))
64 + return quartz->cgContext;
68 +cairo_quartz_finish_cg_context_with_clip (cairo_t *cr)
70 + cairo_surface_t *surface = cr->gstate->target;
72 + cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
74 + if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
77 + CGContextRestoreGState (quartz->cgContext);
82 diff --git a/src/cairo-quartz.h b/src/cairo-quartz.h
83 index e8b71ba..aa1cdd2 100644
84 --- a/src/cairo-quartz.h
85 +++ b/src/cairo-quartz.h
86 @@ -57,6 +57,12 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
87 cairo_public CGContextRef
88 cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
90 +cairo_public CGContextRef
91 +cairo_quartz_get_cg_context_with_clip (cairo_t *cr);
94 +cairo_quartz_finish_cg_context_with_clip (cairo_t *cr);
96 #if CAIRO_HAS_QUARTZ_FONT
99 diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
100 index d4575a3..c10e134 100644
101 --- a/src/cairo-win32-surface.c
102 +++ b/src/cairo-win32-surface.c
104 #include "cairo-win32-private.h"
105 #include "cairo-scaled-font-subsets-private.h"
106 #include "cairo-surface-fallback-private.h"
108 +#include "cairo-surface-clipper-private.h"
109 +#include "cairo-gstate-private.h"
110 +#include "cairo-private.h"
114 @@ -1914,6 +1916,61 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
120 +cairo_win32_get_dc_with_clip (cairo_t *cr)
122 + cairo_surface_t *surface = cr->gstate->target;
124 + _cairo_clip_init_copy(&clip, &cr->gstate->clip);
126 + if (_cairo_surface_is_win32 (surface)){
127 + cairo_win32_surface_t *winsurf = (cairo_win32_surface_t *) surface;
128 + cairo_region_t *clip_region = NULL;
129 + cairo_status_t status;
132 + status = _cairo_clip_get_region (&clip, &clip_region);
133 + assert (status != CAIRO_INT_STATUS_NOTHING_TO_DO);
135 + _cairo_clip_fini(&clip);
139 + _cairo_win32_surface_set_clip_region (winsurf, clip_region);
141 + _cairo_clip_fini(&clip);
142 + return winsurf->dc;
145 + if (_cairo_surface_is_paginated (surface)) {
146 + cairo_surface_t *target;
148 + target = _cairo_paginated_surface_get_target (surface);
150 +#ifndef CAIRO_OMIT_WIN32_PRINTING
151 + if (_cairo_surface_is_win32_printing (target)) {
152 + cairo_status_t status;
153 + cairo_win32_surface_t *winsurf = (cairo_win32_surface_t *) target;
155 + status = _cairo_surface_clipper_set_clip (&winsurf->clipper, &clip);
157 + _cairo_clip_fini(&clip);
162 + return winsurf->dc;
167 + _cairo_clip_fini(&clip);
174 * cairo_win32_surface_get_image
175 * @surface: a #cairo_surface_t
176 diff --git a/src/cairo-win32.h b/src/cairo-win32.h
177 index 7d04d2a..c304f92 100644
178 --- a/src/cairo-win32.h
179 +++ b/src/cairo-win32.h
180 @@ -65,6 +65,9 @@ cairo_win32_surface_create_with_dib (cairo_format_t format,
182 cairo_win32_surface_get_dc (cairo_surface_t *surface);
185 +cairo_win32_get_dc_with_clip (cairo_t *cr);
187 cairo_public cairo_surface_t *
188 cairo_win32_surface_get_image (cairo_surface_t *surface);