[QGIS Commit] r9057 - branches/advanced_printing_branch/src/app/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 13 11:02:56 EDT 2008


Author: mhugent
Date: 2008-08-13 11:02:56 -0400 (Wed, 13 Aug 2008)
New Revision: 9057

Modified:
   branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h
Log:
Keep width height ratio for composer pictures

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp	2008-08-13 13:00:01 UTC (rev 9056)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp	2008-08-13 15:02:56 UTC (rev 9057)
@@ -64,7 +64,20 @@
 
   if(mMode != UNKNOWN)
     {
-      painter->drawImage(QRectF(0, 0, rect().width(), rect().height()), mImage, QRectF(0, 0, mImage.width(), mImage.height()));
+      double widthRatio = mImage.width() / rect().width();
+      double heightRatio = mImage.height() / rect().height();
+      double targetWidth, targetHeight;
+      if(widthRatio > heightRatio)
+	{
+	  targetWidth = rect().width();
+	  targetHeight = mImage.height() / widthRatio;
+	}
+      else
+	{
+	  targetHeight = rect().height();
+	  targetWidth = mImage.width() / heightRatio;
+	}
+      painter->drawImage(QRectF(0, 0, targetWidth, targetHeight), mImage, QRectF(0, 0, mImage.width(), mImage.height()));
     }
 
   //frame and selection boxes
@@ -94,6 +107,7 @@
       if(validTestRenderer.isValid())
 	{
 	  mMode = SVG;
+	  mDefaultSvgSize = validTestRenderer.defaultSize();
 	}
       else
 	{
@@ -132,7 +146,24 @@
   mSvgCacheUpToDate = false;
   if(mMode == SVG)
     {
-      mImage = QImage(rectangle.width() * mCachedDpi/25.4, rectangle.height() * mCachedDpi/25.4, QImage::Format_ARGB32);
+      //keep aspect ratio
+      double widthRatio = rectangle.width() / mDefaultSvgSize.width();
+      double heightRatio = rectangle.height() / mDefaultSvgSize.height();
+
+      double newImageWidth;
+      double newImageHeight;
+
+      if(widthRatio > heightRatio)
+	{
+	  newImageWidth = rectangle.width() * mCachedDpi / 25.4;
+	  newImageHeight = mDefaultSvgSize.height() * widthRatio * mCachedDpi / 25.4;
+	}
+      else
+	{
+	  newImageHeight = rectangle.height() * mCachedDpi / 25.4;
+	  newImageWidth = mDefaultSvgSize.width() * heightRatio * mCachedDpi / 25.4;
+	}
+      mImage = QImage(newImageWidth, newImageHeight, QImage::Format_ARGB32);
     }
   QgsComposerItem::setSceneRect(rectangle);
 }

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h	2008-08-13 13:00:01 UTC (rev 9056)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h	2008-08-13 15:02:56 UTC (rev 9057)
@@ -74,6 +74,7 @@
   /**False if image needs to be rendered from svg*/
   bool mSvgCacheUpToDate;
   int mCachedDpi; //store dpis for which the svg cache is valid
+  QSize mDefaultSvgSize;
 };
 
 #endif



More information about the QGIS-commit mailing list