[cairo] cairo_stroke_extents() with transformation matrix
chris at chris-wilson.co.uk
Mon Feb 1 08:56:41 PST 2010
On Mon, 01 Feb 2010 17:35:25 +0100, "Andreas Falkenhahn" <andreas at airsoftsoftwair.de> wrote:
> how can I get cairo_stroke_extents() to take the current transformation matrix
> into account? I.e. please consider the following code:
> // scale * 2 on both axes
> cairo_matrix_init(&m, 2, 0, 0, 2, 0, 0);
> cairo_set_matrix(cr, &m);
> cairo_rectangle(cr, 0, 0, 320, 240);
> cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
> I'd expect that cairo_stroke_extents() would return something in the range
> of roughly 640 for x2 and roughly 480 for y2. Instead, it simply returns about
> 320 for x2 and about 240 for y2-- just as if there was no transformation at all.
> Is there a way to get cairo_stroke_extents() take the current transformation
> matrix into account?
Ab, but it is. It is transforming the extents of the path from device to
user space using the current transformation matrix. For your purposes, you
actually want to know the device extents, and so should set an identity
transformation when querying the extents.
cairo_scale(cr, 2, 2);
cairo_rectangle(cr, 0, 0, 320, 240);
cairo_stroke_extents(cr, &x1, &y1, &x2, &y2);
Hope this helps, and you have fun using Cairo!
Chris Wilson, Intel Open Source Technology Centre
More information about the cairo