@@ -2827,35 +2827,38 @@ QGraphicsView *QgsComposition::graphicsView() const
2827
2827
2828
2828
void QgsComposition::computeWorldFileParameters ( double & a, double & b, double & c, double & d, double & e, double & f ) const
2829
2829
{
2830
- //
2831
- // Word file parameters : affine transformation parameters from pixel coordinates to map coordinates
2830
+ // World file parameters : affine transformation parameters from pixel coordinates to map coordinates
2832
2831
2833
2832
if ( !mWorldFileMap )
2834
2833
{
2835
2834
return ;
2836
2835
}
2837
2836
2838
- QRectF brect = mWorldFileMap ->mapRectToScene ( mWorldFileMap ->rect () );
2839
- QgsRectangle extent = *mWorldFileMap ->currentMapExtent ();
2837
+ double destinationHeight = paperHeight ();
2838
+ double destinationWidth = paperWidth ();
2839
+
2840
+ QRectF mapItemSceneRect = mWorldFileMap ->mapRectToScene ( mWorldFileMap ->rect () );
2841
+ QgsRectangle mapExtent = *mWorldFileMap ->currentMapExtent ();
2840
2842
2841
2843
double alpha = mWorldFileMap ->mapRotation () / 180 * M_PI;
2842
2844
2843
- double xr = extent .width () / brect .width ();
2844
- double yr = extent .height () / brect .height ();
2845
+ double xRatio = mapExtent .width () / mapItemSceneRect .width ();
2846
+ double yRatio = mapExtent .height () / mapItemSceneRect .height ();
2845
2847
2846
- double XC = extent .center ().x ();
2847
- double YC = extent .center ().y ();
2848
+ double xCenter = mapExtent .center ().x ();
2849
+ double yCenter = mapExtent .center ().y ();
2848
2850
2849
- // get the extent for the page
2850
- double xmin = extent.xMinimum () - mWorldFileMap ->pos ().x () * xr;
2851
- double ymax = extent.yMaximum () + mWorldFileMap ->pos ().y () * yr;
2852
- QgsRectangle paperExtent ( xmin, ymax - paperHeight () * yr, xmin + paperWidth () * xr, ymax );
2851
+ // get the extent (in map units) for the page
2852
+ QPointF mapItemPosOnPage = mWorldFileMap ->pagePos ();
2853
+ double xmin = mapExtent.xMinimum () - mapItemPosOnPage.x () * xRatio;
2854
+ double ymax = mapExtent.yMaximum () + mapItemPosOnPage.y () * yRatio;
2855
+ QgsRectangle paperExtent ( xmin, ymax - destinationHeight * yRatio, xmin + destinationWidth * xRatio, ymax );
2853
2856
2854
2857
double X0 = paperExtent.xMinimum ();
2855
2858
double Y0 = paperExtent.yMinimum ();
2856
2859
2857
- int widthPx = ( int )( printResolution () * paperWidth () / 25.4 );
2858
- int heightPx = ( int )( printResolution () * paperHeight () / 25.4 );
2860
+ int widthPx = ( int )( printResolution () * destinationWidth / 25.4 );
2861
+ int heightPx = ( int )( printResolution () * destinationHeight / 25.4 );
2859
2862
2860
2863
double Ww = paperExtent.width () / widthPx;
2861
2864
double Hh = paperExtent.height () / heightPx;
@@ -2873,10 +2876,10 @@ void QgsComposition::computeWorldFileParameters( double& a, double& b, double& c
2873
2876
double r[6 ];
2874
2877
r[0 ] = cos ( alpha );
2875
2878
r[1 ] = -sin ( alpha );
2876
- r[2 ] = XC * ( 1 - cos ( alpha ) ) + YC * sin ( alpha );
2879
+ r[2 ] = xCenter * ( 1 - cos ( alpha ) ) + yCenter * sin ( alpha );
2877
2880
r[3 ] = sin ( alpha );
2878
2881
r[4 ] = cos ( alpha );
2879
- r[5 ] = - XC * sin ( alpha ) + YC * ( 1 - cos ( alpha ) );
2882
+ r[5 ] = - xCenter * sin ( alpha ) + yCenter * ( 1 - cos ( alpha ) );
2880
2883
2881
2884
// result = rotation x scaling = rotation(scaling(X))
2882
2885
a = r[0 ] * s[0 ] + r[1 ] * s[3 ];
0 commit comments