From b4cc29434769b1d6c08ab2fc76cdcc2dac5dede9 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 26 Apr 2019 09:15:52 +0200 Subject: Fix page breaking with large images Don't go into an infinite loop breaking pages, when an image is about as large as the page. Correctly take top and bottom margins into account when calculating whether the image could fit on one page. Amends change 416b4cf685030114837bd375664fd12047895a62. Fixes: QTBUG-73730 Change-Id: Id311ddf05510be3b1d131702f4e17025a9861e58 Reviewed-by: Simon Hausmann --- src/gui/text/qtextdocumentlayout.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/gui/text/qtextdocumentlayout.cpp') diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index 2e1a2b5bff..bed0a2c450 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -145,6 +145,9 @@ struct QTextLayoutStruct { inline QFixed absoluteY() const { return frameY + y; } + inline QFixed contentHeight() const + { return pageHeight - pageBottomMargin - pageTopMargin; } + inline int currentPage() const { return pageHeight == 0 ? 0 : (absoluteY() / pageHeight).truncate(); } @@ -2701,7 +2704,7 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi getLineHeightParams(blockFormat, line, scaling, &lineAdjustment, &lineBreakHeight, &lineHeight, &lineBottom); while (layoutStruct->pageHeight > 0 && layoutStruct->absoluteY() + lineBreakHeight > layoutStruct->pageBottom && - layoutStruct->pageHeight >= lineBreakHeight) { + layoutStruct->contentHeight() >= lineBreakHeight) { layoutStruct->newPage(); floatMargins(layoutStruct->y, layoutStruct, &left, &right); -- cgit v1.2.3