[cairo] Help for using cairo_region and clip

Carlos López González genetita at gmail.com
Wed Oct 10 03:03:35 PDT 2012

Hi Adhir,
According to the manual:
"Regions are a simple graphical data type representing an area of
integer-aligned rectangles. They are often used on raster surfaces to
track areas of interest, such as change or clip areas."


"cairo_clip ()
void   cairo_clip (cairo_t *cr);

Establishes a new clip region by intersecting the current clip region
with the current path as it would be filled by cairo_fill() and
according to the current fill rule (see cairo_set_fill_rule())."

Do not confuse the "region" word from the cairo_clip description with
the cairo_region_t type. They are pretty different.  The first is like
a path and the second is a pixel aligned rectangle. In general paths
can be of any kind (arcs, strokes, rectangles).

So if you want to clip your path with a rectangle, just use a
rectangle path as clipping path

/* prepare your context and surface here*/
cairo_rectangle(cr, x, y, width, height);
/* add more paths here to the clip*/
/*your stroke painting stuff here*/
cairo_move_to, cairo_line_to, etc.


I hope it helped.

2012/10/10 Adhir Garg <adhir.garg at gmail.com>
> Hello,
> I am pretty new to Cairo and have a query regarding use of
> cairo_region_t and clip.
> What I need is
> 1. Create a region - created using cairo_region_create_rectangle
> 2. Create a Path and clip it with region - Here if I use cairo_clip(),
> then the region is not taken into consideration.
> Somehow, I couldn't locate correct API for intersection of region with clip.
> On extended platforms I could get set_clip_region, but could not find
> the same in Cairo listed APIs.
> Thanks in advance for your help.
> Regards,
> Adhir
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list