Skip to content

Commit

Permalink
[composer] Fix calculation of rotated image size inside picture items…
Browse files Browse the repository at this point in the history
… when rotation is 90 or 270 degrees
  • Loading branch information
nyalldawson committed Jul 19, 2014
1 parent 904443f commit 2d427a4
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/core/composer/qgscomposeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down

0 comments on commit 2d427a4

Please sign in to comment.