diff --git a/python/core/qgscomposeritem.sip b/python/core/qgscomposeritem.sip index ce4162825f0..189beecbe5d 100644 --- a/python/core/qgscomposeritem.sip +++ b/python/core/qgscomposeritem.sip @@ -226,6 +226,10 @@ class QgsComposerItem: QObject, QGraphicsRectItem /**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; diff --git a/src/core/composer/qgscomposeritem.cpp b/src/core/composer/qgscomposeritem.cpp index 5b3f7ffee8a..6b4ccb79d54 100644 --- a/src/core/composer/qgscomposeritem.cpp +++ b/src/core/composer/qgscomposeritem.cpp @@ -803,6 +803,13 @@ double QgsComposerItem::textWidthMillimeters( const QFont& font, const QString& 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 ); diff --git a/src/core/composer/qgscomposeritem.h b/src/core/composer/qgscomposeritem.h index 81dda20f3ec..02365735a63 100644 --- a/src/core/composer/qgscomposeritem.h +++ b/src/core/composer/qgscomposeritem.h @@ -187,9 +187,13 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem /**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; diff --git a/src/core/composer/qgscomposermap.cpp b/src/core/composer/qgscomposermap.cpp index f58ace9b39c..3ec9bb25d75 100644 --- a/src/core/composer/qgscomposermap.cpp +++ b/src/core/composer/qgscomposermap.cpp @@ -947,7 +947,8 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos, { 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;