Skip to content

Commit

Permalink
Improve PDF export
Browse files Browse the repository at this point in the history
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 cf467c4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/core/auto_generated/qgspaintenginehack.sip.in
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/core/layout/qgslayoutexporter.cpp
Expand Up @@ -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 )
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgspaintenginehack.cpp
Expand Up @@ -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
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions src/core/qgspaintenginehack.h
Expand Up @@ -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
{
Expand Down

0 comments on commit cf467c4

Please sign in to comment.