Skip to content

Commit fb26989

Browse files
author
ben
committed
Bounding box now takes into account font descent so letters like g and j are not cut off from the legend title.
1 parent de54c16 commit fb26989

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/core/composer/qgscomposeritem.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,13 @@ double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
837837
return ( fontMetrics.ascent() / FONT_WORKAROUND_SCALE );
838838
}
839839

840+
double QgsComposerItem::fontDescentMillimeters( const QFont& font ) const
841+
{
842+
QFont metricsFont = scaledFontPixelSize( font );
843+
QFontMetricsF fontMetrics( metricsFont );
844+
return ( fontMetrics.descent() / FONT_WORKAROUND_SCALE );
845+
}
846+
840847
double QgsComposerItem::pixelFontSize( double pointSize ) const
841848
{
842849
return ( pointSize * 0.3527 );

src/core/composer/qgscomposeritem.h

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
213213
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
214214
double fontAscentMillimeters( const QFont& font ) const;
215215

216+
/**Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
217+
double fontDescentMillimeters( const QFont& font ) const;
218+
216219
/**Calculates font to from point size to pixel size*/
217220
double pixelFontSize( double pointSize ) const;
218221

src/core/composer/qgscomposerlegend.cpp

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

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

0 commit comments

Comments
 (0)