Skip to content
Permalink
Browse files
Fix calculation of item bounds when using a reference scale
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent 46f1957 commit 803ba4d0a2c353244fa6e46b74461ec23bcd90b9
@@ -72,15 +72,15 @@ bool QgsAnnotationLayerRenderer::render()
break;
}

std::optional< QgsScopedRenderContextReferenceScaleOverride > referenceScaleOverride;
if ( item.second->useSymbologyReferenceScale() )
{
referenceScaleOverride.emplace( QgsScopedRenderContextReferenceScaleOverride( context, item.second->symbologyReferenceScale() ) );
}

const QgsRectangle bounds = item.second->boundingBox( context );
if ( bounds.intersects( context.extent() ) )
{
std::optional< QgsScopedRenderContextReferenceScaleOverride > referenceScaleOverride;
if ( item.second->useSymbologyReferenceScale() )
{
referenceScaleOverride.emplace( QgsScopedRenderContextReferenceScaleOverride( context, item.second->symbologyReferenceScale() ) );
}

item.second->render( context, mFeedback.get() );
std::unique_ptr< QgsRenderedAnnotationItemDetails > details = std::make_unique< QgsRenderedAnnotationItemDetails >( mLayerID, item.first );
details->setBoundingBox( bounds );
@@ -123,6 +123,9 @@ QgsRectangle QgsAnnotationPointTextItem::boundingBox( QgsRenderContext &context
const double widthInPixels = QgsTextRenderer::textWidth( context, mTextFormat, mText.split( '\n' ) );
const double heightInPixels = QgsTextRenderer::textHeight( context, mTextFormat, mText.split( '\n' ) );

// text size has already been calculated using any symbology reference scale factor above -- we need
// to temporarily remove the reference scale here or we'll be undoing the scaling
QgsScopedRenderContextReferenceScaleOverride resetScaleFactor( context, -1.0 );
const double widthInMapUnits = context.convertToMapUnits( widthInPixels, QgsUnitTypes::RenderPixels );
const double heightInMapUnits = context.convertToMapUnits( heightInPixels, QgsUnitTypes::RenderPixels );

0 comments on commit 803ba4d

Please sign in to comment.