[cairo] Cryptic clips

Carl Worth cworth at cworth.org
Fri Nov 30 09:55:04 PST 2007


On Fri, 30 Nov 2007 19:10:09 +0200,Donn wrote:
> 1 matrix [set translate, rotate and scale]
> 2 draw clip shape
> 3 save()
> 4 clip()
> 5   matrix [set translate, rotate and scale]
> 6   draw shape 1
> 7   matrix [set translate, rotate and scale]
> 8   draw shape 2
> 9 restore()
...
> I tried inserting indentity_matrix() after line 4, but that just disappears
> both shapes.

The cairo_identity_matrix call is a pretty big hammer, and often not
appropriate. You don't show it in the above example, but if you also
have other transformations outside the code above that *should* be in
effect, then your call to identity_matrix would undo those.

Instead, the simplest way to make a temporary alteration to the
transformation matrix is with cairo_save and cairo_restore. So you
should be able to just add those two lines to your example:

+	cairo_save

	set up matrix for clip shape
	create path for clip shape

+	cairo_restore

	cairo_save
	    cairo_clip
	    setup matrix for shape 1
	    draw shape 1
	    setup matrix for shape 2
	    draw shape 2
	cairo_restore

I don't know what your code actually looks like, but you might find
that you can have "draw_shape" functions that setup the matrix for the
shape and draw it, and internally are entirely wrapped with cairo_save
and cairo_restore. That's often a very convenient approach to take.

And note that the path is *not* affected by cairo_save and
cairo_restore. This allows you to write "path creating" functions that
have the typical, internal cairo_save/cairo_restore to temporarily
modify the transformation matrix, but can still modify the current
path.

I hope that helps. If not, please feel free to ask again with more
details.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071130/608f8fac/attachment.pgp 


More information about the cairo mailing list