Use fixed font, tighten tolerance in TextEdit largeTextObservesViewport

In tst_qquicktextedit::largeTextObservesViewport(), we needed tolerances
on the expected region to be rendered after scrolling by a particular
pixel delta, because there is so much variation in the default font
between platforms. Clearly, the solution is to use a specific font file;
so now there's a FontLoader to apply it to the TextEdit.
"tarzeau_ocr_a.ttf" is already present elsewhere in this git repository.

High-dpi scaling still seems to make some difference though (rounding
differences presumably), so we still need the tolerances, but they
don't need to be as broad as they did.

Amends 9db23e0e04

Task-number: QTBUG-103096
Change-Id: Ia45d8a93c0ef3d4bfe1fa3e00ecfcc3e89979815
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Shawn Rutledge 2022-10-21 22:02:01 +02:00
parent 8d3aa3baa1
commit f18b33b36f
3 changed files with 21 additions and 11 deletions

Binary file not shown.

View File

@ -9,8 +9,15 @@ Item {
anchors.margins: 100
border.color: "red"
FontLoader {
id: ocr
source: "tarzeau_ocr_a.ttf"
}
TextEdit {
font.pixelSize: 10
font.family: ocr.font.family
font.styleName: ocr.font.styleName
font.pixelSize: 15
cursorDelegate: Rectangle {
border.color: "green"
border.width: 2

View File

@ -3764,15 +3764,15 @@ void tst_qquicktextedit::largeTextObservesViewport_data()
// QQuickTextEdit doesn't populate lines of text beyond the bottom of the window
// cursor position 1000 is on line 121
QTest::newRow("default plain text") << text << QQuickTextEdit::PlainText << false << 1000 << 0
<< 5 << 114 << 155 << 1200 << 2200;
<< 1 << 118 << 142 << 2400 << 3000;
// make the rectangle into a viewport item, and move the text upwards:
// QQuickTextEdit doesn't populate lines of text beyond the bottom of the viewport rectangle
QTest::newRow("clipped plain text") << text << QQuickTextEdit::PlainText << true << 1000 << 0
<< 5 << 123 << 147 << 1200 << 2100;
<< 1 << 123 << 137 << 2550 << 3000;
// scroll backwards
QTest::newRow("scroll backwards in plain text") << text << QQuickTextEdit::PlainText << true << 1000 << 600
<< 10 << 72 << 97 << 600 << 1500;
<< 1 << 93 << 108 << 1475 << 2300;
{
QStringList lines;
@ -3796,20 +3796,20 @@ void tst_qquicktextedit::largeTextObservesViewport_data()
// by default, the root item acts as the viewport:
// QQuickTextEdit doesn't populate blocks beyond the bottom of the window
QTest::newRow("default styled text") << text << QQuickTextEdit::RichText << false << 1000 << 0
<< 120 << 7 << 143 << 2700 << 3700;
<< 1 << 124 << 139 << 3900 << 4500;
// make the rectangle into a viewport item, and move the text upwards:
// QQuickTextEdit doesn't populate blocks that don't intersect the viewport rectangle
QTest::newRow("clipped styled text") << text << QQuickTextEdit::RichText << true << 1000 << 0
<< 3 << 127 << 139 << 2800 << 3600;
<< 1 << 127 << 136 << 4000 << 4360;
// get the "chapter 2" heading into the viewport
QTest::newRow("heading visible") << text << QQuickTextEdit::RichText << true << 800 << 0
<< 3 << 105 << 116 << 2300 << 3000;
<< 1 << 105 << 113 << 3300 << 3600;
// get the "chapter 2" heading into the viewport, and then scroll backwards
QTest::newRow("scroll backwards") << text << QQuickTextEdit::RichText << true << 800 << 20
<< 3 << 104 << 116 << 2200 << 3000;
<< 1 << 104 << 113 << 3200 << 3600;
// get the "chapter 2" heading into the viewport, and then scroll forwards
QTest::newRow("scroll forwards") << text << QQuickTextEdit::RichText << true << 800 << -50
<< 3 << 107 << 119 << 2300 << 3100;
<< 1 << 106 << 115 << 3300 << 3670;
}
void tst_qquicktextedit::largeTextObservesViewport()
@ -3866,11 +3866,14 @@ void tst_qquicktextedit::largeTextObservesViewport()
<< "region" << textPriv->renderedRegion << "bottom" << textPriv->renderedRegion.bottom()
<< "expected range" << expectedRenderedRegionMin << expectedRenderedRegionMax;
if (scrollDelta >= 0) { // unfortunately firstBlockInViewport isn't always reliable after scrolling
QTRY_IMPL((qAbs(textPriv->firstBlockInViewport - expectedBlocksAboveViewport) < expectedBlockTolerance), 5000);
QTRY_IMPL((qAbs(textPriv->firstBlockInViewport - expectedBlocksAboveViewport) <= expectedBlockTolerance), 5000);
}
QVERIFY2((qAbs(textPriv->firstBlockPastViewport - expectedBlocksPastViewport) < expectedBlockTolerance),
QVERIFY2((qAbs(textPriv->firstBlockInViewport - expectedBlocksAboveViewport) <= expectedBlockTolerance),
qPrintable(QString::fromLatin1("Expected first block in viewport %1 to be near %2 (tolerance: %3)")
.arg(textPriv->firstBlockInViewport).arg(expectedBlocksAboveViewport).arg(expectedBlockTolerance)));
QVERIFY2((qAbs(textPriv->firstBlockPastViewport - expectedBlocksPastViewport) <= expectedBlockTolerance),
qPrintable(QString::fromLatin1("Expected first block past viewport %1 to be near %2 (tolerance: %3)")
.arg(textPriv->firstBlockPastViewport).arg(expectedBlocksPastViewport).arg(expectedBlockTolerance)));
QCOMPARE_GT(textPriv->renderedRegion.top(), expectedRenderedRegionMin);
QCOMPARE_LT(textPriv->renderedRegion.bottom(), expectedRenderedRegionMax);
QVERIFY(textPriv->cursorItem);