[cairo] Help for using cairo_region and clip

Adhir Garg adhir.garg at gmail.com
Wed Oct 10 03:20:46 PDT 2012


Hello Carlos,

Thanks for your time for replying.

However, the question still remains unanswered. I am trying to explain
problem in following steps

1. Create a big, filled Rectangle 1000x1000 - cairo_rectangle (cr, 0,
0, 1000, 1000);
2. Create a BIG Rectangle Region 100x100  using
cairo_region_create_rectangle(cr, rectangle*);
3. Exclude a part (region) of it using subtract -
cairo_region_subtract_rectangle
Now I assume that my Region consists of reduced size < 100X100
4. I try to create with another shape (say Rectangle) -  cairo_rectangle
5. If I do cairo_clip(), I only get the rectangle of Step 4

My final expected output is intersection of Region at (3) and Clip in (4).
However, I am unable to find any API that makes use of cairo_region_t.

Prior to 1.10.0, we had API set_clip_region(), This was responsible
for setting the current clip region to current region.

In case, we have such API, where we are actually making use of
cairo_region, it would be great.

Regards,
Adhir

On Wed, Oct 10, 2012 at 3:33 PM, Carlos López González
<genetita at gmail.com> wrote:
> 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."
>
> Also:
>
> "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*/
> cairo_clip(cr);
> /*your stroke painting stuff here*/
> cairo_move_to, cairo_line_to, etc.
>
> See:
> http://cairographics.org/samples/clip/
>
> I hope it helped.
> Carlos
>
> 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
>
>
>
>
> --
> Carlos
> http://synfig.org


More information about the cairo mailing list