summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorVladimir Belyavsky <belyavskyv@gmail.com>2022-09-27 16:57:08 +0300
committerVladimir Belyavsky <belyavskyv@gmail.com>2022-11-19 18:03:32 +0300
commit991c056438b311566bc4ea543af0f33dfd5dffbb (patch)
tree7b86d825cc45b1c91db6c57b09e1cff79e6b3efd /src/gui/text/qtextlayout.cpp
parentb2ed29b8d9b33dcece83000aee28073dd27f1cd9 (diff)
QTextLayout: fix maximumWidth() for a text containing line separator
This is improved version of previous fix 013c346a8dcbd618febb07884c64c740daf9754d that was reverted because it broke some tests for Quick Text. The problem was that it did not work correctly in the case the text was wrapped to a fixed width. To deal with this we'll accumulate current line full width (as if it hadn't been wrapped) in layout data (layoutData->currentMaxWidth). Then when the next line is explicitly wrapped by line or paragraph separator, this accumulated width will be used to adjust layout's maximum width. Change-Id: Iad7119d9808e1db15fe1fbc5db049c3db928529f Fixes: QTBUG-89557 Fixes: QTBUG-104986 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index e4281b78e6..d168a77d57 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1865,6 +1865,7 @@ void QTextLine::layout_helper(int maxGlyphs)
lbh.logClusters = eng->layoutData->logClustersPtr;
lbh.previousGlyph = 0;
+ bool manuallyWrapped = false;
bool hasInlineObject = false;
QFixed maxInlineObjectHeight = 0;
@@ -1940,6 +1941,7 @@ void QTextLine::layout_helper(int maxGlyphs)
lbh.calculateRightBearingForPreviousGlyph();
}
line += lbh.tmpData;
+ manuallyWrapped = true;
goto found;
} else if (current.analysis.flags == QScriptAnalysis::Object) {
lbh.whiteSpaceOrObject = true;
@@ -1974,11 +1976,10 @@ void QTextLine::layout_helper(int maxGlyphs)
addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount,
current, lbh.logClusters, lbh.glyphs);
}
-
- if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width) {
- goto found;
- }
} else {
+ if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width)
+ goto found;
+
lbh.whiteSpaceOrObject = false;
bool sb_or_ws = false;
lbh.saveCurrentGlyph();
@@ -2161,7 +2162,12 @@ found:
eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
} else {
eng->minWidth = qMax(eng->minWidth, lbh.minw);
- eng->maxWidth += line.textWidth + lbh.spaceData.textWidth;
+ eng->layoutData->currentMaxWidth += line.textWidth;
+ if (!manuallyWrapped)
+ eng->layoutData->currentMaxWidth += lbh.spaceData.textWidth;
+ eng->maxWidth = qMax(eng->maxWidth, eng->layoutData->currentMaxWidth);
+ if (manuallyWrapped)
+ eng->layoutData->currentMaxWidth = 0;
}
line.textWidth += trailingSpace;