diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-11-11 09:29:17 +0200 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-11-11 09:29:17 +0200 |
commit | 4ee4fc18b4067b90efa46ca9baba74f53b54d9ec (patch) | |
tree | cc68622c9b85992d99a8373ab55471ee821a4ebf /tests/auto/gui | |
parent | ab28ff2207e8f33754c79793089dbf943d67736d (diff) | |
parent | ebb49c66aaf22ed55d62ff7bc3690fce00b7d8ba (diff) | |
download | qtbase-4ee4fc18b4067b90efa46ca9baba74f53b54d9ec.tar.gz |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.8' into tqtc/lts-5.15-opensourcev5.15.8-lts-lgpl
Change-Id: I569a2246c9e8d70430e8c5405b9f3df2218078ee
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 14 | ||||
-rw-r--r-- | tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp | 8 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp | 60 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextlayout/BLACKLIST | 3 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 59 | ||||
-rw-r--r-- | tests/auto/gui/text/qtexttable/tst_qtexttable.cpp | 89 |
6 files changed, 214 insertions, 19 deletions
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 1d77f70919..417514607f 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -120,6 +120,7 @@ private slots: void copy(); void deepCopyPreservesDpr(); + void fillPreservesDpr(); void dprPassthrough(); void depthOfNullObjects(); @@ -1156,6 +1157,19 @@ void tst_QPixmap::deepCopyPreservesDpr() QCOMPARE(dest.devicePixelRatio(), dpr); } +// Check that the DPR is preserved after doing a fill after an +// assigned copy of the QPixmap +void tst_QPixmap::fillPreservesDpr() +{ + const qreal dpr = 2; + QPixmap src(32, 32); + src.setDevicePixelRatio(dpr); + src.fill(Qt::red); + QPixmap dest = src; + dest.fill(Qt::blue); + QCOMPARE(dest.devicePixelRatio(), dpr); +} + void tst_QPixmap::dprPassthrough() { const qreal dpr = 2; diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index edbb090e42..15e0ecadaa 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -33,6 +33,8 @@ #include <qfontmetrics.h> #include <qtextlayout.h> #include <private/qrawfont_p.h> +#include <private/qfont_p.h> +#include <private/qfontengine_p.h> #include <qpa/qplatformfontdatabase.h> Q_LOGGING_CATEGORY(lcTests, "qt.text.tests") @@ -411,7 +413,11 @@ void tst_QFontDatabase::condensedFontMatching() tfcByStyleName.setStyleName("Condensed"); #ifdef Q_OS_WIN - QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue); + QFont f; + f.setStyleStrategy(QFont::NoFontMerging); + QFontPrivate *font_d = QFontPrivate::get(f); + if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype) + QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue); #endif #ifdef Q_OS_ANDROID diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 7bc9fe47c5..a61824b51c 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -197,6 +197,9 @@ private slots: void clearUndoRedoStacks(); void mergeFontFamilies(); + void contentsChangeIndices_data(); + void contentsChangeIndices(); + private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); void buildRegExpData(); @@ -3716,5 +3719,62 @@ void tst_QTextDocument::clearUndoRedoStacks() } +void tst_QTextDocument::contentsChangeIndices_data() +{ + QTest::addColumn<QString>("html"); + // adding list entries change the entire block, so change position is + // not the same as the cursor position if this value is >= 0 + QTest::addColumn<int>("expectedBegin"); + + QTest::addRow("text") << "Test" << -1; + QTest::addRow("unnumbered list") << "<ul><li>Test</li></ul>" << 0; + QTest::addRow("numbered list") << "<ol><li>Test</li></ol>" << 0; + QTest::addRow("table") << "<table><tr><td>Test</td></tr></table>" << -1; +} + +void tst_QTextDocument::contentsChangeIndices() +{ + QFETCH(QString, html); + QFETCH(int, expectedBegin); + + QTextDocument doc; + QTestDocumentLayout *layout = new QTestDocumentLayout(&doc); + doc.setDocumentLayout(layout); + doc.setHtml(QString("<html><body>%1</body></html>").arg(html)); + + int documentLength = 0; + int cursorLength = 0; + int changeBegin = 0; + int changeRemoved = 0; + int changeAdded = 0; + connect(&doc, &QTextDocument::contentsChange, this, [&](int pos, int removed, int added){ + documentLength = doc.characterCount(); + + QTextCursor cursor(&doc); + cursor.movePosition(QTextCursor::End); + // includes end-of-paragraph character + cursorLength = cursor.position() + 1; + + changeBegin = pos; + changeRemoved = removed; + changeAdded = added; + }); + + QTextCursor cursor(&doc); + cursor.movePosition(QTextCursor::End); + if (expectedBegin < 0) + expectedBegin = cursor.position(); + cursor.insertBlock(); + + const int changeEnd = changeBegin + changeAdded; + + QVERIFY(documentLength > 0); + QCOMPARE(documentLength, cursorLength); + QVERIFY(documentLength >= changeEnd); + QCOMPARE(changeBegin, expectedBegin); + QCOMPARE(changeAdded - changeRemoved, 1); +} + + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" diff --git a/tests/auto/gui/text/qtextlayout/BLACKLIST b/tests/auto/gui/text/qtextlayout/BLACKLIST new file mode 100644 index 0000000000..c05b0de4eb --- /dev/null +++ b/tests/auto/gui/text/qtextlayout/BLACKLIST @@ -0,0 +1,3 @@ +[softHyphens] +winrt + diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 2feca77f40..f3bb5eaffb 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(); @@ -2429,22 +2430,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- | @@ -2453,21 +2477,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(); } @@ -2479,21 +2504,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(); } @@ -2510,7 +2535,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()); @@ -2520,7 +2545,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()); @@ -2530,7 +2555,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(); } } diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp index 474079037b..7d4921203c 100644 --- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp +++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp @@ -29,7 +29,7 @@ #include <QtTest/QtTest> - +#include <qbuffer.h> #include <qtextdocument.h> #include <qtextdocumentfragment.h> #include <qtexttable.h> @@ -44,6 +44,7 @@ #include <QPainter> #include <QPaintEngine> #endif +#include <private/qtextdocumentlayout_p.h> #include <private/qpagedpaintdevice_p.h> typedef QList<int> IntList; @@ -100,6 +101,13 @@ private slots: void checkBorderAttributes_data(); void checkBorderAttributes(); +#ifndef QT_NO_WIDGETS + void columnWidthWithSpans(); + + void columnWidthWithImage_data(); + void columnWidthWithImage(); +#endif + private: QTextTable *create2x2Table(); QTextTable *create4x4Table(); @@ -1278,5 +1286,84 @@ void tst_QTextTable::checkBorderAttributes() } } +#ifndef QT_NO_WIDGETS +void tst_QTextTable::columnWidthWithSpans() +{ + cleanup(); + init(); + QTextTable *table = cursor.insertTable(4, 4); + QTextEdit textEdit; + textEdit.setDocument(doc); + textEdit.show(); + QVERIFY(QTest::qWaitForWindowExposed(&textEdit)); + + for (int i = 0; i < table->columns(); ++i) + table->cellAt(0, i).firstCursorPosition().insertText(QString("Header %1").arg(i)); + + QTextBlock block = table->cellAt(0, 0).firstCursorPosition().block(); + const QRectF beforeRect = table->document()->documentLayout()->blockBoundingRect(block); + table->mergeCells(1, 0, 1, table->columns()); + block = table->cellAt(0, 0).firstCursorPosition().block(); + const QRectF afterRect = table->document()->documentLayout()->blockBoundingRect(block); + QCOMPARE(afterRect, beforeRect); +} + +void tst_QTextTable::columnWidthWithImage_data() +{ + const auto imageHtml = [](int width, int height) { + QImage image(width, height, QImage::Format_RGB32); + image.fill(Qt::red); + QByteArray imageBytes; + QBuffer buffer(&imageBytes); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "png"); + return QString("<td><img src='data:image/png;base64,%1'/></td>") + .arg(QString::fromLatin1(imageBytes.toBase64())); + }; + + QTest::addColumn<QString>("leftHtml"); + QTest::addColumn<QString>("rightHtml"); + QTest::addColumn<QSize>("imageSize"); + QTest::addRow("image") + << imageHtml(500, 32) << "<td></td>" << QSize(500, 32); + QTest::addRow("image, text") + << imageHtml(32, 32) << "<td>abc</td>" << QSize(32, 32); + QTest::addRow("image, 100%% text") + << imageHtml(32, 32) << "<td style='background-color: grey' width='100%'>abc</td>" + << QSize(32, 32); + QTest::addRow("image, image") + << imageHtml(256, 32) << imageHtml(256, 32) << QSize(256, 32); +} + +void tst_QTextTable::columnWidthWithImage() +{ + const QString tableTemplate = "<table><tr>%1 %2</tr></table>"; + + QFETCH(QString, leftHtml); + QFETCH(QString, rightHtml); + QFETCH(QSize, imageSize); + + QTextDocument doc; + doc.setHtml(tableTemplate.arg(leftHtml).arg(rightHtml)); + QTextEdit textEdit; + textEdit.setDocument(&doc); + textEdit.show(); + QVERIFY(QTest::qWaitForWindowExposed(&textEdit)); + + QTextCursor cursor(doc.firstBlock()); + cursor.movePosition(QTextCursor::Right); + + QTextTable *currentTable = cursor.currentTable(); + QVERIFY(currentTable); + + QTextBlock block = currentTable->cellAt(0, 0).firstCursorPosition().block(); + const QRectF leftRect = currentTable->document()->documentLayout()->blockBoundingRect(block); + block = currentTable->cellAt(0, 1).firstCursorPosition().block(); + const QRectF rightRect = currentTable->document()->documentLayout()->blockBoundingRect(block); + QCOMPARE(leftRect.size().toSize(), imageSize); + QVERIFY(rightRect.left() > leftRect.right()); +} +#endif + QTEST_MAIN(tst_QTextTable) #include "tst_qtexttable.moc" |