summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-08-18 11:47:16 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-08-19 13:35:40 +0200
commit43a63901f4eb61ad8a29f4cc7a1700685f88ec35 (patch)
tree0f2b3e4f811cbdcd1fb87d7ecf8eb4fc72606c53 /tests/auto/gui
parent2059d294eb525fe23d1a7681a1563efb513fe31e (diff)
Fix bug with NoFontMerging when font does not support script
When using NoFontMerging, no fallbacks should be resolved. If the font does not support a specific character in the text, we should display a box instead of merging it with another font. But in practice, Qt would still apply the fallback mechanism for one specific case: If the font itself does not support the script of the text, we would get no match and do a search for a fallback instead. Since NoFontMerging is set, we would then force this as preresolved for *all* scripts in the QFont's private data (logically, the match should only have a single response for NoFontMerging). The end result was that if you set the font family before updating the text, you would get broken rendering. This can happen e.g. in Qt Quick, where you could update the font family of a text label while it contains characters which are not supported by the new font. Qt would then pick a fallback instead. When you subsequently update the text, the fallback would already be preresolved for whatever script this is. If it does not support the updated text, we would then see boxes, even if the requested font actually would have supported it. The fix is simply to do an additional pass if NoFontMerging is set and we were not able to match with the specified script. Since the same family might be available in different foundries, with different writing system support, we still want to do a pass first to see if we can match the exact script of the text. Note that QRawFont::fromFont() exploited the bug by using NoFontMerging for getting the fallback font for a specific writing system. To keep this working without having to rewrite fromFont() and risk introducing regressions, we add an argument to make the findFont() function behave as before. It isn't super-pretty, but since it is private API it is hopefully fine. [ChangeLog][QtGui][Text] Fixed an issue with NoFontMerging and changing font families dynamically, where boxes would be seen in place of the correct text. Pick-to: 5.15 6.1 6.2 Done-with: Andy Shaw Fixes: QTBUG-81770 Change-Id: Ide9a36d7528a1040172c5864fa99e7a82eac4e83 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index c324aa3549..a730174ee9 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -652,6 +652,7 @@ void tst_QRawFont::fromFont_data()
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
QTest::addColumn<QString>("familyName");
QTest::addColumn<QFontDatabase::WritingSystem>("writingSystem");
+ QTest::addColumn<QFont::StyleStrategy>("styleStrategy");
for (int i=QFont::PreferDefaultHinting; i<=QFont::PreferFullHinting; ++i) {
QString titleBase = QString::fromLatin1("%2, hintingPreference=%1, writingSystem=%3")
@@ -665,7 +666,8 @@ void tst_QRawFont::fromFont_data()
<< fileName
<< QFont::HintingPreference(i)
<< "QtBidiTestFont"
- << writingSystem;
+ << writingSystem
+ << QFont::PreferDefault;
}
{
@@ -677,7 +679,8 @@ void tst_QRawFont::fromFont_data()
<< fileName
<< QFont::HintingPreference(i)
<< "QtBidiTestFont"
- << writingSystem;
+ << writingSystem
+ << QFont::PreferDefault;
}
{
@@ -689,9 +692,24 @@ void tst_QRawFont::fromFont_data()
<< fileName
<< QFont::HintingPreference(i)
<< "QtBidiTestFont"
- << writingSystem;
+ << writingSystem
+ << QFont::PreferDefault;
}
}
+
+ {
+ QString fileName = testFont;
+ QFontDatabase::WritingSystem writingSystem = QFontDatabase::Arabic;
+
+ QString title = QStringLiteral("No font merging + unsupported script");
+ QTest::newRow(qPrintable(title))
+ << fileName
+ << QFont::PreferDefaultHinting
+ << "QtBidiTestFont"
+ << writingSystem
+ << QFont::NoFontMerging;
+ }
+
}
void tst_QRawFont::fromFont()
@@ -700,6 +718,7 @@ void tst_QRawFont::fromFont()
QFETCH(QFont::HintingPreference, hintingPreference);
QFETCH(QString, familyName);
QFETCH(QFontDatabase::WritingSystem, writingSystem);
+ QFETCH(QFont::StyleStrategy, styleStrategy);
int id = QFontDatabase::addApplicationFont(fileName);
QVERIFY(id >= 0);
@@ -707,6 +726,8 @@ void tst_QRawFont::fromFont()
QFont font(familyName);
font.setHintingPreference(hintingPreference);
font.setPixelSize(26.0);
+ if (styleStrategy != QFont::PreferDefault)
+ font.setStyleStrategy(styleStrategy);
QRawFont rawFont = QRawFont::fromFont(font, writingSystem);
QVERIFY(rawFont.isValid());