diff options
author | Wang Chuan <ouchuanm@outlook.com> | 2020-01-05 09:34:28 +0800 |
---|---|---|
committer | Wang Chuan <ouchuanm@outlook.com> | 2020-01-16 15:00:39 +0800 |
commit | 7b4275b541808a5c26b2524b3bde2b1f9bc56fc1 (patch) | |
tree | 06fab0f0bcbb294e55caff918d21aaa755ab26b1 | |
parent | 43e3c21a0bad9141b6c35cc4ee4a58b4d824462a (diff) |
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 <shawn.rutledge@qt.io>
-rw-r--r-- | src/quick/items/qquicktextnodeengine.cpp | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/data/displaySuperscriptedTag.qml | 18 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 28 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index a0ae4e5f97..2356ab36ef 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -532,7 +532,7 @@ void QQuickTextNodeEngine::addGlyphsForRanges(const QVarLengthArray<QTextLayout: int remainingLength = end - start; for (int j=0; j<ranges.size(); ++j) { const QTextLayout::FormatRange &range = ranges.at(j); - if (range.start + range.length >= currentPosition + if (range.start + range.length > currentPosition && range.start < currentPosition + remainingLength) { if (range.start > currentPosition) { 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: "<span style=\"background-color:rgba(255,255,255,255);vertical-align:super;\">█</span>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<QQuickView> 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<QQuickText *>("text"); + QVERIFY(text); + + QImage img = window->grabWindow(); + QCOMPARE(img.isNull(), false); + + QColor color = img.pixelColor(1, static_cast<int>(text->contentHeight()) / 4 * 3); + QCOMPARE(color.red(), 255); + QCOMPARE(color.blue(), 255); + QCOMPARE(color.green(), 255); +} + QTEST_MAIN(tst_qquicktext) #include "tst_qquicktext.moc" |