Fix rendering of annotation text items in HTML mode when html content

is split into multiple lines
This commit is contained in:
Nyall Dawson 2024-08-05 11:22:29 +10:00
parent e8724fa45e
commit c0ff7dc49a
2 changed files with 4 additions and 4 deletions

View File

@ -88,7 +88,7 @@ void QgsAnnotationPointTextItem::render( QgsRenderContext &context, QgsFeedback
QgsTextRenderer::drawText( pt, - angle * M_PI / 180.0,
QgsTextRenderer::convertQtHAlignment( mAlignment ),
displayText.split( '\n' ), context, mTextFormat );
mTextFormat.allowHtmlFormatting() ? QStringList{displayText }: displayText.split( '\n' ), context, mTextFormat );
}
bool QgsAnnotationPointTextItem::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const
@ -165,8 +165,8 @@ QgsRectangle QgsAnnotationPointTextItem::boundingBox( QgsRenderContext &context
{
const QString displayText = QgsExpression::replaceExpressionText( mText, &context.expressionContext(), &context.distanceArea() );
const double widthInPixels = QgsTextRenderer::textWidth( context, mTextFormat, displayText.split( '\n' ) );
const double heightInPixels = QgsTextRenderer::textHeight( context, mTextFormat, displayText.split( '\n' ) );
const double widthInPixels = QgsTextRenderer::textWidth( context, mTextFormat, mTextFormat.allowHtmlFormatting() ? QStringList{displayText }: displayText.split( '\n' ) );
const double heightInPixels = QgsTextRenderer::textHeight( context, mTextFormat, mTextFormat.allowHtmlFormatting() ? QStringList{displayText }: displayText.split( '\n' ) );
// text size has already been calculated using any symbology reference scale factor above -- we need
// to temporarily remove the reference scale here or we'll be undoing the scaling

View File

@ -96,7 +96,7 @@ void QgsAnnotationRectangleTextItem::render( QgsRenderContext &context, QgsFeedb
context.setFlag( Qgis::RenderContextFlag::ApplyScalingWorkaroundForTextRendering, true );
QgsTextRenderer::drawText( innerRect, 0,
QgsTextRenderer::convertQtHAlignment( mAlignment ),
displayText.split( '\n' ), context, mTextFormat, true,
mTextFormat.allowHtmlFormatting() ? QStringList{displayText }: displayText.split( '\n' ), context, mTextFormat, true,
QgsTextRenderer::convertQtVAlignment( mAlignment ),
Qgis::TextRendererFlag::WrapLines );
context.setFlag( Qgis::RenderContextFlag::ApplyScalingWorkaroundForTextRendering, prevWorkaroundFlag );