Skip to content
Permalink
Browse files
Keep font size and scale painter using QgsScopedRenderContextScaleToP…
…ixels
  • Loading branch information
mhugent committed May 13, 2021
1 parent dce94dc commit b46fb253237ef07b715d5d335267d409720ef790
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/core/layertree/qgslayertreemodellegendnode.cpp
@@ -1477,12 +1477,14 @@ QSizeF QgsVectorLabelLegendNode::drawSymbol( const QgsLegendSettings &settings,
{
QStringList textLines( mLabelSettings.legendString() );
QgsTextFormat textFormat = mLabelSettings.format();
textFormat.setSize( textFormat.size() / renderContext.scaleFactor() ); //painter is usually scaled (e.g. mm unit)
QgsRenderContext ctx( renderContext );
double textWidth, textHeight;
textWidthHeight( textWidth, textHeight, ctx, textFormat, textLines );
QPointF textPos( xOffset + settings.symbolSize().width() / 2.0 - textWidth / 2.0, yOffset + settings.symbolSize().height() / 2.0 + textHeight / 2.0 );
textWidth /= renderContext.scaleFactor();
textHeight /= renderContext.scaleFactor();
QPointF textPos( renderContext.scaleFactor() * ( xOffset + settings.symbolSize().width() / 2.0 - textWidth / 2.0 ), renderContext.scaleFactor() * ( yOffset + settings.symbolSize().height() / 2.0 + textHeight / 2.0 ) );

QgsScopedRenderContextScaleToPixels scopedScaleToPixels( ctx );
QgsTextRenderer::drawText( textPos, 0.0, QgsTextRenderer::AlignLeft, textLines, ctx, textFormat );

const double symbolWidth = std::max( textWidth, settings.symbolSize().width() );

0 comments on commit b46fb25

Please sign in to comment.