Skip to content

Commit 09aa281

Browse files
author
mhugent
committedApr 16, 2011
Fix for bug grid annotation distance to map frame (#2899)
git-svn-id: http://svn.osgeo.org/qgis/trunk@15720 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 136b608 commit 09aa281

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed
 

‎python/core/qgscomposeritem.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ class QgsComposerItem: QObject, QGraphicsRectItem
226226
/**Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
227227
double textWidthMillimeters( const QFont& font, const QString& text ) const;
228228

229+
/**Returns the font height of a character in millimeters
230+
@note this method was added in version 1.7*/
231+
double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
232+
229233
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
230234
double fontAscentMillimeters( const QFont& font ) const;
231235

‎src/core/composer/qgscomposeritem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,13 @@ double QgsComposerItem::textWidthMillimeters( const QFont& font, const QString&
803803
return ( fontMetrics.width( text ) / FONT_WORKAROUND_SCALE );
804804
}
805805

806+
double QgsComposerItem::fontHeightCharacterMM( const QFont& font, const QChar& c ) const
807+
{
808+
QFont metricsFont = scaledFontPixelSize( font );
809+
QFontMetricsF fontMetrics( metricsFont );
810+
return ( fontMetrics.boundingRect( c ).height() / FONT_WORKAROUND_SCALE );
811+
}
812+
806813
double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
807814
{
808815
QFont metricsFont = scaledFontPixelSize( font );

‎src/core/composer/qgscomposeritem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,13 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
187187
/**Like the above, but with a rectangle for multiline text*/
188188
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignement = Qt::AlignLeft, Qt::AlignmentFlag valignement = Qt::AlignTop ) const;
189189

190-
/**Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
190+
/**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
191191
double textWidthMillimeters( const QFont& font, const QString& text ) const;
192192

193+
/**Returns the font height of a character in millimeters
194+
@note this method was added in version 1.7*/
195+
double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
196+
193197
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
194198
double fontAscentMillimeters( const QFont& font ) const;
195199

‎src/core/composer/qgscomposermap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
947947
{
948948
Border frameBorder = borderForLineCoord( pos );
949949
double textWidth = textWidthMillimeters( mGridAnnotationFont, annotationString );
950-
double textHeight = fontAscentMillimeters( mGridAnnotationFont );
950+
//relevant for annotations is the height of digits
951+
double textHeight = fontHeightCharacterMM( mGridAnnotationFont, QChar( '0' ) );
951952
double xpos = pos.x();
952953
double ypos = pos.y();
953954
int rotation = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.