[cairo] Help for using cairo_region and clip
Carlos López González
genetita at gmail.com
Wed Oct 10 04:04:15 PDT 2012
2012/10/10 Adhir Garg <adhir.garg at gmail.com>:
> 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 -
> 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
Can you be more explicit with this code? Please paste the code that
currently you build and run to check that it doesn't do what you want.
I think that you cannot subtract a cairo_region_t from a path or
viceversa. Cairo regions are for raster surfaces (where those integers
coincide with pixels) but in general a rectangle represents pixels or
not, depending on the surface that the cairo context was initialized.
> 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.
Possibly you don't need to use cairo_region_t at all, and just work
with paths and clips.
> 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.
Does this help?
> 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."
>> "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>
>>> 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.
>>> cairo mailing list
>>> cairo at cairographics.org
More information about the cairo