[cairo] 2 clipping questions

Behdad Esfahbod behdad at behdad.org
Wed Apr 25 23:56:44 PDT 2007

On Thu, 2007-04-26 at 02:26 -0400, Tim Teulings wrote:
> Hallo!
> Two questions regarding clipping:
> 1.
> In my GUI library I make use of subtracting clipping. This means, that
> if I have a drawing area of 1000x1000 I can define a clipping region of
> example 200,200-800,800 and then define an subtracting clipping region
> of 400,400-600,600. If I now fill the entire drawing region I get
> rectangular ring. This is help if you have a hierarchical gadget
> structure and want the parent gadget to fill its background without
> drawing into the region of its children (this could be worked around of
> course by doing multiple manual partial drawing around the children but
> using clipping makes things of course simpler).
> Subtractive clipping seams to be available for all major drawing systems
> (X11, Win32, Mac OS X) but not for cairo. Is this true? Are there plans
> to change this?

I think cairo supports this too.  Try adding the inner rectangle with a
reverse winding.  That is, instead of 400,400-600,600, use
400,600-600,400.  That *should* subtract.  Not sure if it works that way

> 2.
> Recently I started to support Gtk theming. For this I directly copy
> image data from a pixmap into a cairo surface using XCopyArea. It seams
> however that if I directly access the OS drawable in this way the
> clipping defined on the cairo level for this surface is not honored. Is
> this possible?

Of course.  Is this surprising?

> Is there an easy workaround for this?

Use cairo surfaces.  You can create a cairo surface for your native
surface very easily.  Using cairo_xlib_surface_create() for example.

> Must I fall back to
> reading the clipping rectangles from cairo and manually apply them on
> the X11 level using X11 clipping functions

You can do that too.  cairo_copy_clip_rectangle_list() was added to
cairo 1.4 for purposes similar to this.

>  (the other solution would be
> to make sure that source and target are cairo surfaces and do the
> copying on the cairo level).

Yes.  That's what you normally do.  Any reason to avoid that?


"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759

More information about the cairo mailing list