Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix handling of justify align with final line in multiparagraphs
(cherry picked from commit 024522b)
  • Loading branch information
nyalldawson committed Dec 1, 2021
1 parent e96533a commit 07a18f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/textrenderer/qgstextrenderer.cpp
Expand Up @@ -1483,7 +1483,8 @@ void QgsTextRenderer::drawTextInternalHorizontal( QgsRenderContext &context, con
{
const QgsTextBlock block = document.at( i );

const bool isFinalLine = i == document.size() - 1;
const bool isFinalLineInParagraph = ( i == document.size() - 1 )
|| document.at( i + 1 ).toPlainText().trimmed().isEmpty();

QgsScopedQPainterState painterState( context.painter() );
context.setPainterFlagsUsingContext();
Expand Down Expand Up @@ -1519,7 +1520,7 @@ void QgsTextRenderer::drawTextInternalHorizontal( QgsRenderContext &context, con
break;

case AlignJustify:
if ( !isFinalLine && labelWidest > labelWidth )
if ( !isFinalLineInParagraph && labelWidest > labelWidth )
{
calculateExtraSpacingForLineJustification( labelWidest - labelWidth, block, extraWordSpace, extraLetterSpace );
}
Expand Down
12 changes: 12 additions & 0 deletions tests/src/python/test_qgstextrenderer.py
Expand Up @@ -2680,6 +2680,18 @@ def testDrawTextRectJustifyAlign(self):
assert self.checkRender(format, 'text_rect_justify_aligned', text=['test'],
alignment=QgsTextRenderer.AlignJustify, rect=QRectF(100, 100, 200, 100))

def testDrawTextRectMultiparagraphJustifyAlign(self):
format = QgsTextFormat()
format.setFont(getTestFont('bold'))
format.setSize(30)
format.setSizeUnit(QgsUnitTypes.RenderPoints)
format.buffer().setEnabled(True)
format.buffer().setSize(4)
format.buffer().setSizeUnit(QgsUnitTypes.RenderMillimeters)
assert self.checkRender(format, 'text_rect_multiparagraph_justify_aligned',
text=['a t est', 'of justify', '', 'with two', 'pgraphs'],
alignment=QgsTextRenderer.AlignJustify, rect=QRectF(50, 100, 250, 100))

def testDrawTextRectMultilineBottomAlign(self):
format = QgsTextFormat()
format.setFont(getTestFont('bold'))
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 07a18f4

Please sign in to comment.