Skip to content

Commit 2d427a4

Browse files
committed
[composer] Fix calculation of rotated image size inside picture items when rotation is 90 or 270 degrees
1 parent 904443f commit 2d427a4

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/core/composer/qgscomposeritem.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -891,26 +891,35 @@ QRectF QgsComposerItem::largestRotatedRectWithinBounds( QRectF originalRect, QRe
891891
double boundsHeight = boundsRect.height();
892892
double ratioBoundsRect = boundsWidth / boundsHeight;
893893

894+
double clippedRotation = fmod( rotation, 360.0 );
895+
894896
//shortcut for some rotation values
895-
if ( rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270 )
897+
if ( clippedRotation == 0 || clippedRotation == 90 || clippedRotation == 180 || clippedRotation == 270 )
896898
{
897-
double originalRatio = originalWidth / originalHeight;
898-
double rectScale = originalRatio > ratioBoundsRect ? boundsWidth / originalWidth : boundsHeight / originalHeight;
899+
double rectScale;
900+
if ( clippedRotation == 0 || clippedRotation == 180 )
901+
{
902+
rectScale = (( originalWidth / originalHeight ) > ratioBoundsRect ) ? boundsWidth / originalWidth : boundsHeight / originalHeight;
903+
}
904+
else
905+
{
906+
rectScale = (( originalHeight / originalWidth ) > ratioBoundsRect ) ? boundsWidth / originalHeight : boundsHeight / originalWidth;
907+
}
899908
double rectScaledWidth = rectScale * originalWidth;
900909
double rectScaledHeight = rectScale * originalHeight;
901910

902-
if ( rotation == 0 || rotation == 180 )
911+
if ( clippedRotation == 0 || clippedRotation == 180 )
903912
{
904913
return QRectF(( boundsWidth - rectScaledWidth ) / 2.0, ( boundsHeight - rectScaledHeight ) / 2.0, rectScaledWidth, rectScaledHeight );
905914
}
906915
else
907916
{
908-
return QRectF(( boundsWidth - rectScaledHeight ) / 2.0, ( boundsHeight - rectScaledWidth ) / 2.0, rectScaledHeight, rectScaledWidth );
917+
return QRectF(( boundsWidth - rectScaledHeight ) / 2.0, ( boundsHeight - rectScaledWidth ) / 2.0, rectScaledWidth, rectScaledHeight );
909918
}
910919
}
911920

912921
//convert angle to radians and flip
913-
double angleRad = -rotation * M_DEG2RAD;
922+
double angleRad = -clippedRotation * M_DEG2RAD;
914923
double cosAngle = cos( angleRad );
915924
double sinAngle = sin( angleRad );
916925

0 commit comments

Comments
 (0)