From 7b4275b541808a5c26b2524b3bde2b1f9bc56fc1 Mon Sep 17 00:00:00 2001 From: Wang Chuan Date: Sun, 5 Jan 2020 09:34:28 +0800 Subject: QQuickTextNodeEngine: reduce redundant rendering of glyphs The glyphs between two text blocks that have different text format will be rendered twice, and in this case the rich text will be display incorrectly.(e.g., the first text block is a superscript and the second is a normal text) Fixes this by reduce the redundant rendering of glyphs between two differently formatted text blocks Fixes: QTBUG-80759 Change-Id: I51ca3f7df1ad368d28df9beb6124a87bf50f0e01 Reviewed-by: Shawn Rutledge --- .../qquicktext/data/displaySuperscriptedTag.qml | 18 ++++++++++++++ tests/auto/quick/qquicktext/tst_qquicktext.cpp | 28 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml (limited to 'tests/auto/quick/qquicktext') diff --git a/tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml b/tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml new file mode 100644 index 0000000000..b0ed21a0c8 --- /dev/null +++ b/tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Rectangle { + width: 200 + height: 200 + color: "white" + Text { + objectName: "text" + textFormat: Text.RichText + anchors.fill: parent + color: "black" + // display a black rectangle at the top left of the text + text: "This is a test" + verticalAlignment: Text.AlignTop + horizontalAlignment: Text.AlignLeft + font.pixelSize: 30 + } +} diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 06ce730091..a64c9372da 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -168,6 +168,8 @@ private slots: void transparentBackground(); + void displaySuperscriptedTag(); + private: QStringList standard; QStringList richText; @@ -4507,6 +4509,32 @@ void tst_qquicktext::transparentBackground() QCOMPARE(color.blue(), 255); QCOMPARE(color.green(), 255); } + +void tst_qquicktext::displaySuperscriptedTag() +{ + if ((QGuiApplication::platformName() == QLatin1String("offscreen")) + || (QGuiApplication::platformName() == QLatin1String("minimal"))) + QSKIP("Skipping due to grabToImage not functional on offscreen/minimimal platforms"); + + QScopedPointer window(new QQuickView); + window->setSource(testFileUrl("displaySuperscriptedTag.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickText *text = window->findChild("text"); + QVERIFY(text); + + QImage img = window->grabWindow(); + QCOMPARE(img.isNull(), false); + + QColor color = img.pixelColor(1, static_cast(text->contentHeight()) / 4 * 3); + QCOMPARE(color.red(), 255); + QCOMPARE(color.blue(), 255); + QCOMPARE(color.green(), 255); +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" -- cgit v1.2.3