[cairo] set a reverse clip

Carl Worth cworth at cworth.org
Wed Sep 9 10:03:33 PDT 2009


Excerpts from zaheer ahmad's message of Tue Sep 08 00:18:20 -0700 2009:
> hi,

Hi Zaheer!

> i have two rectangles A and B that may or may not intersect. If they do
> intersect (lets say C), i would like a cairo clip on A such that only C is
> masked out from the drawing and the rest of A gets drawn. how can i do that.
> i dont seem to find a reverse of cairo_clip, something like
> cairo_set_source_surface(A), cairo_rev_clip(B). Appreciate any pointers.

This is possible to do, but it takes a couple of calls to cairo_clip,
(at least the way I've come up with so far).

The first thing to understand is that cairo_clip respects the fill
rule[*] as set by cairo_set_fill_rule. The default FILL_RULE_WINDING
means that you can make one rectangle "subtract" from another by
defining it in the opposite direction as the other.

So you might start with the following:

	cairo_rectangle (cr, A.x, A.y, A.width, A.height);
	cairo_rectangle (cr, B.x + B.width, B.y, - B.width, B.height);
	cairo_clip (cr);

Note that the B rectange is carefully constructed to wind in the
opposite direction as the A rectangle. The result of the above is that
all drawing will be clipped to the union of A and B but with the
intersection C masked out, just as you want.

What you don't want, though, (as I understand the question), is for
the drawing to also appear within B. So you can follow the above with
a straightforward clip to A:

	cairo_rectangle (cr, A.x, A.y, A.width, A.height);
	cairo_clip (cr);

and hopefully you know have exactly what you want.

I hope that helps. Please let us know if you need anything more, and
have fun with cairo!

-Carl

[*] http://cairographics.org/manual/cairo-context.html#cairo-fill-rule-t
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20090909/f0d55601/attachment.pgp 


More information about the cairo mailing list