Skip to content

Commit

Permalink
Fix vertical alignment in data defined labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 19, 2013
1 parent d94ecd3 commit 5ab0df5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/qgspallabeling.cpp
Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit 5ab0df5

Please sign in to comment.