Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhugent committed Apr 16, 2011
1 parent 136b608 commit 09aa281
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions python/core/qgscomposeritem.sip
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -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 );
Expand Down
6 changes: 5 additions & 1 deletion src/core/composer/qgscomposeritem.h
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 09aa281

Please sign in to comment.