Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 72714e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/core/qgspallabeling.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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 );
}

// -------------
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgspallabeling.h
Expand Up @@ -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 );

Expand Down

0 comments on commit 72714e6

Please sign in to comment.