Skip to content
Permalink
Browse files

Fix label map unit scale range for font size and buffer

Refs #14698, but other label size parameters are still
ignoring scale ranges
  • Loading branch information
nyalldawson committed Apr 25, 2016
1 parent 3322bcb commit 72714e6f5edb41aca84e361a46ffc4fd6d4523d5
Showing with 15 additions and 10 deletions.
  1. +13 −8 src/core/qgspallabeling.cpp
  2. +2 −2 src/core/qgspallabeling.h
@@ -2226,6 +2226,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
}

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

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

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

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

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

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

if ( unit == MapUnits && mapUnitsPerPixel > 0.0 )
{
size = size / mapUnitsPerPixel * ( rasterfactor ? c.rasterScaleFactor() : 1 );
size = size / mapUnitsPerPixel;
//check max/min size
if ( mapUnitScale.minSizeMMEnabled )
size = qMax( size, mapUnitScale.minSizeMM * c.scaleFactor() );
if ( mapUnitScale.maxSizeMMEnabled )
size = qMin( size, mapUnitScale.maxSizeMM * c.scaleFactor() );
}
else // e.g. in points or mm
{
double ptsTomm = ( unit == Points ? 0.352778 : 1 );
size *= ptsTomm * c.scaleFactor() * ( rasterfactor ? c.rasterScaleFactor() : 1 );
size *= ptsTomm * c.scaleFactor();
}
return size;
return size * ( rasterfactor ? c.rasterScaleFactor() : 1 );
}

// -------------
@@ -695,8 +695,8 @@ class CORE_EXPORT QgsPalLayerSettings
QVariant& exprVal, QgsExpressionContext &context, const QVariant& originalValue = QVariant() );

void parseTextStyle( QFont& labelFont,
QgsPalLayerSettings::SizeUnit fontunits,
QgsRenderContext& context );
QgsRenderContext& context,
double fontSizeScaleFactor = 1.0 );

void parseTextBuffer( QgsRenderContext& context );

0 comments on commit 72714e6

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