Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dakcarto committed Jun 13, 2014
1 parent 469be12 commit c1d80ed
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 45 deletions.
4 changes: 4 additions & 0 deletions python/core/qgspallabeling.sip
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgslabelengineconfigdialog.cpp
Expand Up @@ -46,6 +46,7 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget* parent )
mShadowDebugRectChkBox->setChecked( lbl.isShowingShadowRectangles() );

chkShowPartialsLabels->setChecked( lbl.isShowingPartialsLabels() );
mDrawOutlinesChkBox->setChecked( lbl.isDrawingOutlineLabels() );
}


Expand All @@ -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();

Expand All @@ -81,4 +83,5 @@ void QgsLabelEngineConfigDialog::setDefaults()
chkShowAllLabels->setChecked( false );
mShadowDebugRectChkBox->setChecked( false );
chkShowPartialsLabels->setChecked( p.getShowPartial() );
mDrawOutlinesChkBox->setChecked( true );
}
35 changes: 25 additions & 10 deletions src/core/qgspallabeling.cpp
Expand Up @@ -3211,6 +3211,7 @@ QgsPalLabeling::QgsPalLabeling()
mShowingShadowRects = false;
mShowingAllLabels = false;
mShowingPartialsLabels = p.getShowPartial();
mDrawOutlineLabels = true;
}

QgsPalLabeling::~QgsPalLabeling()
Expand Down Expand Up @@ -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 )
Expand All @@ -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();
}
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -5037,6 +5051,7 @@ QgsLabelingEngineInterface* QgsPalLabeling::clone()
lbl->mShowingCandidates = mShowingCandidates;
lbl->mShowingShadowRects = mShowingShadowRects;
lbl->mShowingPartialsLabels = mShowingPartialsLabels;
lbl->mDrawOutlineLabels = mDrawOutlineLabels;
return lbl;
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/qgspallabeling.h
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
Expand Down
77 changes: 42 additions & 35 deletions src/ui/qgsengineconfigdialog.ui
Expand Up @@ -215,43 +215,41 @@
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="2" column="0">
<spacer name="horizontalSpacer_3">
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowPartialsLabels">
<property name="text">
<string>Show partials labels</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="mShadowDebugRectChkBox">
<property name="text">
<string>Show shadow rectangles (for debugging)</string>
</property>
</widget>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>8</height>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show all labels and features for all layers</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowCandidates">
<property name="text">
<string>Show candidates (for debugging)</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
Expand All @@ -264,30 +262,39 @@
</property>
</widget>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer_4">
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show all labels and features for all layers</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
<width>8</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="mShadowDebugRectChkBox">
<property name="text">
<string>Show shadow rectangles (for debugging)</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowPartialsLabels">
<widget class="QCheckBox" name="mDrawOutlinesChkBox">
<property name="text">
<string>Show partials labels</string>
<string>Draw text as outlines (recommended)</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit c1d80ed

Please sign in to comment.