Skip to content
Permalink
Browse files
Improve PDF export
We no longer require paint engine hack for Qt 6.3 or KDE's fork, which
now means that pattern brushes and gradients are correctly exported
to PDF without forced rasterization.

Results in higher quality PDF outputs with smaller file sizes

Thanks to KDAB for the fix!
  • Loading branch information
nyalldawson committed Nov 4, 2021
1 parent 1495cd5 commit cf467c4e179a536b6799a282895f071c7faa7994
Showing with 22 additions and 0 deletions.
  1. +5 −0 python/core/auto_generated/qgspaintenginehack.sip.in
  2. +4 −0 src/core/layout/qgslayoutexporter.cpp
  3. +10 −0 src/core/qgspaintenginehack.cpp
  4. +3 −0 src/core/qgspaintenginehack.h
@@ -12,6 +12,11 @@ class QgsPaintEngineHack : QPaintEngine
{
%Docstring(signature="appended")
Hack to workaround Qt #5114 by disabling PatternTransform

.. note::

This is not required for builds based on Qt 6.3 or later, or Qt 5.15 builds
using KDE's maintained fork. On these versions the class has no effect.
%End

%TypeHeaderCode
@@ -1219,7 +1219,11 @@ void QgsLayoutExporter::preparePrintAsPdf( QgsLayout *layout, QPrinter &printer,
// May not work on Windows or non-X11 Linux. Works fine on Mac using QPrinter::NativeFormat
//printer.setFontEmbeddingEnabled( true );

#if defined(WITH_QT5_KDE_FORK) || QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
// paint engine hack not required, fixed upstream
#else
QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() );
#endif
}

void QgsLayoutExporter::preparePrint( QgsLayout *layout, QPrinter &printer, bool setFirstPageSize )
@@ -16,10 +16,14 @@
***************************************************************************/

#include "qgspaintenginehack.h"
#include "qgsconfig.h"

// Hack to workaround Qt #5114 by disabling PatternTransform
void QgsPaintEngineHack::fixFlags()
{
#if defined(WITH_QT5_KDE_FORK) || QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
// not required, fixed upstream
#else
gccaps = PaintEngineFeatures();
gccaps |= ( QPaintEngine::PrimitiveTransform
// | QPaintEngine::PatternTransform
@@ -41,13 +45,19 @@ void QgsPaintEngineHack::fixFlags()
| QPaintEngine::RasterOpModes
| QPaintEngine::PaintOutsidePaintEvent
);
#endif
}

void QgsPaintEngineHack::fixEngineFlags( QPaintEngine *engine )
{
#if defined(WITH_QT5_KDE_FORK) || QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
// not required, fixed upstream
( void )engine;
#else
if ( !engine )
return;

QgsPaintEngineHack *hack = static_cast<QgsPaintEngineHack *>( engine );
hack->fixFlags();
#endif
}
@@ -21,6 +21,9 @@
/**
* \ingroup core
* \brief Hack to workaround Qt #5114 by disabling PatternTransform
*
* \note This is not required for builds based on Qt 6.3 or later, or Qt 5.15 builds
* using KDE's maintained fork. On these versions the class has no effect.
*/
class CORE_EXPORT QgsPaintEngineHack : public QPaintEngine
{

0 comments on commit cf467c4

Please sign in to comment.