From 60894cebf164e7c90f4f01b590a619c08868aff0 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 7 Jun 2024 13:15:38 +1000 Subject: [PATCH] When exporting layouts to PDF/SVG, always simplify mask clip paths This results in much smaller output file sizes, and files which load much quicker in PDF viewers/editors Refs #50734 Refs #54788 --- src/core/layout/qgslayoutexporter.cpp | 12 ++++++++++++ src/core/layout/qgslayoutexporter.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/core/layout/qgslayoutexporter.cpp b/src/core/layout/qgslayoutexporter.cpp index abd15200b552..1ab7190f3358 100644 --- a/src/core/layout/qgslayoutexporter.cpp +++ b/src/core/layout/qgslayoutexporter.cpp @@ -552,6 +552,7 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToPdf( const QString &f ( void )contextRestorer; mLayout->renderContext().setDpi( settings.dpi ); mLayout->renderContext().setPredefinedScales( settings.predefinedMapScales ); + mLayout->renderContext().setMaskSettings( createExportMaskSettings() ); if ( settings.simplifyGeometries ) { @@ -777,6 +778,7 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToPdf( QgsAbstractLayou iterator->layout()->renderContext().setFlags( settings.flags ); iterator->layout()->renderContext().setPredefinedScales( settings.predefinedMapScales ); + iterator->layout()->renderContext().setMaskSettings( createExportMaskSettings() ); if ( settings.simplifyGeometries ) { @@ -1026,6 +1028,7 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::exportToSvg( const QString &f mLayout->renderContext().setFlag( QgsLayoutRenderContext::FlagForceVectorOutput, settings.forceVectorOutput ); mLayout->renderContext().setTextRenderFormat( s.textRenderFormat ); mLayout->renderContext().setPredefinedScales( settings.predefinedMapScales ); + mLayout->renderContext().setMaskSettings( createExportMaskSettings() ); if ( settings.simplifyGeometries ) { @@ -1911,6 +1914,15 @@ QgsVectorSimplifyMethod QgsLayoutExporter::createExportSimplifyMethod() return simplifyMethod; } +QgsMaskRenderSettings QgsLayoutExporter::createExportMaskSettings() +{ + QgsMaskRenderSettings settings; + // this is quite a conservative setting -- I think we could make this more aggressive and get smaller file sizes + // without too much loss of quality... + settings.setSimplificationTolerance( 0.5 ); + return settings; +} + void QgsLayoutExporter::computeWorldFileParameters( double &a, double &b, double &c, double &d, double &e, double &f, double dpi ) const { if ( !mLayout ) diff --git a/src/core/layout/qgslayoutexporter.h b/src/core/layout/qgslayoutexporter.h index 3c92ead162ed..51005785e4b0 100644 --- a/src/core/layout/qgslayoutexporter.h +++ b/src/core/layout/qgslayoutexporter.h @@ -779,6 +779,7 @@ class CORE_EXPORT QgsLayoutExporter ExportResult handleLayeredExport( const QList &items, const std::function &exportFunc ); static QgsVectorSimplifyMethod createExportSimplifyMethod(); + static QgsMaskRenderSettings createExportMaskSettings(); friend class TestQgsLayout; friend class TestQgsLayoutExporter;