From c1d80ed6a6bdac03ed9d02d2f5bbaca17d2e1b8f Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Fri, 13 Jun 2014 10:13:55 -0600 Subject: [PATCH] Initial fix for #3975, label engine vectorizing texts in SVG and PDF output - Add labeling engine option to render text-as-text - Default is still text-as-outlines (vectorized), due to differences between text (as text) and buffer (as outline) methods - Good output with printing to PDF (searchable, selectable text and embedded fonts) - OK output with SVG, but differences between text (as text) and buffer (as outline) methods Does not yet include unit tests or auto-setting of text-as-text for SVG output --- python/core/qgspallabeling.sip | 4 + src/app/qgslabelengineconfigdialog.cpp | 3 + src/core/qgspallabeling.cpp | 35 +++++--- src/core/qgspallabeling.h | 5 ++ src/ui/qgsengineconfigdialog.ui | 119 +++++++++++++------------ 5 files changed, 100 insertions(+), 66 deletions(-) diff --git a/python/core/qgspallabeling.sip b/python/core/qgspallabeling.sip index d321ee7dc72..db506d9c577 100644 --- a/python/core/qgspallabeling.sip +++ b/python/core/qgspallabeling.sip @@ -666,6 +666,10 @@ class QgsPalLabeling : QgsLabelingEngineInterface bool isShowingPartialsLabels() const; void setShowingPartialsLabels( bool showing ); + //! @note added in 2.4 + bool isDrawingOutlineLabels() const; + void setDrawingOutlineLabels( bool outline ); + // implemented methods from labeling engine interface //! called when we're going to start with rendering diff --git a/src/app/qgslabelengineconfigdialog.cpp b/src/app/qgslabelengineconfigdialog.cpp index eb8b4579c1e..730d86a9e37 100644 --- a/src/app/qgslabelengineconfigdialog.cpp +++ b/src/app/qgslabelengineconfigdialog.cpp @@ -46,6 +46,7 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget* parent ) mShadowDebugRectChkBox->setChecked( lbl.isShowingShadowRectangles() ); chkShowPartialsLabels->setChecked( lbl.isShowingPartialsLabels() ); + mDrawOutlinesChkBox->setChecked( lbl.isDrawingOutlineLabels() ); } @@ -64,6 +65,7 @@ void QgsLabelEngineConfigDialog::onOK() lbl.setShowingShadowRectangles( mShadowDebugRectChkBox->isChecked() ); lbl.setShowingAllLabels( chkShowAllLabels->isChecked() ); lbl.setShowingPartialsLabels( chkShowPartialsLabels->isChecked() ); + lbl.setDrawingOutlineLabels( mDrawOutlinesChkBox->isChecked() ); lbl.saveEngineSettings(); @@ -81,4 +83,5 @@ void QgsLabelEngineConfigDialog::setDefaults() chkShowAllLabels->setChecked( false ); mShadowDebugRectChkBox->setChecked( false ); chkShowPartialsLabels->setChecked( p.getShowPartial() ); + mDrawOutlinesChkBox->setChecked( true ); } diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index aaceaa769d8..bd3a49725cf 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -3211,6 +3211,7 @@ QgsPalLabeling::QgsPalLabeling() mShowingShadowRects = false; mShowingAllLabels = false; mShowingPartialsLabels = p.getShowPartial(); + mDrawOutlineLabels = true; } QgsPalLabeling::~QgsPalLabeling() @@ -4443,6 +4444,11 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con textp.setPen( Qt::NoPen ); textp.setBrush( tmpLyr.textColor ); textp.drawPath( path ); + // TODO: why are some font settings lost on drawPicture() when using drawText() inside QPicture? + // e.g. some capitalization options, but not others + //textp.setFont( tmpLyr.textFont ); + //textp.setPen( tmpLyr.textColor ); + //textp.drawText( 0, 0, component.text() ); textp.end(); if ( tmpLyr.shadowDraw && tmpLyr.shadowUnder == QgsPalLayerSettings::ShadowText ) @@ -4459,20 +4465,24 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QgsRenderContext& con { painter->setCompositionMode( tmpLyr.blendMode ); } -// painter->setPen( Qt::NoPen ); -// painter->setBrush( tmpLyr.textColor ); -// painter->drawPath( path ); // scale for any print output or image saving @ specific dpi painter->scale( component.dpiRatio(), component.dpiRatio() ); - _fixQPictureDPI( painter ); - painter->drawPicture( 0, 0, textPict ); - - // regular text draw, for testing optimization -// painter->setFont( tmpLyr.textFont ); -// painter->setPen( tmpLyr.textColor ); -// painter->drawText( 0, 0, multiLineList.at( i ) ); + if ( mDrawOutlineLabels ) + { + // draw outlined text + _fixQPictureDPI( painter ); + painter->drawPicture( 0, 0, textPict ); + } + else + { + // draw text as text (for SVG and PDF exports) + painter->setFont( tmpLyr.textFont ); + painter->setPen( tmpLyr.textColor ); + painter->setRenderHint( QPainter::TextAntialiasing ); + painter->drawText( 0, 0, component.text() ); + } } painter->restore(); } @@ -5004,6 +5014,8 @@ void QgsPalLabeling::loadEngineSettings() "PAL", "/ShowingAllLabels", false, &saved ); mShowingPartialsLabels = QgsProject::instance()->readBoolEntry( "PAL", "/ShowingPartialsLabels", p.getShowPartial(), &saved ); + mDrawOutlineLabels = QgsProject::instance()->readBoolEntry( + "PAL", "/DrawOutlineLabels", true, &saved ); } void QgsPalLabeling::saveEngineSettings() @@ -5016,6 +5028,7 @@ void QgsPalLabeling::saveEngineSettings() QgsProject::instance()->writeEntry( "PAL", "/ShowingShadowRects", mShowingShadowRects ); QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", mShowingAllLabels ); QgsProject::instance()->writeEntry( "PAL", "/ShowingPartialsLabels", mShowingPartialsLabels ); + QgsProject::instance()->writeEntry( "PAL", "/DrawOutlineLabels", mDrawOutlineLabels ); } void QgsPalLabeling::clearEngineSettings() @@ -5028,6 +5041,7 @@ void QgsPalLabeling::clearEngineSettings() QgsProject::instance()->removeEntry( "PAL", "/ShowingShadowRects" ); QgsProject::instance()->removeEntry( "PAL", "/ShowingAllLabels" ); QgsProject::instance()->removeEntry( "PAL", "/ShowingPartialsLabels" ); + QgsProject::instance()->removeEntry( "PAL", "/DrawOutlineLabels" ); } QgsLabelingEngineInterface* QgsPalLabeling::clone() @@ -5037,6 +5051,7 @@ QgsLabelingEngineInterface* QgsPalLabeling::clone() lbl->mShowingCandidates = mShowingCandidates; lbl->mShowingShadowRects = mShowingShadowRects; lbl->mShowingPartialsLabels = mShowingPartialsLabels; + lbl->mDrawOutlineLabels = mDrawOutlineLabels; return lbl; } diff --git a/src/core/qgspallabeling.h b/src/core/qgspallabeling.h index 5e097039711..e720116ad32 100644 --- a/src/core/qgspallabeling.h +++ b/src/core/qgspallabeling.h @@ -740,6 +740,10 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface bool isShowingPartialsLabels() const { return mShowingPartialsLabels; } void setShowingPartialsLabels( bool showing ) { mShowingPartialsLabels = showing; } + //! @note added in 2.4 + bool isDrawingOutlineLabels() const { return mDrawOutlineLabels; } + void setDrawingOutlineLabels( bool outline ) { mDrawOutlineLabels = outline; } + // implemented methods from labeling engine interface //! called when we're going to start with rendering @@ -856,6 +860,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface bool mShowingAllLabels; // whether to avoid collisions or not bool mShowingShadowRects; // whether to show debugging rectangles for drop shadows bool mShowingPartialsLabels; // whether to avoid partials labels or not + bool mDrawOutlineLabels; // whether to draw labels as text or outlines QgsLabelingResults* mResults; }; diff --git a/src/ui/qgsengineconfigdialog.ui b/src/ui/qgsengineconfigdialog.ui index c8eb470a78d..9c3842d3b8b 100644 --- a/src/ui/qgsengineconfigdialog.ui +++ b/src/ui/qgsengineconfigdialog.ui @@ -215,7 +215,67 @@ 6 - + + + + Show partials labels + + + + + + + Show shadow rectangles (for debugging) + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + Show candidates (for debugging) + + + + + + + + 0 + 0 + + + + (i.e. including colliding objects) + + + + + + + + 0 + 0 + + + + Show all labels and features for all layers + + + + Qt::Horizontal @@ -231,63 +291,10 @@ - - - - - 0 - 0 - - - - Show all labels and features for all layers - - - - - - - Show candidates (for debugging) - - - - - - - - 0 - 0 - - - - (i.e. including colliding objects) - - - - - - - Qt::Horizontal - - - - 0 - 20 - - - - - - - - Show shadow rectangles (for debugging) - - - - + - Show partials labels + Draw text as outlines (recommended)