Skip to content

Commit

Permalink
[layouts] Fix fragile option to export text as text in SVG exports
Browse files Browse the repository at this point in the history
Refs #3975

(cherry picked from commit 1d04105)
  • Loading branch information
nyalldawson committed Dec 11, 2018
1 parent 8053198 commit 0e694ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
33 changes: 9 additions & 24 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,17 +2169,12 @@ void QgsLayoutDesignerDialog::exportToSvg()
outputFileName += QLatin1String( ".svg" );
}

bool prevSettingLabelsAsOutlines = mLayout->project()->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true );
setLastExportPath( outputFileName );

QgsLayoutExporter::SvgExportSettings svgSettings;
bool exportAsText = false;
if ( !getSvgExportSettings( svgSettings, exportAsText ) )
if ( !getSvgExportSettings( svgSettings ) )
return;

//temporarily override label draw outlines setting
mLayout->project()->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), exportAsText );

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );

Expand Down Expand Up @@ -2245,7 +2240,6 @@ void QgsLayoutDesignerDialog::exportToSvg()
}

mView->setPaintingEnabled( true );
mLayout->project()->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), prevSettingLabelsAsOutlines );
}

void QgsLayoutDesignerDialog::atlasPreviewTriggered( bool checked )
Expand Down Expand Up @@ -2759,15 +2753,10 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
return;
}

bool prevSettingLabelsAsOutlines = mLayout->project()->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true );
QgsLayoutExporter::SvgExportSettings svgSettings;
bool exportAsText = false;
if ( !getSvgExportSettings( svgSettings, exportAsText ) )
if ( !getSvgExportSettings( svgSettings ) )
return;

//temporarily override label draw outlines setting
mLayout->project()->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), exportAsText );

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );

Expand Down Expand Up @@ -2863,7 +2852,6 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
}

mView->setPaintingEnabled( true );
mLayout->project()->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), prevSettingLabelsAsOutlines );
}

void QgsLayoutDesignerDialog::exportAtlasToPdf()
Expand Down Expand Up @@ -3223,17 +3211,12 @@ void QgsLayoutDesignerDialog::exportReportToSvg()
QgisApp::instance()->activateWindow();
this->raise();
#endif
bool prevSettingLabelsAsOutlines = mMasterLayout->layoutProject()->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true );
setLastExportPath( outputFileName );

QgsLayoutExporter::SvgExportSettings svgSettings;
bool exportAsText = false;
if ( !getSvgExportSettings( svgSettings, exportAsText ) )
if ( !getSvgExportSettings( svgSettings ) )
return;

//temporarily override label draw outlines setting
mMasterLayout->layoutProject()->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), exportAsText );

mView->setPaintingEnabled( false );
QgsTemporaryCursorOverride cursorOverride( Qt::BusyCursor );

Expand Down Expand Up @@ -3328,7 +3311,6 @@ void QgsLayoutDesignerDialog::exportReportToSvg()
}

mView->setPaintingEnabled( true );
mMasterLayout->layoutProject()->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), prevSettingLabelsAsOutlines );
}

void QgsLayoutDesignerDialog::exportReportToPdf()
Expand Down Expand Up @@ -3974,10 +3956,10 @@ bool QgsLayoutDesignerDialog::getRasterExportSettings( QgsLayoutExporter::ImageE
return true;
}

bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings, bool &exportAsText )
bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings )
{
bool groupLayers = false;
bool prevSettingLabelsAsOutlines = mMasterLayout->layoutProject()->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true );
bool prevSettingLabelsAsOutlines = false;
bool clipToContent = false;
double marginTop = 0.0;
double marginRight = 0.0;
Expand All @@ -4001,6 +3983,7 @@ bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExport
bottomMargin = mLayout->customProperty( QStringLiteral( "svgCropMarginBottom" ), 0 ).toInt();
leftMargin = mLayout->customProperty( QStringLiteral( "svgCropMarginLeft" ), 0 ).toInt();
includeMetadata = mLayout->customProperty( QStringLiteral( "svgIncludeMetadata" ), 1 ).toBool();
prevSettingLabelsAsOutlines = mLayout->customProperty( QStringLiteral( "svgRenderTextAsOutlines" ), 1 ).toBool();
}

// open options dialog
Expand All @@ -4027,6 +4010,7 @@ bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExport
marginBottom = options.mBottomMarginSpinBox->value();
marginLeft = options.mLeftMarginSpinBox->value();
includeMetadata = options.mIncludeMetadataCheckbox->isChecked();
QgsRenderContext::TextRenderFormat textRenderFormat = options.chkTextAsOutline->isChecked() ? QgsRenderContext::TextFormatAlwaysOutlines : QgsRenderContext::TextFormatAlwaysText;

if ( mLayout )
{
Expand All @@ -4038,15 +4022,16 @@ bool QgsLayoutDesignerDialog::getSvgExportSettings( QgsLayoutExporter::SvgExport
mLayout->setCustomProperty( QStringLiteral( "svgCropMarginBottom" ), marginBottom );
mLayout->setCustomProperty( QStringLiteral( "svgCropMarginLeft" ), marginLeft );
mLayout->setCustomProperty( QStringLiteral( "svgIncludeMetadata" ), includeMetadata ? 1 : 0 );
mLayout->setCustomProperty( QStringLiteral( "svgRenderTextAsOutlines" ), textRenderFormat == QgsRenderContext::TextFormatAlwaysOutlines ? 1 : 0 );
}

settings.cropToContents = clipToContent;
settings.cropMargins = QgsMargins( marginLeft, marginTop, marginRight, marginBottom );
settings.forceVectorOutput = options.mForceVectorCheckBox->isChecked();
settings.exportAsLayers = groupLayers;
settings.exportMetadata = includeMetadata;
settings.textRenderFormat = textRenderFormat;

exportAsText = options.chkTextAsOutline->isChecked();
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerB

bool showFileSizeWarning();
bool getRasterExportSettings( QgsLayoutExporter::ImageExportSettings &settings, QSize &imageSize );
bool getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings, bool &exportAsText );
bool getSvgExportSettings( QgsLayoutExporter::SvgExportSettings &settings );

void toggleAtlasActions( bool enabled );

Expand Down

0 comments on commit 0e694ea

Please sign in to comment.