Skip to content

Commit 5ab0df5

Browse files
committed
Fix vertical alignment in data defined labeling
1 parent d94ecd3 commit 5ab0df5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/core/qgspallabeling.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -2029,25 +2029,28 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
20292029
{
20302030
QString valiString = exprVal.toString();
20312031
QgsDebugMsgLevel( QString( "exprVal Vali:%1" ).arg( valiString ), 4 );
2032+
20322033
if ( valiString.compare( "Bottom", Qt::CaseInsensitive ) != 0 )
20332034
{
2034-
if ( valiString.compare( "Top", Qt::CaseInsensitive ) == 0
2035-
|| valiString.compare( "Cap", Qt::CaseInsensitive ) == 0 )
2035+
if ( valiString.compare( "Top", Qt::CaseInsensitive ) == 0 )
20362036
{
20372037
ydiff -= labelY;
20382038
}
20392039
else
20402040
{
20412041
double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
2042-
20432042
if ( valiString.compare( "Base", Qt::CaseInsensitive ) == 0 )
20442043
{
20452044
ydiff -= labelY * descentRatio;
20462045
}
2047-
else if ( valiString.compare( "Half", Qt::CaseInsensitive ) == 0 )
2046+
else //'Cap' or 'Half'
20482047
{
2049-
ydiff -= labelY * descentRatio;
2050-
ydiff -= labelY * 0.5 * ( 1 - descentRatio );
2048+
double capHeightRatio = ( labelFontMetrics->boundingRect( 'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
2049+
ydiff -= labelY * capHeightRatio;
2050+
if ( valiString.compare( "Half", Qt::CaseInsensitive ) == 0 )
2051+
{
2052+
ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
2053+
}
20512054
}
20522055
}
20532056
}

0 commit comments

Comments
 (0)