diff --git a/python/PyQt6/core/auto_generated/effects/qgspainteffect.sip.in b/python/PyQt6/core/auto_generated/effects/qgspainteffect.sip.in index 2f8cc03e4a49..f4afe88fb9b2 100644 --- a/python/PyQt6/core/auto_generated/effects/qgspainteffect.sip.in +++ b/python/PyQt6/core/auto_generated/effects/qgspainteffect.sip.in @@ -305,13 +305,16 @@ effects. .. seealso:: :py:func:`sourceAsImage` %End - void fixQPictureDpi( QPainter *painter ) const; + void fixQPictureDpi( QPainter *painter ) const /Deprecated/; %Docstring Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures. This may need to be called by derived classes prior to rendering results onto a painter. :param painter: destination painter + +.. deprecated:: + QGIS 3.40, use :py:func:`QgsPainting.drawPicture()` or :py:func:`QgsPainting.applyScaleFixForQPictureDpi()` instead. %End }; diff --git a/python/PyQt6/core/auto_generated/painting/qgspainting.sip.in b/python/PyQt6/core/auto_generated/painting/qgspainting.sip.in index a4af00314a60..72c2f88e1b25 100644 --- a/python/PyQt6/core/auto_generated/painting/qgspainting.sip.in +++ b/python/PyQt6/core/auto_generated/painting/qgspainting.sip.in @@ -87,6 +87,57 @@ Returns ``True`` if the triangle could be rendered, or ``False`` if it could not .. versionadded:: 3.34 %End + static int qtDefaultDpiX(); +%Docstring +Returns the default Qt horizontal DPI. + +.. note:: + + This method proxies the internal Qt :py:func:`~QgsPainting.qt_defaultDpiX` function. + +.. seealso:: :py:func:`qtDefaultDpiY` + +.. versionadded:: 3.40 +%End + + static int qtDefaultDpiY(); +%Docstring +Returns the default Qt vertical DPI. + +.. note:: + + This method proxies the internal Qt :py:func:`~QgsPainting.qt_defaultDpiY` function. + +.. seealso:: :py:func:`qtDefaultDpiX` + +.. versionadded:: 3.40 +%End + + static void applyScaleFixForQPictureDpi( QPainter *painter ); +%Docstring +Applies a workaround to a ``painter`` to avoid an issue with incorrect scaling +when drawing QPictures. + +.. note:: + + This is a low-level method, which alters the ``painter`` state and relies on the + caller saving/restoring painter state accordingly. Consider using + the high-level :py:func:`~QgsPainting.drawPicture` method instead. + +.. seealso:: :py:func:`drawPicture` + +.. versionadded:: 3.40 +%End + + static void drawPicture( QPainter *painter, const QPointF &point, const QPicture &picture ); +%Docstring +Draws a picture onto a ``painter``, correctly applying workarounds to avoid issues +with incorrect scaling. + +.. seealso:: :py:func:`applyScaleFixForQPictureDpi` + +.. versionadded:: 3.40 +%End }; /************************************************************************ diff --git a/python/core/auto_generated/effects/qgspainteffect.sip.in b/python/core/auto_generated/effects/qgspainteffect.sip.in index 10b667520b4a..8dc2b0776d2a 100644 --- a/python/core/auto_generated/effects/qgspainteffect.sip.in +++ b/python/core/auto_generated/effects/qgspainteffect.sip.in @@ -305,13 +305,16 @@ effects. .. seealso:: :py:func:`sourceAsImage` %End - void fixQPictureDpi( QPainter *painter ) const; + void fixQPictureDpi( QPainter *painter ) const /Deprecated/; %Docstring Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures. This may need to be called by derived classes prior to rendering results onto a painter. :param painter: destination painter + +.. deprecated:: + QGIS 3.40, use :py:func:`QgsPainting.drawPicture()` or :py:func:`QgsPainting.applyScaleFixForQPictureDpi()` instead. %End }; diff --git a/python/core/auto_generated/painting/qgspainting.sip.in b/python/core/auto_generated/painting/qgspainting.sip.in index a4af00314a60..72c2f88e1b25 100644 --- a/python/core/auto_generated/painting/qgspainting.sip.in +++ b/python/core/auto_generated/painting/qgspainting.sip.in @@ -87,6 +87,57 @@ Returns ``True`` if the triangle could be rendered, or ``False`` if it could not .. versionadded:: 3.34 %End + static int qtDefaultDpiX(); +%Docstring +Returns the default Qt horizontal DPI. + +.. note:: + + This method proxies the internal Qt :py:func:`~QgsPainting.qt_defaultDpiX` function. + +.. seealso:: :py:func:`qtDefaultDpiY` + +.. versionadded:: 3.40 +%End + + static int qtDefaultDpiY(); +%Docstring +Returns the default Qt vertical DPI. + +.. note:: + + This method proxies the internal Qt :py:func:`~QgsPainting.qt_defaultDpiY` function. + +.. seealso:: :py:func:`qtDefaultDpiX` + +.. versionadded:: 3.40 +%End + + static void applyScaleFixForQPictureDpi( QPainter *painter ); +%Docstring +Applies a workaround to a ``painter`` to avoid an issue with incorrect scaling +when drawing QPictures. + +.. note:: + + This is a low-level method, which alters the ``painter`` state and relies on the + caller saving/restoring painter state accordingly. Consider using + the high-level :py:func:`~QgsPainting.drawPicture` method instead. + +.. seealso:: :py:func:`drawPicture` + +.. versionadded:: 3.40 +%End + + static void drawPicture( QPainter *painter, const QPointF &point, const QPicture &picture ); +%Docstring +Draws a picture onto a ``painter``, correctly applying workarounds to avoid issues +with incorrect scaling. + +.. seealso:: :py:func:`applyScaleFixForQPictureDpi` + +.. versionadded:: 3.40 +%End }; /************************************************************************ diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index db37d483f98d..bd3dd17b1f41 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -177,8 +177,6 @@ #include #include -Q_GUI_EXPORT extern int qt_defaultDpiX(); - // // Mac OS X Includes // Must include before GEOS 3 due to unqualified use of 'Point' diff --git a/src/app/qgsanimationexportdialog.cpp b/src/app/qgsanimationexportdialog.cpp index d339a064fca5..2ec5e9043755 100644 --- a/src/app/qgsanimationexportdialog.cpp +++ b/src/app/qgsanimationexportdialog.cpp @@ -28,8 +28,6 @@ #include #include -Q_GUI_EXPORT extern int qt_defaultDpiX(); - QgsAnimationExportDialog::QgsAnimationExportDialog( QWidget *parent, QgsMapCanvas *mapCanvas, const QList< QgsMapDecoration * > &decorations ) : QDialog( parent ) , mMapCanvas( mapCanvas ) diff --git a/src/app/qgsmapsavedialog.cpp b/src/app/qgsmapsavedialog.cpp index e14e73ed4afe..5c1ae7d778f8 100644 --- a/src/app/qgsmapsavedialog.cpp +++ b/src/app/qgsmapsavedialog.cpp @@ -47,8 +47,6 @@ #include "qgsfileutils.h" #include "qgsannotationlayer.h" -Q_GUI_EXPORT extern int qt_defaultDpiX(); - QgsMapSaveDialog::QgsMapSaveDialog( QWidget *parent, QgsMapCanvas *mapCanvas, const QList &decorations, const QList< QgsAnnotation *> &annotations, DialogType type ) : QDialog( parent ) , mDialogType( type ) diff --git a/src/core/annotations/qgsannotation.cpp b/src/core/annotations/qgsannotation.cpp index 122c3d7d8514..9cb1688f9acf 100644 --- a/src/core/annotations/qgsannotation.cpp +++ b/src/core/annotations/qgsannotation.cpp @@ -24,12 +24,11 @@ #include "qgssymbol.h" #include "qgsmarkersymbol.h" #include "qgsfillsymbol.h" +#include "qgspainting.h" #include #include -Q_GUI_EXPORT extern int qt_defaultDpiX(); - QgsAnnotation::QgsAnnotation( QObject *parent ) : QObject( parent ) , mMarkerSymbol( new QgsMarkerSymbol() ) @@ -329,7 +328,7 @@ void QgsAnnotation::_readXml( const QDomElement &annotationElem, const QgsReadWr } mContentsMargins = QgsMargins::fromString( annotationElem.attribute( QStringLiteral( "contentsMargin" ) ) ); - const double dpiScale = 25.4 / qt_defaultDpiX(); + const double dpiScale = 25.4 / QgsPainting::qtDefaultDpiX(); if ( annotationElem.hasAttribute( QStringLiteral( "frameWidthMM" ) ) ) mFrameSize.setWidth( annotationElem.attribute( QStringLiteral( "frameWidthMM" ), QStringLiteral( "5" ) ).toDouble() ); else diff --git a/src/core/effects/qgseffectstack.cpp b/src/core/effects/qgseffectstack.cpp index 18c5daf782d6..00f82353e830 100644 --- a/src/core/effects/qgseffectstack.cpp +++ b/src/core/effects/qgseffectstack.cpp @@ -19,6 +19,7 @@ #include "qgspainteffectregistry.h" #include "qgsrendercontext.h" #include "qgsapplication.h" +#include "qgspainting.h" #include QgsEffectStack::QgsEffectStack( const QgsEffectStack &other ) @@ -136,9 +137,7 @@ void QgsEffectStack::draw( QgsRenderContext &context ) QPicture *pic = results.takeLast(); if ( mEffectList.at( i )->drawMode() != QgsPaintEffect::Modifier ) { - const QgsScopedQPainterState painterState( context.painter() ); - fixQPictureDpi( context.painter() ); - context.painter()->drawPicture( 0, 0, *pic ); + QgsPainting::drawPicture( context.painter(), QPointF( 0, 0 ), *pic ); } delete pic; } diff --git a/src/core/effects/qgspainteffect.cpp b/src/core/effects/qgspainteffect.cpp index 12587b45b0c7..a4d2f38a148c 100644 --- a/src/core/effects/qgspainteffect.cpp +++ b/src/core/effects/qgspainteffect.cpp @@ -20,10 +20,9 @@ #include "qgslogger.h" #include "qgsrendercontext.h" #include "qgssymbollayerutils.h" -#include +#include "qgspainting.h" -Q_GUI_EXPORT extern int qt_defaultDpiX(); -Q_GUI_EXPORT extern int qt_defaultDpiY(); +#include QgsPaintEffect::QgsPaintEffect( const QgsPaintEffect &other ) : mEnabled( other.enabled() ) @@ -132,9 +131,7 @@ void QgsPaintEffect::drawSource( QPainter &painter ) { if ( requiresQPainterDpiFix ) { - const QgsScopedQPainterState painterState( &painter ); - fixQPictureDpi( &painter ); - painter.drawPicture( 0, 0, *mPicture ); + QgsPainting::drawPicture( &painter, QPointF( 0, 0 ), *mPicture ); } else { @@ -180,12 +177,7 @@ QRectF QgsPaintEffect::boundingRect( const QRectF &rect, const QgsRenderContext void QgsPaintEffect::fixQPictureDpi( QPainter *painter ) const { - // QPicture makes an assumption that we drawing to it with system DPI. - // Then when being drawn, it scales the painter. The following call - // negates the effect. There is no way of setting QPicture's DPI. - // See QTBUG-20361 - painter->scale( static_cast< double >( qt_defaultDpiX() ) / painter->device()->logicalDpiX(), - static_cast< double >( qt_defaultDpiY() ) / painter->device()->logicalDpiY() ); + QgsPainting::applyScaleFixForQPictureDpi( painter ); } QRectF QgsPaintEffect::imageBoundingRect( const QgsRenderContext &context ) const diff --git a/src/core/effects/qgspainteffect.h b/src/core/effects/qgspainteffect.h index d67603d2bbe7..c38f8551530a 100644 --- a/src/core/effects/qgspainteffect.h +++ b/src/core/effects/qgspainteffect.h @@ -289,8 +289,10 @@ class CORE_EXPORT QgsPaintEffect SIP_NODEFAULTCTORS * when drawing QPictures. This may need to be called by derived classes prior * to rendering results onto a painter. * \param painter destination painter + * + * \deprecated QGIS 3.40, use QgsPainting::drawPicture() or QgsPainting::applyScaleFixForQPictureDpi() instead. */ - void fixQPictureDpi( QPainter *painter ) const; + Q_DECL_DEPRECATED void fixQPictureDpi( QPainter *painter ) const SIP_DEPRECATED; private: diff --git a/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp b/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp index c8fada63ed5a..29bc11d6435f 100644 --- a/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp +++ b/src/core/maprenderer/qgsmaprenderercustompainterjob.cpp @@ -21,22 +21,10 @@ #include "qgsmaplayerrenderer.h" #include "qgsmaplayerlistutils_p.h" #include "qgselevationmap.h" +#include "qgspainting.h" #include -Q_GUI_EXPORT extern int qt_defaultDpiX(); -Q_GUI_EXPORT extern int qt_defaultDpiY(); - -static void _fixQPictureDPI( QPainter *p ) -{ - // QPicture makes an assumption that we drawing to it with system DPI. - // Then when being drawn, it scales the painter. The following call - // negates the effect. There is no way of setting QPicture's DPI. - // See QTBUG-20361 - p->scale( static_cast< double >( qt_defaultDpiX() ) / p->device()->logicalDpiX(), - static_cast< double >( qt_defaultDpiY() ) / p->device()->logicalDpiY() ); -} - // // QgsMapRendererAbstractCustomPainterJob // @@ -480,10 +468,7 @@ void QgsMapRendererCustomPainterJob::doRender() // if there is vector rendering we use it, else we use the raster rendering if ( job.picture ) { - mPainter->save(); - _fixQPictureDPI( mPainter ); - mPainter->drawPicture( 0, 0, *job.picture ); - mPainter->restore(); + QgsPainting::drawPicture( mPainter, QPointF( 0, 0 ), *job.picture ); } else mPainter->drawImage( 0, 0, *job.img ); @@ -491,10 +476,7 @@ void QgsMapRendererCustomPainterJob::doRender() if ( mLabelJob.picture ) { - mPainter->save(); - _fixQPictureDPI( mPainter ); - mPainter->drawPicture( 0, 0, *mLabelJob.picture ); - mPainter->restore(); + QgsPainting::drawPicture( mPainter, QPointF( 0, 0 ), *mLabelJob.picture ); } } } diff --git a/src/core/painting/qgsgeometrypaintdevice.cpp b/src/core/painting/qgsgeometrypaintdevice.cpp index 18f73665d85c..3b382078e048 100644 --- a/src/core/painting/qgsgeometrypaintdevice.cpp +++ b/src/core/painting/qgsgeometrypaintdevice.cpp @@ -19,9 +19,7 @@ #include "qgsgeos.h" #include "qgsmultipolygon.h" #include "qgsmultilinestring.h" - -Q_GUI_EXPORT extern int qt_defaultDpiX(); -Q_GUI_EXPORT extern int qt_defaultDpiY(); +#include "qgspainting.h" // // QgsGeometryPaintEngine @@ -652,18 +650,18 @@ int QgsGeometryPaintDevice::metric( PaintDeviceMetric m ) const val = static_cast< int >( mPaintEngine->geometry().boundingBox().height() ); break; case PdmWidthMM: - val = static_cast< int >( 25.4 / qt_defaultDpiX() * mPaintEngine->geometry().boundingBox().width() ); + val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiX() * mPaintEngine->geometry().boundingBox().width() ); break; case PdmHeightMM: - val = static_cast< int >( 25.4 / qt_defaultDpiY() * mPaintEngine->geometry().boundingBox().height() ); + val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiY() * mPaintEngine->geometry().boundingBox().height() ); break; case PdmDpiX: case PdmPhysicalDpiX: - val = qt_defaultDpiX(); + val = QgsPainting::qtDefaultDpiX(); break; case PdmDpiY: case PdmPhysicalDpiY: - val = qt_defaultDpiY(); + val = QgsPainting::qtDefaultDpiY(); break; case PdmNumColors: val = 16777216; diff --git a/src/core/painting/qgsmaskpaintdevice.cpp b/src/core/painting/qgsmaskpaintdevice.cpp index 5dd3ca54821a..e13ac0546a2d 100644 --- a/src/core/painting/qgsmaskpaintdevice.cpp +++ b/src/core/painting/qgsmaskpaintdevice.cpp @@ -14,10 +14,7 @@ ***************************************************************************/ #include "qgsmaskpaintdevice.h" - - -Q_GUI_EXPORT extern int qt_defaultDpiX(); -Q_GUI_EXPORT extern int qt_defaultDpiY(); +#include "qgspainting.h" ///@cond PRIVATE @@ -85,18 +82,18 @@ int QgsMaskPaintDevice::metric( PaintDeviceMetric m ) const val = static_cast< int >( mPaintEngine->maskPainterPath().boundingRect().height() ); break; case PdmWidthMM: - val = static_cast< int >( 25.4 / qt_defaultDpiX() * mPaintEngine->maskPainterPath().boundingRect().width() ); + val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiX() * mPaintEngine->maskPainterPath().boundingRect().width() ); break; case PdmHeightMM: - val = static_cast< int >( 25.4 / qt_defaultDpiY() * mPaintEngine->maskPainterPath().boundingRect().height() ); + val = static_cast< int >( 25.4 / QgsPainting::qtDefaultDpiY() * mPaintEngine->maskPainterPath().boundingRect().height() ); break; case PdmDpiX: case PdmPhysicalDpiX: - val = qt_defaultDpiX(); + val = QgsPainting::qtDefaultDpiX(); break; case PdmDpiY: case PdmPhysicalDpiY: - val = qt_defaultDpiY(); + val = QgsPainting::qtDefaultDpiY(); break; case PdmNumColors: val = 16777216; diff --git a/src/core/painting/qgspainting.cpp b/src/core/painting/qgspainting.cpp index ea4dfb3799c7..6ed80c5f99c0 100644 --- a/src/core/painting/qgspainting.cpp +++ b/src/core/painting/qgspainting.cpp @@ -18,6 +18,9 @@ #include +Q_GUI_EXPORT extern int qt_defaultDpiX(); +Q_GUI_EXPORT extern int qt_defaultDpiY(); + QPainter::CompositionMode QgsPainting::getCompositionMode( Qgis::BlendMode blendMode ) { // Map Qgis::BlendMode::Normal to QPainter::CompositionMode @@ -219,3 +222,36 @@ bool QgsPainting::drawTriangleUsingTexture( QPainter *painter, const QPolygonF & return true; } + +int QgsPainting::qtDefaultDpiX() +{ + return qt_defaultDpiX(); +} + +int QgsPainting::qtDefaultDpiY() +{ + return qt_defaultDpiY(); +} + +void QgsPainting::applyScaleFixForQPictureDpi( QPainter *painter ) +{ + // QPicture makes an assumption that we drawing to it with system DPI. + // Then when being drawn, it scales the painter. The following call + // negates the effect. There is no way of setting QPicture's DPI. + // See QTBUG-20361 + painter->scale( static_cast< double >( QgsPainting::qtDefaultDpiX() ) / painter->device()->logicalDpiX(), + static_cast< double >( QgsPainting::qtDefaultDpiY() ) / painter->device()->logicalDpiY() ); +} + +void QgsPainting::drawPicture( QPainter *painter, const QPointF &point, const QPicture &picture ) +{ + // QPicture makes an assumption that we drawing to it with system DPI. + // Then when being drawn, it scales the painter. The following call + // negates the effect. There is no way of setting QPicture's DPI. + // See QTBUG-20361 + const double xScale = static_cast< double >( QgsPainting::qtDefaultDpiX() ) / painter->device()->logicalDpiX(); + const double yScale = static_cast< double >( QgsPainting::qtDefaultDpiY() ) / painter->device()->logicalDpiY(); + painter->scale( xScale, yScale ); + painter->drawPicture( QPointF( point.x() / xScale, point.y() / yScale ), picture ); + painter->scale( 1 / xScale, 1 / yScale ); +} diff --git a/src/core/painting/qgspainting.h b/src/core/painting/qgspainting.h index cd8243c596cb..660998911d4b 100644 --- a/src/core/painting/qgspainting.h +++ b/src/core/painting/qgspainting.h @@ -98,6 +98,47 @@ class CORE_EXPORT QgsPainting float textureX3, float textureY3 ); + /** + * Returns the default Qt horizontal DPI. + * + * \note This method proxies the internal Qt qt_defaultDpiX() function. + * + * \see qtDefaultDpiY() + * \since QGIS 3.40 + */ + static int qtDefaultDpiX(); + + /** + * Returns the default Qt vertical DPI. + * + * \note This method proxies the internal Qt qt_defaultDpiY() function. + * + * \see qtDefaultDpiX() + * \since QGIS 3.40 + */ + static int qtDefaultDpiY(); + + /** + * Applies a workaround to a \a painter to avoid an issue with incorrect scaling + * when drawing QPictures. + * + * \note This is a low-level method, which alters the \a painter state and relies on the + * caller saving/restoring painter state accordingly. Consider using + * the high-level drawPicture() method instead. + * + * \see drawPicture() + * \since QGIS 3.40 + */ + static void applyScaleFixForQPictureDpi( QPainter *painter ); + + /** + * Draws a picture onto a \a painter, correctly applying workarounds to avoid issues + * with incorrect scaling. + * + * \see applyScaleFixForQPictureDpi() + * \since QGIS 3.40 + */ + static void drawPicture( QPainter *painter, const QPointF &point, const QPicture &picture ); }; #endif // QGSPAINTING_H diff --git a/src/core/qgsmapsettings.cpp b/src/core/qgsmapsettings.cpp index c36e4d23a62f..bb492d424b63 100644 --- a/src/core/qgsmapsettings.cpp +++ b/src/core/qgsmapsettings.cpp @@ -29,12 +29,10 @@ #include "qgscoordinatetransform.h" #include "qgsellipsoidutils.h" #include "qgsunittypes.h" - -Q_GUI_EXPORT extern int qt_defaultDpiX(); - +#include "qgspainting.h" QgsMapSettings::QgsMapSettings() - : mDpi( qt_defaultDpiX() ) // DPI that will be used by default for QImage instances + : mDpi( QgsPainting::qtDefaultDpiX() ) // DPI that will be used by default for QImage instances , mSize( QSize( 0, 0 ) ) , mBackgroundColor( Qt::white ) , mSelectionColor( Qt::yellow ) diff --git a/src/core/symbology/qgsmarkersymbollayer.cpp b/src/core/symbology/qgsmarkersymbollayer.cpp index 7bc65562deea..f372146dce7b 100644 --- a/src/core/symbology/qgsmarkersymbollayer.cpp +++ b/src/core/symbology/qgsmarkersymbollayer.cpp @@ -29,6 +29,7 @@ #include "qgsfillsymbol.h" #include "qgsfontmanager.h" #include "qgscolorutils.h" +#include "qgspainting.h" #include #include @@ -40,22 +41,8 @@ #include -Q_GUI_EXPORT extern int qt_defaultDpiX(); -Q_GUI_EXPORT extern int qt_defaultDpiY(); - static constexpr int MAX_FONT_CHARACTER_SIZE_IN_PIXELS = 500; -static void _fixQPictureDPI( QPainter *p ) -{ - // QPicture makes an assumption that we drawing to it with system DPI. - // Then when being drawn, it scales the painter. The following call - // negates the effect. There is no way of setting QPicture's DPI. - // See QTBUG-20361 - p->scale( static_cast< double >( qt_defaultDpiX() ) / p->device()->logicalDpiX(), - static_cast< double >( qt_defaultDpiY() ) / p->device()->logicalDpiY() ); -} - - ////// @@ -2469,9 +2456,7 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext ( context.renderContext().flags() & Qgis::RenderContextFlag::RenderBlocking ), evaluatedParameters ); if ( pct.width() > 1 ) { - const QgsScopedQPainterState painterPictureState( p ); - _fixQPictureDPI( p ); - p->drawPicture( 0, 0, pct ); + QgsPainting::drawPicture( p, QPointF( 0, 0 ), pct ); } } diff --git a/src/core/textrenderer/qgstextrenderer.cpp b/src/core/textrenderer/qgstextrenderer.cpp index 1f8876d959d8..203cfa78e75a 100644 --- a/src/core/textrenderer/qgstextrenderer.cpp +++ b/src/core/textrenderer/qgstextrenderer.cpp @@ -29,23 +29,11 @@ #include "qgstextmetrics.h" #include "qgstextrendererutils.h" #include "qgsgeos.h" - +#include "qgspainting.h" #include #include -Q_GUI_EXPORT extern int qt_defaultDpiX(); -Q_GUI_EXPORT extern int qt_defaultDpiY(); - -static void _fixQPictureDPI( QPainter *p ) -{ - // QPicture makes an assumption that we drawing to it with system DPI. - // Then when being drawn, it scales the painter. The following call - // negates the effect. There is no way of setting QPicture's DPI. - // See QTBUG-20361 - p->scale( static_cast< double >( qt_defaultDpiX() ) / p->device()->logicalDpiX(), - static_cast< double >( qt_defaultDpiY() ) / p->device()->logicalDpiY() ); -} Qgis::TextHorizontalAlignment QgsTextRenderer::convertQtHAlignment( Qt::Alignment alignment ) { @@ -731,7 +719,7 @@ double QgsTextRenderer::drawBuffer( QgsRenderContext &context, const QgsTextRend // scale for any print output or image saving @ specific dpi p->scale( component.dpiRatio, component.dpiRatio ); - _fixQPictureDPI( p ); + QgsPainting::applyScaleFixForQPictureDpi( p ); p->drawPicture( 0, 0, buffPict ); return advance / scaleFactor; @@ -1408,7 +1396,7 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer // scale for any print output or image saving @ specific dpi p->scale( component.dpiRatio, component.dpiRatio ); - _fixQPictureDPI( p ); + QgsPainting::applyScaleFixForQPictureDpi( p ); p->drawPicture( 0, 0, shapePict ); p->setCompositionMode( QPainter::CompositionMode_SourceOver ); // just to be sure break; @@ -1931,7 +1919,7 @@ void QgsTextRenderer::drawTextInternalHorizontal( QgsRenderContext &context, con case Qgis::TextRenderFormat::AlwaysOutlines: { // draw outlined text - _fixQPictureDPI( context.painter() ); + QgsPainting::applyScaleFixForQPictureDpi( context.painter() ); context.painter()->drawPicture( 0, 0, textPict ); break; } @@ -2211,7 +2199,7 @@ void QgsTextRenderer::drawTextInternalVertical( QgsRenderContext &context, const { // draw outlined text context.painter()->translate( 0, currentBlockYOffset ); - _fixQPictureDPI( context.painter() ); + QgsPainting::applyScaleFixForQPictureDpi( context.painter() ); context.painter()->drawPicture( 0, 0, textPict ); currentBlockYOffset += partYOffset; break; diff --git a/src/gui/layout/qgslayoutlegendwidget.cpp b/src/gui/layout/qgslayoutlegendwidget.cpp index 0829ed2d47ec..6139f37b65b9 100644 --- a/src/gui/layout/qgslayoutlegendwidget.cpp +++ b/src/gui/layout/qgslayoutlegendwidget.cpp @@ -43,6 +43,7 @@ #include "qgslayoutundostack.h" #include "qgsexpressionfinder.h" #include "qgscolorramplegendnode.h" +#include "qgspainting.h" #include #include @@ -51,8 +52,6 @@ ///@cond PRIVATE -Q_GUI_EXPORT extern int qt_defaultDpiX(); - static int _unfilteredLegendNodeIndex( QgsLayerTreeModelLegendNode *legendNode ) { return legendNode->model()->layerOriginalLegendNodes( legendNode->layerNode() ).indexOf( legendNode ); @@ -1411,7 +1410,7 @@ void QgsLayoutLegendWidget::setLegendMapViewData() { if ( mLegend->linkedMap() ) { - int dpi = qt_defaultDpiX(); + const int dpi = QgsPainting::qtDefaultDpiX(); QgsLayoutMeasurementConverter measurementConverter = QgsLayoutMeasurementConverter(); measurementConverter.setDpi( dpi ); double mapWidth = measurementConverter.convert( mLegend->linkedMap()->sizeWithUnits(), Qgis::LayoutUnit::Pixels ).width();