Skip to content
Permalink
Browse files

Add word and letter spacing to PAL layer of adv labeling

- Caveat: does not work with curved line labels (yet)
- Reorganize form widgets, moving mulit-line options to own groupbox
- Character width option removed due to very erratic QFont::setStretch() bugs
  • Loading branch information
dakcarto committed Aug 31, 2012
1 parent 6028b81 commit 31d1b95bdb1816630aef42a24f1c284b68d37fc7
Showing with 307 additions and 288 deletions.
  1. +22 −2 src/app/qgslabelinggui.cpp
  2. +1 −0 src/app/qgslabelinggui.h
  3. +14 −0 src/core/qgspallabeling.cpp
  4. +270 −286 src/ui/qgslabelingguibase.ui
@@ -47,7 +47,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM

connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
connect( mFontSizeUnitComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mFontTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
connect( btnBufferColor, SIGNAL( clicked() ), this, SLOT( changeBufferColor() ) );
@@ -512,6 +511,8 @@ void QgsLabelingGui::changeTextFont()
{
// store properties of QFont that might be stripped by font dialog
QFont::Capitalization captials = mRefFont.capitalization();
double wordspacing = mRefFont.wordSpacing();
double letterspacing = mRefFont.letterSpacing();

bool ok;
#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
@@ -534,6 +535,8 @@ void QgsLabelingGui::changeTextFont()

// reassign possibly stripped QFont properties
font.setCapitalization( captials );
font.setWordSpacing( wordspacing );
font.setLetterSpacing( QFont::AbsoluteSpacing, letterspacing );

updateFont( font );
}
@@ -569,6 +572,8 @@ void QgsLabelingGui::updateFontViaStyle( const QString & fontstyle )
styledfont.setCapitalization( mRefFont.capitalization() );
styledfont.setUnderline( mRefFont.underline() );
styledfont.setStrikeOut( mRefFont.strikeOut() );
styledfont.setWordSpacing( mRefFont.wordSpacing() );
styledfont.setLetterSpacing( QFont::AbsoluteSpacing, mRefFont.letterSpacing() );
mRefFont = styledfont;
}
// if no match, style combobox will be left blank, which should not affect engine labeling
@@ -611,6 +616,8 @@ void QgsLabelingGui::updateFont( QFont font )
mFontCapitalsComboBox->setCurrentIndex( idx == -1 ? 0 : idx );
mFontUnderlineBtn->setChecked( mRefFont.underline() );
mFontStrikethroughBtn->setChecked( mRefFont.strikeOut() );
mFontWordSpacingSpinBox->setValue( mRefFont.wordSpacing() );
mFontLetterSpacingSpinBox->setValue( mRefFont.letterSpacing() );
blockFontChangeSignals( false );

// update font name with font face
@@ -633,6 +640,7 @@ void QgsLabelingGui::updatePreview()
lblFontPreview->setFont( mRefFont );
QFont previewFont = lblFontPreview->font();
double fontSize = mFontSizeSpinBox->value();
double previewRatio = mPreviewSize / fontSize;
double bufferSize = 0.0;
QString grpboxtitle;

@@ -643,11 +651,14 @@ void QgsLabelingGui::updatePreview()
mPreviewSizeSlider->setEnabled( true );
grpboxtitle = tr( "Sample @ %1 pts (using map units)" ).arg( mPreviewSize );

previewFont.setWordSpacing( previewRatio * mFontWordSpacingSpinBox->value() );
previewFont.setLetterSpacing( QFont::AbsoluteSpacing, previewRatio * mFontLetterSpacingSpinBox->value() );

if ( chkBuffer->isChecked() )
{
if ( mBufferUnitComboBox->currentIndex() == 1 ) // map units
{
bufferSize = ( mPreviewSize / fontSize ) * spinBufferSize->value() / 2.5;
bufferSize = previewRatio * spinBufferSize->value() / 3.527;
}
else // millimeters
{
@@ -850,6 +861,15 @@ void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
updateFont( mRefFont );
}

void QgsLabelingGui::on_mFontSizeUnitComboBox_currentIndexChanged( int index )
{
double singleStep = ( index == 1 ) ? 10.0 : 1.0 ; //10 for map units, 1 for mm
mFontSizeSpinBox->setSingleStep( singleStep );
mFontWordSpacingSpinBox->setSingleStep( singleStep );
mFontLetterSpacingSpinBox->setSingleStep( singleStep / 10 );
updateFont( mRefFont );
}

void QgsLabelingGui::on_mBufferUnitComboBox_currentIndexChanged( int index )
{
double singleStep = ( index == 1 ) ? 1.0 : 0.1 ; //1.0 for map units, 0.1 for mm
@@ -58,6 +58,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void on_mFontStrikethroughBtn_toggled( bool ckd );
void on_mFontWordSpacingSpinBox_valueChanged( double spacing );
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
void on_mBufferUnitComboBox_currentIndexChanged( int index );
void on_mXCoordinateComboBox_currentIndexChanged( const QString & text );
void on_mYCoordinateComboBox_currentIndexChanged( const QString & text );
@@ -354,6 +354,8 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
textFont.setCapitalization(( QFont::Capitalization ) layer->customProperty( "labeling/fontCapitals", QVariant( 0 ) ).toUInt() );
textFont.setUnderline( layer->customProperty( "labeling/fontUnderline" ).toBool() );
textFont.setStrikeOut( layer->customProperty( "labeling/fontStrikeout" ).toBool() );
textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->customProperty( "labeling/fontLetterSpacing", QVariant( 0.0 ) ).toDouble() );
textFont.setWordSpacing( layer->customProperty( "labeling/fontWordSpacing", QVariant( 0.0 ) ).toDouble() );
textColor = _readColor( layer, "labeling/textColor" );
textTransp = layer->customProperty( "labeling/textTransp" ).toInt();
previewBkgrdColor = QColor( layer->customProperty( "labeling/previewBkgrdColor", "#ffffff" ).toString() );
@@ -401,6 +403,8 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/fontItalic", textFont.italic() );
layer->setCustomProperty( "labeling/fontStrikeout", textFont.strikeOut() );
layer->setCustomProperty( "labeling/fontUnderline", textFont.underline() );
layer->setCustomProperty( "labeling/fontLetterSpacing", textFont.letterSpacing() );
layer->setCustomProperty( "labeling/fontWordSpacing", textFont.wordSpacing() );

_writeColor( layer, "labeling/textColor", textColor );
layer->setCustomProperty( "labeling/textTransp", textTransp );
@@ -974,6 +978,16 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
{
lyr.textFont.setPixelSize( pixelFontSize );
}

if ( lyr.fontSizeInMapUnits )
{
double spacingPixelSize = lyr.textFont.wordSpacing() / ctx.mapToPixel().mapUnitsPerPixel() * ctx.rasterScaleFactor();
lyr.textFont.setWordSpacing( spacingPixelSize );

spacingPixelSize = lyr.textFont.letterSpacing() / ctx.mapToPixel().mapUnitsPerPixel() * ctx.rasterScaleFactor();
lyr.textFont.setLetterSpacing( QFont::AbsoluteSpacing, spacingPixelSize );
}

//raster and vector scale factors
lyr.vectorScaleFactor = ctx.scaleFactor();
lyr.rasterCompressFactor = ctx.rasterScaleFactor();

0 comments on commit 31d1b95

Please sign in to comment.
You can’t perform that action at this time.