[cairo] Re: How to use clipping?

Sebastien Lemieux lemieuxs at iro.umontreal.ca
Tue Aug 3 10:47:54 PDT 2004

Hi Carl,

  Thanks for the fast reply!  I guess I'm still missing something, here is 
a sample of code I wrote (the none cairo_ calls are just wrappers in the 
object class and all work is done on the cairo_t *mImage):

  cairo_new_path (mImage);
  move_to (mView_min_x + 10, mView_min_y + 10);
  line_to (mView_min_x + 10, mView_max_y - 10);
  line_to (mView_max_x - 10, mView_max_y - 10);
  line_to (mView_max_x - 10, mView_min_y + 10);
  line_to (mView_min_x + 10, mView_min_y + 10);
  cairo_close_path (mImage); 

  cairo_clip (mImage);

  move_to (mView_min_x, mView_min_y);
  line_to (mView_max_x, mView_max_y);
  set_line_width (1.0);
  set_rgb_color (0, 0, 0);
  stroke ();

I've included the resulting image as a png where we can see that the 
diagonal line is drawn both within and beyond the clipping region.  The 
last stroke() draws both the clipping rectangle and the diagonal line.


On Tue, 3 Aug 2004, Carl Worth wrote:

> Within the cairo graphics state, there is a notion of a current clipping
> path. Initially, this path is infinitely large, (eg. no clipping is
> performed).
> Calling cairo_clip computes a new clipping path by intersecting the
> current clipping path with the current path, (ie. the path formed with
> things like cairo_move_to/line_to/curve_to). After that, the effect of
> all subsequent drawing operations will be restricted to the area within
> the current clipping path.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.png
Type: image/png
Size: 4683 bytes
Url : http://lists.freedesktop.org/archives/cairo/attachments/20040803/3aa6aeaa/test.png

More information about the cairo mailing list