[cairo] set a reverse clip

Wed Sep 9 23:18:17 PDT 2009

```Thanks carl. i found the the solution in the mailing list using
WINDING/EVEN_ODD with A and C (intersect of A and B), for that i had to
compute the intersect rect C. with the two clips suggested, computing C
would not be required.

>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.
This and the documentation on the fill rule behavior ("The ray can be in any
direction, as long as it doesn't pass through the end point of a segment or
have a tricky intersection such as intersecting tangent to the path.")
requires some graphics theory to understand it. I cant at this moment.

thanks,
Zaheer

On Wed, Sep 9, 2009 at 10:33 PM, Carl Worth <cworth at cworth.org> wrote:

> 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.
>
>
>        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 --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20090910/16f71ce4/attachment.html
```