diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp index ec192f7a92d..c4fa171147a 100644 --- a/src/app/layout/qgslayoutdesignerdialog.cpp +++ b/src/app/layout/qgslayoutdesignerdialog.cpp @@ -65,6 +65,7 @@ #include "qgsreportorganizerwidget.h" #include "qgsreadwritecontext.h" #include "ui_qgssvgexportoptions.h" +#include "ui_qgspdfexportoptions.h" #include "qgsproxyprogresstask.h" #include "ui_defaults.h" @@ -2065,13 +2066,15 @@ void QgsLayoutDesignerDialog::exportToPdf() mView->setPaintingEnabled( false ); QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor ); + + QgsLayoutExporter::PdfExportSettings pdfSettings; + if ( !getPdfExportSettings( pdfSettings ) ) + return; + QgsProxyProgressTask *proxyTask = new QgsProxyProgressTask( tr( "Exporting “%1”" ).arg( mMasterLayout->name() ) ); QgsApplication::taskManager()->addTask( proxyTask ); - QgsLayoutExporter::PdfExportSettings pdfSettings; pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool(); - pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool(); - pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat(); // force a refresh, to e.g. update data defined properties, tables, etc mLayout->refresh(); @@ -2968,9 +2971,10 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf() QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor ); QgsLayoutExporter::PdfExportSettings pdfSettings; + if ( !getPdfExportSettings( pdfSettings ) ) + return; + pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool(); - pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool(); - pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat(); QString error; std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >(); @@ -3345,17 +3349,15 @@ void QgsLayoutDesignerDialog::exportReportToPdf() QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor ); bool rasterize = false; - bool forceVectorOutput = false; if ( mLayout ) { rasterize = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool(); - forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool(); } QgsLayoutExporter::PdfExportSettings pdfSettings; - // TODO - show a dialog allowing users to control these settings on a per-output basis + if ( !getPdfExportSettings( pdfSettings ) ) + return; + pdfSettings.rasterizeWholeImage = rasterize; - pdfSettings.forceVectorOutput = forceVectorOutput; - pdfSettings.textRenderFormat = mLayout->project()->labelingEngineSettings().defaultTextRenderFormat(); QString error; std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >(); @@ -4047,6 +4049,55 @@ bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExport return true; } +bool QgsLayoutDesignerDialog::getPdfExportSettings( QgsLayoutExporter::PdfExportSettings &settings ) +{ + QgsRenderContext::TextRenderFormat prevTextRenderFormat = mMasterLayout->layoutProject()->labelingEngineSettings().defaultTextRenderFormat(); + bool previousForceVector = false; + bool includeMetadata = true; + if ( mLayout ) + { + mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool(); + includeMetadata = mLayout->customProperty( QStringLiteral( "pdfIncludeMetadata" ), 1 ).toBool(); + const int prevLayoutSettingLabelsAsOutlines = mLayout->customProperty( QStringLiteral( "pdfTextFormat" ), -1 ).toInt(); + if ( prevLayoutSettingLabelsAsOutlines >= 0 ) + { + // previous layout setting takes default over project setting + prevTextRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( prevLayoutSettingLabelsAsOutlines ); + } + } + + // open options dialog + QDialog dialog; + Ui::QgsPdfExportOptionsDialog options; + options.setupUi( &dialog ); + + options.mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines ); + options.mTextRenderFormatComboBox->addItem( tr( "Always Export Text as Text Objects" ), QgsRenderContext::TextFormatAlwaysText ); + + options.mTextRenderFormatComboBox->setCurrentIndex( options.mTextRenderFormatComboBox->findData( prevTextRenderFormat ) ); + options.mForceVectorCheckBox->setChecked( previousForceVector ); + options.mIncludeMetadataCheckbox->setChecked( includeMetadata ); + + if ( dialog.exec() != QDialog::Accepted ) + return false; + + includeMetadata = options.mIncludeMetadataCheckbox->isChecked(); + QgsRenderContext::TextRenderFormat textRenderFormat = static_cast< QgsRenderContext::TextRenderFormat >( options.mTextRenderFormatComboBox->currentData().toInt() ); + + if ( mLayout ) + { + //save dialog settings + mLayout->setCustomProperty( QStringLiteral( "pdfIncludeMetadata" ), includeMetadata ? 1 : 0 ); + mLayout->setCustomProperty( QStringLiteral( "pdfTextFormat" ), static_cast< int >( textRenderFormat ) ); + } + + settings.forceVectorOutput = options.mForceVectorCheckBox->isChecked(); + settings.exportMetadata = includeMetadata; + settings.textRenderFormat = textRenderFormat; + + return true; +} + void QgsLayoutDesignerDialog::toggleAtlasControls( bool atlasEnabled ) { //preview defaults to unchecked diff --git a/src/app/layout/qgslayoutdesignerdialog.h b/src/app/layout/qgslayoutdesignerdialog.h index 39ee13a5d72..cbdd54fd2a7 100644 --- a/src/app/layout/qgslayoutdesignerdialog.h +++ b/src/app/layout/qgslayoutdesignerdialog.h @@ -505,6 +505,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB bool showFileSizeWarning(); bool getRasterExportSettings( QgsLayoutExporter::ImageExportSettings &settings, QSize &imageSize ); bool getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings ); + bool getPdfExportSettings( QgsLayoutExporter::PdfExportSettings &settings ); void toggleAtlasActions( bool enabled ); diff --git a/src/ui/layout/qgspdfexportoptions.ui b/src/ui/layout/qgspdfexportoptions.ui new file mode 100644 index 00000000000..73f69df9c8c --- /dev/null +++ b/src/ui/layout/qgspdfexportoptions.ui @@ -0,0 +1,129 @@ + + + QgsPdfExportOptionsDialog + + + + 0 + 0 + 489 + 190 + + + + PDF Export Options + + + + + + PDF Options + + + + + + Export RDF metadata + + + true + + + + + + + + + + Text export + + + + + + + If checked, the layout will always be kept as vector objects when exported to a compatible format, even if the appearance of the resultant file does not match the layouts settings. If unchecked, some elements in the layout may be rasterized in order to keep their appearance intact. + + + Always export as vectors + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + QgsCollapsibleGroupBoxBasic + QGroupBox +
qgscollapsiblegroupbox.h
+ 1 +
+
+ + mForceVectorCheckBox + mIncludeMetadataCheckbox + mTextRenderFormatComboBox + + + + + buttonBox + accepted() + QgsPdfExportOptionsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + QgsPdfExportOptionsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +