summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-02-01 10:21:04 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-08 15:06:08 +0000
commitbce9a182ad7c5730cfb691bc082b01f8c3be2e7f (patch)
treebd608d9fb4d7c0e0cba4ee1924283fe4eb50dd73 /tests/auto
parent59e4fe68e5d602d07d24871b1a1fe6ec8a462e2a (diff)
Handle macOS 11 issues in softHyphens test
Calculate the effective width of the hyphen better, and compare with ceiled sizes. Fixes: QTBUG-90698 Change-Id: I7ed2eb44c54240ecb2f8a38e5acf1f32608b2bfb Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> (cherry picked from commit 0ffdbb21261eee3a9ec1cd541478ee883a12065c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp59
1 files changed, 42 insertions, 17 deletions
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index 7433d2c534..bbb53d85cc 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -141,6 +141,7 @@ private slots:
void showLineAndParagraphSeparatorsCrash();
void koreanWordWrap();
void tooManyDirectionalCharctersCrash_qtbug77819();
+ void softHyphens_data();
void softHyphens();
void min_maximumWidth();
@@ -2401,22 +2402,45 @@ void tst_QTextLayout::tooManyDirectionalCharctersCrash_qtbug77819()
tl.endLayout();
}
+void tst_QTextLayout::softHyphens_data()
+{
+ QTest::addColumn<int>("fontSize");
+
+ QTest::newRow("12") << 12;
+ QTest::newRow("14") << 14;
+ QTest::newRow("16") << 16;
+}
+
void tst_QTextLayout::softHyphens()
{
+ QFETCH(int, fontSize);
QString text = QStringLiteral("xxxx\u00ad") + QStringLiteral("xxxx\u00ad");
QFont font;
- font.setPixelSize(14);
+ font.setPixelSize(fontSize);
font.setHintingPreference(QFont::PreferNoHinting);
- const float xAdvance = QFontMetricsF(font).horizontalAdvance(QChar('x'));
- const float shyAdvance = QFontMetricsF(font).horizontalAdvance(QChar::SoftHyphen);
- if (xAdvance < (shyAdvance + 1.0f))
- QSKIP("Default font not suitable for this test.");
+ const float xAdvance = QFontMetricsF(font).horizontalAdvance(QChar::fromLatin1('x'));
+ float shyWidth = 0.0f;
QTextLayout layout(text, font);
QTextOption option;
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
layout.setTextOption(option);
-
+ {
+ // Calculate the effective width of a line-ending hyphen
+ // This calculation is currently done to work-around odditities on
+ // macOS 11 (see QTBUG-90698).
+ QTextLayout test(QStringLiteral("x\u00ad"), font);
+ // Note: This only works because Qt show the soft-hyphen when ending a text.
+ // This _could_ be considered a bug and the test would need to be changed
+ // if we stop doing that.
+ test.beginLayout();
+ QTextLine line = test.createLine();
+ line.setLineWidth(10 * xAdvance);
+ line.setPosition(QPoint(0, 0));
+ shyWidth = line.naturalTextWidth() - xAdvance;
+ test.endLayout();
+ }
+ qreal linefit;
// Loose fit
// xxxx- |
// xxxx- |
@@ -2425,21 +2449,22 @@ void tst_QTextLayout::softHyphens()
int y = 0;
layout.beginLayout();
QTextLine line = layout.createLine();
- line.setLineWidth(qCeil(5 * xAdvance) + 1);
+ line.setLineWidth(qCeil(5 * xAdvance + shyWidth) + 1);
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 5);
- QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+ linefit = line.naturalTextWidth();
+ QVERIFY(qAbs(linefit - qCeil(4 * xAdvance + shyWidth)) <= 1.0);
pos += line.textLength();
y += qRound(line.ascent() + line.descent());
line = layout.createLine();
- line.setLineWidth(qCeil(5 * xAdvance) + 1);
+ line.setLineWidth(qCeil(5 * xAdvance + shyWidth) + 1);
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 5);
- QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - linefit) <= 1.0);
layout.endLayout();
}
@@ -2451,21 +2476,21 @@ void tst_QTextLayout::softHyphens()
int y = 0;
layout.beginLayout();
QTextLine line = layout.createLine();
- line.setLineWidth(qCeil(4 * xAdvance + shyAdvance) + 1);
+ line.setLineWidth(qCeil(linefit) + 1);
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 5);
- QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - linefit) <= 1.0);
pos += line.textLength();
y += qRound(line.ascent() + line.descent());
line = layout.createLine();
- line.setLineWidth(qCeil(4 * xAdvance + shyAdvance) + 1);
+ line.setLineWidth(qCeil(linefit) + 1);
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 5);
- QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - linefit) <= 1.0);
layout.endLayout();
}
@@ -2482,7 +2507,7 @@ void tst_QTextLayout::softHyphens()
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 4);
- QVERIFY(qAbs(line.naturalTextWidth() - 4 * xAdvance) <= 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - qCeil(4 * xAdvance)) <= 1.0);
pos += line.textLength();
y += qRound(line.ascent() + line.descent());
@@ -2492,7 +2517,7 @@ void tst_QTextLayout::softHyphens()
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 5);
- QVERIFY(qAbs(line.naturalTextWidth() - 4 * xAdvance) <= 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - qCeil(4 * xAdvance)) <= 1.0);
pos += line.textLength();
y += qRound(line.ascent() + line.descent());
@@ -2502,7 +2527,7 @@ void tst_QTextLayout::softHyphens()
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
QCOMPARE(line.textLength(), 1);
- QVERIFY(qAbs(line.naturalTextWidth() - shyAdvance) <= 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - shyWidth) <= 1.0);
layout.endLayout();
}
}