Skip to content

Commit 72714e6

Browse files
committed
Fix label map unit scale range for font size and buffer
Refs #14698, but other label size parameters are still ignoring scale ranges
1 parent 3322bcb commit 72714e6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/core/qgspallabeling.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
22262226
}
22272227

22282228
int fontPixelSize = sizeToPixel( fontSize, context, fontunits, true, fontSizeMapUnitScale );
2229+
double fontSizeScaleFactor = fontSize / ( fontPixelSize - 0.5 );
22292230
// don't try to show font sizes less than 1 pixel (Qt complains)
22302231
if ( fontPixelSize < 1 )
22312232
{
@@ -2283,7 +2284,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
22832284

22842285
// calculate rest of font attributes and store any data defined values
22852286
// this is done here for later use in making label backgrounds part of collision management (when implemented)
2286-
parseTextStyle( labelFont, fontunits, context );
2287+
parseTextStyle( labelFont, context, fontSizeScaleFactor );
22872288
parseTextFormatting( context );
22882289
parseTextBuffer( context );
22892290
parseShapeBackground( context );
@@ -3188,8 +3189,7 @@ bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,
31883189
}
31893190

31903191
void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
3191-
QgsPalLayerSettings::SizeUnit fontunits,
3192-
QgsRenderContext &context )
3192+
QgsRenderContext &context, double fontSizeScaleFactor )
31933193
{
31943194
// NOTE: labelFont already has pixelSize set, so pointSize or pointSizeF might return -1
31953195

@@ -3319,7 +3319,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
33193319
wordspace = wspacing;
33203320
}
33213321
}
3322-
labelFont.setWordSpacing( sizeToPixel( wordspace, context, fontunits, false, fontSizeMapUnitScale ) );
3322+
labelFont.setWordSpacing( wordspace * fontSizeScaleFactor + 0.5 );
33233323

33243324
// data defined letter spacing?
33253325
double letterspace = labelFont.letterSpacing();
@@ -3333,7 +3333,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
33333333
letterspace = lspacing;
33343334
}
33353335
}
3336-
labelFont.setLetterSpacing( QFont::AbsoluteSpacing, sizeToPixel( letterspace, context, fontunits, false, fontSizeMapUnitScale ) );
3336+
labelFont.setLetterSpacing( QFont::AbsoluteSpacing, letterspace * fontSizeScaleFactor + 0.5 );
33373337

33383338
// data defined font capitalization?
33393339
QFont::Capitalization fontcaps = labelFont.capitalization();
@@ -3846,14 +3846,19 @@ double QgsPalLayerSettings::scaleToPixelContext( double size, const QgsRenderCon
38463846

38473847
if ( unit == MapUnits && mapUnitsPerPixel > 0.0 )
38483848
{
3849-
size = size / mapUnitsPerPixel * ( rasterfactor ? c.rasterScaleFactor() : 1 );
3849+
size = size / mapUnitsPerPixel;
3850+
//check max/min size
3851+
if ( mapUnitScale.minSizeMMEnabled )
3852+
size = qMax( size, mapUnitScale.minSizeMM * c.scaleFactor() );
3853+
if ( mapUnitScale.maxSizeMMEnabled )
3854+
size = qMin( size, mapUnitScale.maxSizeMM * c.scaleFactor() );
38503855
}
38513856
else // e.g. in points or mm
38523857
{
38533858
double ptsTomm = ( unit == Points ? 0.352778 : 1 );
3854-
size *= ptsTomm * c.scaleFactor() * ( rasterfactor ? c.rasterScaleFactor() : 1 );
3859+
size *= ptsTomm * c.scaleFactor();
38553860
}
3856-
return size;
3861+
return size * ( rasterfactor ? c.rasterScaleFactor() : 1 );
38573862
}
38583863

38593864
// -------------

src/core/qgspallabeling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ class CORE_EXPORT QgsPalLayerSettings
695695
QVariant& exprVal, QgsExpressionContext &context, const QVariant& originalValue = QVariant() );
696696

697697
void parseTextStyle( QFont& labelFont,
698-
QgsPalLayerSettings::SizeUnit fontunits,
699-
QgsRenderContext& context );
698+
QgsRenderContext& context,
699+
double fontSizeScaleFactor = 1.0 );
700700

701701
void parseTextBuffer( QgsRenderContext& context );
702702

0 commit comments

Comments
 (0)