Skip to content
Permalink
Browse files

fix device size in decoration item

the size should take the device pixel ration into account
fixes #20321
  • Loading branch information
3nids committed Nov 3, 2018
1 parent 7b6d2c0 commit 8d91a6eea9d38b1ce8fea63212a66de46da0a033
@@ -124,8 +124,14 @@ void QgsDecorationCopyright::render( const QgsMapSettings &mapSettings, QgsRende
double textWidth = QgsTextRenderer::textWidth( context, mTextFormat, displayStringList, &fm );
double textHeight = QgsTextRenderer::textHeight( context, mTextFormat, displayStringList, QgsTextRenderer::Point, &fm );

int deviceHeight = context.painter()->device()->height();
int deviceWidth = context.painter()->device()->width();
QPaintDevice *device = context.painter()->device();
#if QT_VERSION < 0x050600
int deviceHeight = device->height() / device->devicePixelRatio();
int deviceWidth = device->width() / device->devicePixelRatio();
#else
int deviceHeight = device->height() / device->devicePixelRatioF();
int deviceWidth = device->width() / device->devicePixelRatioF();
#endif

float xOffset( 0 ), yOffset( 0 );

@@ -168,8 +168,14 @@ void QgsDecorationNorthArrow::render( const QgsMapSettings &mapSettings, QgsRend
( centerYDouble * std::cos( radiansDouble ) )
) - centerYDouble );
// need width/height of paint device
int deviceHeight = context.painter()->device()->height();
int deviceWidth = context.painter()->device()->width();
QPaintDevice *device = context.painter()->device();
#if QT_VERSION < 0x050600
int deviceHeight = device->height() / device->devicePixelRatio();
int deviceWidth = device->width() / device->devicePixelRatio();
#else
int deviceHeight = device->height() / device->devicePixelRatioF();
int deviceWidth = device->width() / device->devicePixelRatioF();
#endif

// Set margin according to selected units
int xOffset = 0;
@@ -177,8 +177,14 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender
return;

//Get canvas dimensions
int deviceHeight = context.painter()->device()->height();
int deviceWidth = context.painter()->device()->width();
QPaintDevice *device = context.painter()->device();
#if QT_VERSION < 0x050600
int deviceHeight = device->height() / device->devicePixelRatio();
int deviceWidth = device->width() / device->devicePixelRatio();
#else
int deviceHeight = device->height() / device->devicePixelRatioF();
int deviceWidth = device->width() / device->devicePixelRatioF();
#endif

//Get map units per pixel. This can be negative at times (to do with
//projections) and that just confuses the rest of the code in this

0 comments on commit 8d91a6e

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