Fix vertical alignment in data defined labeling

This commit is contained in:
Marco Hugentobler 2013-07-19 14:16:23 +02:00
parent d94ecd3746
commit 5ab0df5262

View File

@ -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;
}
}
}
}