Skip to content

Commit

Permalink
Fix handling of justify align with final line in multiparagraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 30, 2021
1 parent f65ea56 commit 423ef09
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/core/textrenderer/qgstextrenderer.cpp
Expand Up @@ -1585,7 +1585,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 @@ -1621,7 +1622,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
8 changes: 4 additions & 4 deletions tests/src/python/test_qgstextrenderer.py
Expand Up @@ -2742,17 +2742,17 @@ def testDrawTextRectJustifyAlign(self):
assert self.checkRender(format, 'text_rect_justify_aligned', text=['test'],
alignment=QgsTextRenderer.AlignJustify, rect=QRectF(100, 100, 200, 100))

def testDrawTextRectMultilineJustifyAlign(self):
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_multiline_justify_aligned',
text=['a t est', 'off', 'justification', 'align'],
alignment=QgsTextRenderer.AlignJustify, rect=QRectF(100, 100, 200, 100))
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 testDrawTextRectWordWrapSingleLine(self):
format = QgsTextFormat()
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 423ef09

Please sign in to comment.