Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle device pixel ratio correctly in svg marker rendering
  • Loading branch information
nyalldawson committed May 17, 2023
1 parent 0ab8891 commit 8c9e37f
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/core/symbology/qgsmarkersymbollayer.cpp
Expand Up @@ -2330,7 +2330,8 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext

bool hasDataDefinedSize = false;
const double scaledWidth = calculateSize( context, hasDataDefinedSize );
const double width = context.renderContext().convertToPainterUnits( scaledWidth, mSizeUnit, mSizeMapUnitScale );
const double devicePixelRatio = context.renderContext().devicePixelRatio();
const double width = context.renderContext().convertToPainterUnits( scaledWidth, mSizeUnit, mSizeMapUnitScale ) * devicePixelRatio;

//don't render symbols with a width below one or above 10,000 pixels
if ( static_cast< int >( width ) < 1 || 10000.0 < width )
Expand Down Expand Up @@ -2404,8 +2405,8 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext
if ( ( !context.renderContext().forceVectorOutput() && !rotated ) || ( context.selected() && rasterizeSelected ) )
{
QImage img = QgsApplication::svgCache()->svgAsImage( path, width, fillColor, strokeColor, strokeWidth,
context.renderContext().scaleFactor(), fitsInCache, aspectRatio,
( context.renderContext().flags() & Qgis::RenderContextFlag::RenderBlocking ), evaluatedParameters );
context.renderContext().scaleFactor(), fitsInCache, aspectRatio,
( context.renderContext().flags() & Qgis::RenderContextFlag::RenderBlocking ), evaluatedParameters );
if ( fitsInCache && img.width() > 1 )
{
usePict = false;
Expand All @@ -2420,11 +2421,28 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext
{
QImage transparentImage = img.copy();
QgsSymbolLayerUtils::multiplyImageOpacity( &transparentImage, context.opacity() );
p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage );
if ( devicePixelRatio == 1 )
{
p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage );
}
else
{
p->drawImage( QRectF( -transparentImage.width() / 2.0 / devicePixelRatio, -transparentImage.height() / 2.0 / devicePixelRatio,
transparentImage.width() / devicePixelRatio, transparentImage.height() / devicePixelRatio
), transparentImage );
}
}
else
{
p->drawImage( -img.width() / 2.0, -img.height() / 2.0, img );
if ( devicePixelRatio == 1 )
{
p->drawImage( -img.width() / 2.0, -img.height() / 2.0, img );
}
else
{
p->drawImage( QRectF( -img.width() / 2.0 / devicePixelRatio, -img.height() / 2.0 / devicePixelRatio,
img.width() / devicePixelRatio, img.height() / devicePixelRatio ), img );
}
}
}
}
Expand Down

0 comments on commit 8c9e37f

Please sign in to comment.