Skip to content
Permalink
Browse files

Port font marker away from deprecated API

Note: it's highly likely there's a bug here, and we should be
using the (tight)boundingRect of the string here instead of the
width/horizontalAdvance. But doing so changes the rendering position
of characters substantially, as it means that font markers are
properly centered on the actual character itself (otherwise
a character like '.' is not placed over the point itself, but
rather below it! iThat's the current behavior).

We could possibly handle this by only applying the improved
positioning to newly created font marker symbols, but that's
left for a follow-up work...
  • Loading branch information
nyalldawson committed Feb 7, 2020
1 parent 3c89d26 commit 578616cf936ced32e861c48dc42e352398b89852
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/core/symbology/qgsmarkersymbollayer.cpp
@@ -3040,7 +3040,11 @@ void QgsFontMarkerSymbolLayer::startRender( QgsSymbolRenderContext &context )
mFont.setPixelSize( std::max( 2, static_cast< int >( std::round( sizePixels ) ) ) );
delete mFontMetrics;
mFontMetrics = new QFontMetrics( mFont );
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
mChrWidth = mFontMetrics->width( mString );
#else
mChrWidth = mFontMetrics->horizontalAdvance( mString );
#endif
mChrOffset = QPointF( mChrWidth / 2.0, -mFontMetrics->ascent() / 2.0 );
mOrigSize = mSize; // save in case the size would be data defined

@@ -3071,7 +3075,11 @@ QString QgsFontMarkerSymbolLayer::characterToRender( QgsSymbolRenderContext &con
stringToRender = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyCharacter, context.renderContext().expressionContext(), mString );
if ( stringToRender != mString )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
charWidth = mFontMetrics->width( stringToRender );
#else
charWidth = mFontMetrics->horizontalAdvance( stringToRender );
#endif
charOffset = QPointF( charWidth / 2.0, -mFontMetrics->ascent() / 2.0 );
}
}

0 comments on commit 578616c

Please sign in to comment.
You can’t perform that action at this time.