summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2020-04-29 18:18:51 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2020-05-05 19:17:35 +0200
commit8d6d1d6fea1d262f97f088eb92441cececad3f88 (patch)
treed1216ea9a20e3caabb749cda094366411d883032 /tests/auto/gui
parent0534aeffe9a807c5853987a02390c409600e1897 (diff)
Fix bug in QTextLayout::min/maxWidth for WrapAtWordBoundaryOrAnywhere
In that specific wrapping mode, it will first try a normal word wrap. If it doesn't fit within the specified line width it will discard the result of that and try WrapAnywhere by calling layout_helper() recursively. The problem was that at the point it called itself again it had already adjusted eng->maxWidth: eng->maxWidth += line.textWidth; This was not restored, but carried on to the recursive call to layout_helper(), so the end result was that the maximumWidth would accumulate text widths from parts of the same line twice. Due to the same recursive behavior the minimumWidth also had a problem: It always returned the width of the widest word because it took the qMax() of the minimum widths of the two passes, (WordWrap and then WrapAnywhere) effectively making the minimum width always be the width of the widest word (even though it could wrap at finer granularity). Pick-to: 5.15 Task-number: QTBUG-77337 Change-Id: Ie7e9c17b157506352c2da38cc7f4a8dfa1283966 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index 8466305832..9c5b58884a 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -142,6 +142,7 @@ private slots:
void koreanWordWrap();
void tooManyDirectionalCharctersCrash_qtbug77819();
void softHyphens();
+ void min_maximumWidth();
private:
QFont testFont;
@@ -2488,5 +2489,41 @@ void tst_QTextLayout::softHyphens()
}
}
+void tst_QTextLayout::min_maximumWidth()
+{
+ QString longString("lmong_long_crazy_87235982735_23857239682376923876923876-fuwhfhfw-names-AAAA-deeaois2019-03-03.and.more");
+ QTextLayout layout(longString, testFont);
+
+ for (int wrapMode = QTextOption::NoWrap; wrapMode <= QTextOption::WrapAtWordBoundaryOrAnywhere; ++wrapMode) {
+ QTextOption opt;
+ opt.setWrapMode((QTextOption::WrapMode)wrapMode);
+ layout.setTextOption(opt);
+ layout.beginLayout();
+ while (layout.createLine().isValid()) { }
+ layout.endLayout();
+ const qreal minWidth = layout.minimumWidth();
+ const qreal maxWidth = layout.maximumWidth();
+
+ // Try the layout from slightly wider than the widest (maxWidth)
+ // and narrow it down to slighly narrower than minWidth
+ // layout.maximumWidth() should return the same regardless
+ qreal width = qCeil(maxWidth/10)*10 + 10; // begin a bit wider
+ const qreal stepSize = 20;
+ while (width >= minWidth - stepSize) {
+ layout.beginLayout();
+ for (;;) {
+ QTextLine line = layout.createLine();
+ if (!line.isValid())
+ break;
+ line.setLineWidth(width);
+ }
+ layout.endLayout();
+ QCOMPARE(layout.minimumWidth(), minWidth);
+ QCOMPARE(layout.maximumWidth(), maxWidth);
+ width -= stepSize;
+ }
+ }
+}
+
QTEST_MAIN(tst_QTextLayout)
#include "tst_qtextlayout.moc"