Skip to content
Permalink
Browse files

[composer] Fix calculation of rotated image size inside picture items…

… when rotation is 90 or 270 degrees
  • Loading branch information
nyalldawson committed Jul 19, 2014
1 parent 904443f commit 2d427a4ece131af8f9a7ed51aa79de78a4612dc9
Showing with 15 additions and 6 deletions.
  1. +15 −6 src/core/composer/qgscomposeritem.cpp
@@ -891,26 +891,35 @@ QRectF QgsComposerItem::largestRotatedRectWithinBounds( QRectF originalRect, QRe
double boundsHeight = boundsRect.height();
double ratioBoundsRect = boundsWidth / boundsHeight;

double clippedRotation = fmod( rotation, 360.0 );

//shortcut for some rotation values
if ( rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270 )
if ( clippedRotation == 0 || clippedRotation == 90 || clippedRotation == 180 || clippedRotation == 270 )
{
double originalRatio = originalWidth / originalHeight;
double rectScale = originalRatio > ratioBoundsRect ? boundsWidth / originalWidth : boundsHeight / originalHeight;
double rectScale;
if ( clippedRotation == 0 || clippedRotation == 180 )
{
rectScale = (( originalWidth / originalHeight ) > ratioBoundsRect ) ? boundsWidth / originalWidth : boundsHeight / originalHeight;
}
else
{
rectScale = (( originalHeight / originalWidth ) > ratioBoundsRect ) ? boundsWidth / originalHeight : boundsHeight / originalWidth;
}
double rectScaledWidth = rectScale * originalWidth;
double rectScaledHeight = rectScale * originalHeight;

if ( rotation == 0 || rotation == 180 )
if ( clippedRotation == 0 || clippedRotation == 180 )
{
return QRectF(( boundsWidth - rectScaledWidth ) / 2.0, ( boundsHeight - rectScaledHeight ) / 2.0, rectScaledWidth, rectScaledHeight );
}
else
{
return QRectF(( boundsWidth - rectScaledHeight ) / 2.0, ( boundsHeight - rectScaledWidth ) / 2.0, rectScaledHeight, rectScaledWidth );
return QRectF(( boundsWidth - rectScaledHeight ) / 2.0, ( boundsHeight - rectScaledWidth ) / 2.0, rectScaledWidth, rectScaledHeight );
}
}

//convert angle to radians and flip
double angleRad = -rotation * M_DEG2RAD;
double angleRad = -clippedRotation * M_DEG2RAD;
double cosAngle = cos( angleRad );
double sinAngle = sin( angleRad );

0 comments on commit 2d427a4

Please sign in to comment.
You can’t perform that action at this time.