Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 8d91a6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/app/decorations/qgsdecorationcopyright.cpp
Expand Up @@ -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 );

Expand Down
10 changes: 8 additions & 2 deletions src/app/decorations/qgsdecorationnortharrow.cpp
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/app/decorations/qgsdecorationscalebar.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 8d91a6e

Please sign in to comment.