Skip to content

Commit

Permalink
When exporting layouts to PDF/SVG, always simplify mask clip paths
Browse files Browse the repository at this point in the history
This results in much smaller output file sizes, and files which
load much quicker in PDF viewers/editors

Refs qgis#50734
Refs qgis#54788
  • Loading branch information
nyalldawson committed Jun 10, 2024
1 parent a79764f commit 1581c62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/layout/qgslayoutexporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutexporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ class CORE_EXPORT QgsLayoutExporter
ExportResult handleLayeredExport( const QList<QGraphicsItem *> &items, const std::function<QgsLayoutExporter::ExportResult( unsigned int layerId, const QgsLayoutItem::ExportLayerDetail &layerDetails )> &exportFunc );

static QgsVectorSimplifyMethod createExportSimplifyMethod();
static QgsMaskRenderSettings createExportMaskSettings();
friend class TestQgsLayout;
friend class TestQgsLayoutExporter;

Expand Down

0 comments on commit 1581c62

Please sign in to comment.