Skip to content
Permalink
Browse files

[layouts] Fix resizing multiline label items to adjust to the size

of their text
  • Loading branch information
nyalldawson committed Oct 10, 2020
1 parent f940ffc commit 6829e6351e1dab18f1fa0c0443107eb7617794c7
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/core/layout/qgslayoututils.cpp
@@ -220,13 +220,21 @@ double QgsLayoutUtils::textWidthMM( const QFont &font, const QString &text )
{
//upscale using FONT_WORKAROUND_SCALE
//ref: http://osgeo-org.1560.x6.nabble.com/Multi-line-labels-and-font-bug-td4157152.html

const QStringList multiLineSplit = text.split( '\n' );
QFont metricsFont = scaledFontPixelSize( font );
QFontMetricsF fontMetrics( metricsFont );

double maxWidth = 0;
for ( const QString &line : multiLineSplit )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return ( fontMetrics.width( text ) / FONT_WORKAROUND_SCALE );
maxWidth = std::max( maxWidth, ( fontMetrics.width( line ) / FONT_WORKAROUND_SCALE ) );
#else
return ( fontMetrics.horizontalAdvance( text ) / FONT_WORKAROUND_SCALE );
maxWidth = std::max( maxWidth, ( fontMetrics.horizontalAdvance( line ) / FONT_WORKAROUND_SCALE ) );
#endif
}
return maxWidth;
}

double QgsLayoutUtils::textHeightMM( const QFont &font, const QString &text, double multiLineHeight )

0 comments on commit 6829e63

Please sign in to comment.
You can’t perform that action at this time.