Skip to content
Permalink
Browse files
Bounding box now takes into account font descent so letters like g an…
…d j are not cut off from the legend title.
  • Loading branch information
ben committed Jan 4, 2013
1 parent de54c16 commit fb26989a7a31251c4fe42f2704aac3b8a807327d
Showing with 11 additions and 1 deletion.
  1. +7 −0 src/core/composer/qgscomposeritem.cpp
  2. +3 −0 src/core/composer/qgscomposeritem.h
  3. +1 −1 src/core/composer/qgscomposerlegend.cpp
@@ -837,6 +837,13 @@ double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
return ( fontMetrics.ascent() / FONT_WORKAROUND_SCALE );
}

double QgsComposerItem::fontDescentMillimeters( const QFont& font ) const
{
QFont metricsFont = scaledFontPixelSize( font );
QFontMetricsF fontMetrics( metricsFont );
return ( fontMetrics.descent() / FONT_WORKAROUND_SCALE );
}

double QgsComposerItem::pixelFontSize( double pointSize ) const
{
return ( pointSize * 0.3527 );
@@ -213,6 +213,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double fontAscentMillimeters( const QFont& font ) const;

/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double fontDescentMillimeters( const QFont& font ) const;

/**Calculates font to from point size to pixel size*/
double pixelFontSize( double pointSize ) const;

@@ -212,7 +212,7 @@ QSizeF QgsComposerLegend::drawTitle( QPainter* painter, QPointF point, Qt::Align
{
// it does not draw the last world if rectangle width is exactly text width
double width = textWidthMillimeters( mTitleFont, *titlePart ) + 1;
double height = fontAscentMillimeters( mTitleFont );
double height = fontAscentMillimeters( mTitleFont ) + fontDescentMillimeters( mTitleFont );

double left = halignement == Qt::AlignLeft ? point.x() : point.x() - width / 2;

0 comments on commit fb26989

Please sign in to comment.