[cairo] Unsymmetrical rotation
Bill Spitzak
spitzak at gmail.com
Tue Mar 5 12:05:52 PST 2013
On 03/04/2013 11:15 PM, Carlos López González wrote:
> Hi Blagoj,
> I don't think it is a bug I think that you need to do one extra step:
> If alpha is the angle (ccw), origin is the rotation center (in device
> units) and w,h are the final image dimensions you have to do this:
>
> cairo_translate(cr, origin.x, origin.y);
>
> cairo_rotate(cr, -1.0*angle);
>
> cairo_translate(cr, -origin.x, -origin.y);
>
> cairo_set_source_surface(cr, source, x, y);
>
> where x and y are the result of the minimum x and minimum y of the
> clockwise rotated corners
> of the source surface top_left(0,0), top_right(w, 0), bottom_left(0, h)
> and bottom_right(w, h).
So you are saying the xy arguments for cairo_set_source_surface are the
location to put the top-left corner of the bounding box of the
transformed image? That's totally useless and very hard to believe! The
only way to get a predictable result is for both Cairo and the caller to
do the exact same bounding box calculation, thus they both have to do
the transform?
I'm pretty certain the xy cause a translation from some location that
Cairo considers "natural" and that it is either in the source surface
space (that might be useful) or in the CTM (in which case another
cairo_translate would do the same thing). I know I have gotten correct
transforms out of Cairo, though it is not easy. I think this was done by
passing 0,0 for the x,y.
More information about the cairo
mailing list