From 5ab0df5262fa9433c6cf4b52a6ba2a15e257b879 Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Fri, 19 Jul 2013 14:16:23 +0200 Subject: [PATCH] Fix vertical alignment in data defined labeling --- src/core/qgspallabeling.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index 044ca85bad0..e5cd13cf18f 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -2029,25 +2029,28 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f { QString valiString = exprVal.toString(); QgsDebugMsgLevel( QString( "exprVal Vali:%1" ).arg( valiString ), 4 ); + if ( valiString.compare( "Bottom", Qt::CaseInsensitive ) != 0 ) { - if ( valiString.compare( "Top", Qt::CaseInsensitive ) == 0 - || valiString.compare( "Cap", Qt::CaseInsensitive ) == 0 ) + if ( valiString.compare( "Top", Qt::CaseInsensitive ) == 0 ) { ydiff -= labelY; } else { double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height(); - if ( valiString.compare( "Base", Qt::CaseInsensitive ) == 0 ) { ydiff -= labelY * descentRatio; } - else if ( valiString.compare( "Half", Qt::CaseInsensitive ) == 0 ) + else //'Cap' or 'Half' { - ydiff -= labelY * descentRatio; - ydiff -= labelY * 0.5 * ( 1 - descentRatio ); + double capHeightRatio = ( labelFontMetrics->boundingRect( 'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height(); + ydiff -= labelY * capHeightRatio; + if ( valiString.compare( "Half", Qt::CaseInsensitive ) == 0 ) + { + ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0; + } } } }