[QGIS Commit] r15720 - in trunk/qgis: python/core src/core/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Apr 16 04:34:02 EDT 2011


Author: mhugent
Date: 2011-04-16 01:34:02 -0700 (Sat, 16 Apr 2011)
New Revision: 15720

Modified:
   trunk/qgis/python/core/qgscomposeritem.sip
   trunk/qgis/src/core/composer/qgscomposeritem.cpp
   trunk/qgis/src/core/composer/qgscomposeritem.h
   trunk/qgis/src/core/composer/qgscomposermap.cpp
Log:
Fix for bug grid annotation distance to map frame (#2899)

Modified: trunk/qgis/python/core/qgscomposeritem.sip
===================================================================
--- trunk/qgis/python/core/qgscomposeritem.sip	2011-04-16 07:06:52 UTC (rev 15719)
+++ trunk/qgis/python/core/qgscomposeritem.sip	2011-04-16 08:34:02 UTC (rev 15720)
@@ -226,6 +226,10 @@
     /**Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
     double textWidthMillimeters( const QFont& font, const QString& text ) const;
 
+    /**Returns the font height of a character in millimeters
+      @note this method was added in version 1.7*/
+    double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
+
     /**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
     double fontAscentMillimeters( const QFont& font ) const;
 

Modified: trunk/qgis/src/core/composer/qgscomposeritem.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.cpp	2011-04-16 07:06:52 UTC (rev 15719)
+++ trunk/qgis/src/core/composer/qgscomposeritem.cpp	2011-04-16 08:34:02 UTC (rev 15720)
@@ -803,6 +803,13 @@
   return ( fontMetrics.width( text ) / FONT_WORKAROUND_SCALE );
 }
 
+double QgsComposerItem::fontHeightCharacterMM( const QFont& font, const QChar& c ) const
+{
+  QFont metricsFont = scaledFontPixelSize( font );
+  QFontMetricsF fontMetrics( metricsFont );
+  return ( fontMetrics.boundingRect( c ).height() / FONT_WORKAROUND_SCALE );
+}
+
 double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
 {
   QFont metricsFont = scaledFontPixelSize( font );

Modified: trunk/qgis/src/core/composer/qgscomposeritem.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.h	2011-04-16 07:06:52 UTC (rev 15719)
+++ trunk/qgis/src/core/composer/qgscomposeritem.h	2011-04-16 08:34:02 UTC (rev 15720)
@@ -187,9 +187,13 @@
     /**Like the above, but with a rectangle for multiline text*/
     void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignement = Qt::AlignLeft, Qt::AlignmentFlag valignement = Qt::AlignTop ) const;
 
-    /**Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
+    /**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
     double textWidthMillimeters( const QFont& font, const QString& text ) const;
 
+    /**Returns the font height of a character in millimeters
+      @note this method was added in version 1.7*/
+    double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
+
     /**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
     double fontAscentMillimeters( const QFont& font ) const;
 

Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp	2011-04-16 07:06:52 UTC (rev 15719)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp	2011-04-16 08:34:02 UTC (rev 15720)
@@ -947,7 +947,8 @@
 {
   Border frameBorder = borderForLineCoord( pos );
   double textWidth = textWidthMillimeters( mGridAnnotationFont, annotationString );
-  double textHeight = fontAscentMillimeters( mGridAnnotationFont );
+  //relevant for annotations is the height of digits
+  double textHeight = fontHeightCharacterMM( mGridAnnotationFont, QChar( '0' ) );
   double xpos = pos.x();
   double ypos = pos.y();
   int rotation = 0;



More information about the QGIS-commit mailing list