Skip to content
Permalink
Browse files
Fix vertical alignment in data defined labeling
  • Loading branch information
mhugent committed Jul 19, 2013
1 parent d94ecd3 commit 5ab0df5262fa9433c6cf4b52a6ba2a15e257b879
Showing with 9 additions and 6 deletions.
  1. +9 −6 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;
}
}
}
}

0 comments on commit 5ab0df5

Please sign in to comment.