summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorVladimir Belyavsky <belyavskyv@gmail.com>2022-09-16 21:24:17 +0300
committerVladimir Belyavsky <belyavskyv@gmail.com>2022-09-20 06:52:21 +0000
commit013c346a8dcbd618febb07884c64c740daf9754d (patch)
treeae51601e1f280a19fd955180cca8c4b2a168fb82 /src/gui/text
parent53086094d8d2721a05c6e205e6217b17b92cc618 (diff)
QTextLayout: fix maximumWidth() for a text containing line separator
When laying out, we need to increase layout's maximum width _only_ if the previous line was not explicitly wrapped by a line or paragraph separator, or if the current line's width is greater than the previously accumulated layout's maximum width. Fixes: QTBUG-89557 Fixes: QTBUG-104986 Pick-to: 6.2 6.4 Change-Id: Ib7cc4b9dda8f20166dcbd5cfd3b56424bb33d14a Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextengine.cpp3
-rw-r--r--src/gui/text/qtextengine_p.h1
-rw-r--r--src/gui/text/qtextlayout.cpp9
3 files changed, 12 insertions, 1 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index c6da4b8f4a..718471a8f5 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2603,6 +2603,7 @@ QTextEngine::LayoutData::LayoutData()
hasBidi = false;
layoutState = LayoutEmpty;
haveCharAttributes = false;
+ previousLineManuallyWrapped = false;
logClustersPtr = nullptr;
available_glyphs = 0;
}
@@ -2637,6 +2638,7 @@ QTextEngine::LayoutData::LayoutData(const QString &str, void **stack_memory, int
hasBidi = false;
layoutState = LayoutEmpty;
haveCharAttributes = false;
+ previousLineManuallyWrapped = false;
}
QTextEngine::LayoutData::~LayoutData()
@@ -2722,6 +2724,7 @@ void QTextEngine::freeMemory()
layoutData->hasBidi = false;
layoutData->layoutState = LayoutEmpty;
layoutData->haveCharAttributes = false;
+ layoutData->previousLineManuallyWrapped = false;
layoutData->items.clear();
}
if (specialData)
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index c653bfc92f..c207ab63ae 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -385,6 +385,7 @@ public:
uint layoutState : 2;
uint memory_on_stack : 1;
uint haveCharAttributes : 1;
+ uint previousLineManuallyWrapped : 1;
QString string;
bool reallocate(int totalGlyphs);
};
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 9cf5d8963b..b88c902aca 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1808,6 +1808,7 @@ void QTextLine::layout_helper(int maxGlyphs)
lbh.logClusters = eng->layoutData->logClustersPtr;
lbh.previousGlyph = 0;
+ bool manuallyWrapped = false;
bool hasInlineObject = false;
QFixed maxInlineObjectHeight = 0;
@@ -1883,6 +1884,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;
@@ -2105,7 +2107,10 @@ found:
eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
} else {
eng->minWidth = qMax(eng->minWidth, lbh.minw);
- eng->maxWidth += line.textWidth;
+ if (eng->layoutData->previousLineManuallyWrapped)
+ eng->maxWidth = qMax(eng->maxWidth, line.textWidth);
+ else
+ eng->maxWidth += line.textWidth;
}
if (line.textWidth > 0 && item < eng->layoutData->items.size())
@@ -2119,6 +2124,8 @@ found:
line.justified = false;
line.gridfitted = false;
+
+ eng->layoutData->previousLineManuallyWrapped = manuallyWrapped;
}
/*!