[cairo] Unsymmetrical rotation

Blagoj Kupev bkupev at gmail.com
Tue Mar 5 13:24:43 PST 2013


Hello,
I might have problems describing what i'm trying to achieve, so let my try
to explain it using some graphics. What i need to do is to place a gauge
instrument at display that i'd like to rotate according to the input value.
So i'm using a simple png image:
+-------+
|---o    |
+-------+
image 1

The image 1 is with size of 100x100 pixels. Please note that the corners
are invisible, so only the arrow is visible. What i'd like to achieve is to
put it on window with size of 640x320 (fixed size) on bottom middle part of
the window. When i tried to do this I'm noticing that the arrow image is
not placed always at same place and the placement is dependent of the
rotation angle.
It seem that regardless of the placement of the origin of the image prior
and after the rotation, cairo is using original image when
cairo_set_source_surface is applied.

This would mean that when the rotation is applied, the second
cairo_transform is still calculated according to the original image and
then the offset will be according to top-left corner of the original image.

So now I'm wondering is there a simple method to rotate and place the
original image at predefined offsets in the window or i should make complex
CTM that will do this?

Thanks,
Blagoj

On Tue, Mar 5, 2013 at 9:05 PM, Bill Spitzak <spitzak at gmail.com> wrote:

> 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.
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.**org/mailman/listinfo/cairo<http://lists.cairographics.org/mailman/listinfo/cairo>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130305/98b075d9/attachment.html>


More information about the cairo mailing list