@@ -891,26 +891,35 @@ QRectF QgsComposerItem::largestRotatedRectWithinBounds( QRectF originalRect, QRe
891
891
double boundsHeight = boundsRect.height ();
892
892
double ratioBoundsRect = boundsWidth / boundsHeight;
893
893
894
+ double clippedRotation = fmod ( rotation, 360.0 );
895
+
894
896
// 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 )
896
898
{
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
+ }
899
908
double rectScaledWidth = rectScale * originalWidth;
900
909
double rectScaledHeight = rectScale * originalHeight;
901
910
902
- if ( rotation == 0 || rotation == 180 )
911
+ if ( clippedRotation == 0 || clippedRotation == 180 )
903
912
{
904
913
return QRectF (( boundsWidth - rectScaledWidth ) / 2.0 , ( boundsHeight - rectScaledHeight ) / 2.0 , rectScaledWidth, rectScaledHeight );
905
914
}
906
915
else
907
916
{
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 );
909
918
}
910
919
}
911
920
912
921
// convert angle to radians and flip
913
- double angleRad = -rotation * M_DEG2RAD;
922
+ double angleRad = -clippedRotation * M_DEG2RAD;
914
923
double cosAngle = cos ( angleRad );
915
924
double sinAngle = sin ( angleRad );
916
925
0 commit comments