diff --git a/src/core/symbology-ng/qgssymbollayerv2utils.cpp b/src/core/symbology-ng/qgssymbollayerv2utils.cpp index f8db8ec108d3..a3d2da53279f 100644 --- a/src/core/symbology-ng/qgssymbollayerv2utils.cpp +++ b/src/core/symbology-ng/qgssymbollayerv2utils.cpp @@ -660,3 +660,19 @@ double QgsSymbolLayerV2Utils::pixelSizeScaleFactor( QgsRenderContext& c, QgsSymb return c.rasterScaleFactor() / c.mapToPixel().mapUnitsPerPixel(); } } + +QgsRenderContext QgsSymbolLayerV2Utils::createRenderContext( QPainter* p ) +{ + QgsRenderContext context; + context.setPainter( p ); + context.setRasterScaleFactor( 1.0 ); + if ( p && p->device() ) + { + context.setScaleFactor( p->device()->logicalDpiX() / 25.4 ); + } + else + { + context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value + } + return context; +} diff --git a/src/core/symbology-ng/qgssymbollayerv2utils.h b/src/core/symbology-ng/qgssymbollayerv2utils.h index fcff7ec76c93..b441b39ce69b 100644 --- a/src/core/symbology-ng/qgssymbollayerv2utils.h +++ b/src/core/symbology-ng/qgssymbollayerv2utils.h @@ -73,6 +73,8 @@ class CORE_EXPORT QgsSymbolLayerV2Utils static double lineWidthScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u ); /**Returns scale factor painter units -> pixel dimensions*/ static double pixelSizeScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u ); + /**Creates a render context for a pixel based device*/ + static QgsRenderContext createRenderContext( QPainter* p ); }; class QPolygonF; diff --git a/src/core/symbology-ng/qgssymbolv2.cpp b/src/core/symbology-ng/qgssymbolv2.cpp index 0098729227b1..adfca1f6e47b 100644 --- a/src/core/symbology-ng/qgssymbolv2.cpp +++ b/src/core/symbology-ng/qgssymbolv2.cpp @@ -160,8 +160,7 @@ QColor QgsSymbolV2::color() void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size ) { - QgsRenderContext context; - context.setPainter( painter ); + QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( painter ); QgsSymbolV2RenderContext symbolContext( context, mOutputUnit ); for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it ) { @@ -186,9 +185,7 @@ QImage QgsSymbolV2::bigSymbolPreviewImage() p.drawLine( 50, 0, 50, 100 ); } - QgsRenderContext context; - context.setPainter( &p ); - + QgsRenderContext context = QgsSymbolLayerV2Utils::createRenderContext( &p ); startRender( context ); if ( mType == QgsSymbolV2::Line ) @@ -248,7 +245,7 @@ QgsSymbolLayerV2List QgsSymbolV2::cloneLayers() const //////////////////// QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u ) - : mRenderContext( c ), mOutputUnit( u ) + : mRenderContext( c ), mOutputUnit( u ) { } @@ -258,12 +255,12 @@ QgsSymbolV2RenderContext::~QgsSymbolV2RenderContext() } -double QgsSymbolV2RenderContext::outputLineWidth(double width) const +double QgsSymbolV2RenderContext::outputLineWidth( double width ) const { return width * QgsSymbolLayerV2Utils::lineWidthScaleFactor( mRenderContext, mOutputUnit ); } -double QgsSymbolV2RenderContext::outputPixelSize(double size) const +double QgsSymbolV2RenderContext::outputPixelSize( double size ) const { return size * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( mRenderContext, mOutputUnit ); }