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
  • Loading branch information
nyalldawson committed Dec 11, 2018
1 parent ea069ed commit 1921181
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 @@ -2167,17 +2167,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 @@ -2243,7 +2238,6 @@ void QgsLayoutDesignerDialog::exportToSvg()
}

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

void QgsLayoutDesignerDialog::atlasPreviewTriggered( bool checked )
Expand Down Expand Up @@ -2757,15 +2751,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 @@ -2861,7 +2850,6 @@ void QgsLayoutDesignerDialog::exportAtlasToSvg()
}

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

void QgsLayoutDesignerDialog::exportAtlasToPdf()
Expand Down Expand Up @@ -3221,17 +3209,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 @@ -3326,7 +3309,6 @@ void QgsLayoutDesignerDialog::exportReportToSvg()
}

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

void QgsLayoutDesignerDialog::exportReportToPdf()
Expand Down Expand Up @@ -3972,10 +3954,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 @@ -3999,6 +3981,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 @@ -4025,6 +4008,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 @@ -4036,15 +4020,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 1921181

Please sign in to comment.