<div dir="ltr"><div><div><div>Hi Blagoj,<br></div>I don't think it is a bug I think that you need to do one extra step:<br></div>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:<br>
</div><pre><div class="" id="LC429"><span class="">cairo_translate</span><span class="">(</span><span class="">cr</span><span class="">,</span> origin.x<span class="">,</span> origin.y<span class=""></span><span class="">);</span></div>
<div class="" id="LC430"><span class="">cairo_rotate</span><span class="">(</span><span class="">cr</span><span class="">,</span> <span class="">-</span><span class="">1.0</span><span class="">*</span><span class="">angle</span><span class="">);</span></div>
<div class="" id="LC431"><span class="">cairo_translate</span><span class="">(</span><span class="">cr</span><span class="">,</span> <span class="">-</span><span class="">origin.x</span><span class=""></span><span class="">,</span> <span class="">-</span><span class="">origin.y</span><span class=""></span><span class="">);</span></div>
<div class="" id="LC432"><span class="">cairo_set_source_surface</span><span class="">(</span><span class="">cr</span><span class="">,</span> <span class="">source</span><span class="">,</span> x<span class=""></span><span class=""></span><span class="">,</span> y<span class=""></span><span class="">);<br>
<br></span></div><div class="" id="LC432"><span style="font-family:arial,helvetica,sans-serif"><span class="">where x and y are the result of the minimum x and minimum y of the clockwise rotated corners <br>of the source surface top_left(0,0), top_right(w, 0), bottom_left(0, h) and bottom_right(w, h). <br>
This rotation has to be performed at origin of course.<br><br></span></span></div><div class="" id="LC432"><span style="font-family:arial,helvetica,sans-serif"><span class="">In your case it worked fine when offsets are zero but when offset is not zero you have to undo the <br>
rotation of the offset first before apply it.<br></span></span></div><div class="" id="LC432"><span style="font-family:arial,helvetica,sans-serif"><span class=""><br></span></span></div><div class="" id="LC432"><span class=""><span style="font-family:arial,helvetica,sans-serif">See one example code here:</span><br>
<a href="https://github.com/synfig/synfig/blob/genete_new_cairo_core_2/synfig-core/src/modules/lyr_std/rotate.cpp#L428">https://github.com/synfig/synfig/blob/genete_new_cairo_core_2/synfig-core/src/modules/lyr_std/rotate.cpp#L428</a><br>
</span></div><div class="" id="LC432"><span class=""><span style="font-family:arial,helvetica,sans-serif">Notice that in the sample code there is one extra scale operation from user units to device units.<br><br></span></span></div>
<div class="" id="LC432"><span class=""><span style="font-family:arial,helvetica,sans-serif">I hope it helped.<br></span></span></div><div class="" id="LC432"><span class=""><span style="font-family:arial,helvetica,sans-serif">Carlos<br>
</span></span></div></pre><div class="gmail_extra"><br><br><div class="gmail_quote">2013/3/4 Blagoj Kupev <span dir="ltr"><<a href="mailto:bkupev@gmail.com" target="_blank">bkupev@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>Does anyone else have any other idea? Can this be a bug in cairo?<br>Best regards,<br>Blagoj<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On Sun, Mar 3, 2013 at 9:59 PM, Blagoj Kupev <span dir="ltr"><<a href="mailto:bkupev@gmail.com" target="_blank">bkupev@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><img alt=""></div><div>Hello,<br>Already
tried, and does not work... as i can understand the documentation the
functions cairo_translate and cairo_rotate only modify the current
transformation matrix and then the transformation is applied when the
function cairo_set_source_surface is called. Then as i understand,
cairo_set_source_surface is doing additional matrix transformation with
the x and y offsets prior the matrix is executed. <br>
<br></div>It seems that:<div><div><br> cairo_translate (cr, x_origin, y_origin);<br>
cairo_rotate (cr, (2*3.14*angle/360));<br></div></div><div>
cairo_set_source_surface(cr, surf1, x, y);<br><br>Is the same as:</div><div><br><div>
cairo_translate (cr, x_origin, y_origin);<br>
cairo_rotate (cr, (2*3.14*angle/360));<br></div></div><div>
cairo_translate (cr, x, y);<br> cairo_set_source_surface(cr, surf1, 0, 0);<br>
<br>Thanks,<br>Blagoj<br><br></div><div class="gmail_quote"><div>On Sun, Mar 3, 2013 at 9:37 PM, Bill Spitzak <span dir="ltr"><<a href="mailto:spitzak@gmail.com" target="_blank">spitzak@gmail.com</a>></span> wrote:<br>
</div><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On 03/03/2013 06:33 AM, Blagoj Kupev wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
cairo_translate (cr, x_origin, y_origin);<br>
cairo_rotate (cr, (2*3.14*angle/360));<br>
<br>
cairo_set_source_surface(cr, surf1, -x_origin+x_offset, -y_origin);<br>
cairo_paint(cr);<br>
</blockquote>
<br></div>
I think this will work:<div><br>
<br>
cairo_translate (cr, x_origin, y_origin);<br>
cairo_rotate (cr, (2*3.14*angle/360));<br></div>
cairo_translate (cr, x_offset, 0);<br>
cairo_set_source_surface(cr, surf1, -x_origin, -y_origin);<span><font color="#888888"><br>
<br>
-- <br>
cairo mailing list<br>
<a href="mailto:cairo@cairographics.org" target="_blank">cairo@cairographics.org</a><br>
<a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.<u></u>org/mailman/listinfo/cairo</a><br>
</font></span></blockquote></div></div></div><br>
</blockquote></div><br>
</div></div><br>--<br>
cairo mailing list<br>
<a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
<a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br></blockquote></div><br><br clear="all"><br>-- <br>Carlos<br><a href="http://synfig.org" target="_blank">http://synfig.org</a><br>
</div></div>