summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2016-01-27 04:35:05 +0400
committerKonstantin Ritt <ritt.ks@gmail.com>2016-01-29 11:24:49 +0000
commit3e5719ae7b8f4ff2b1aff6d9134386bcc64e5b4b (patch)
tree94b0f9ef7407ce5f17bbdc7f8b6a23b2d7e4a4c3 /tests/auto/gui
parent270cc073b7e0fbc34d635aa70788e70d66433334 (diff)
QFont: Fix possible cache misses due to misprepared cache key
Parse the requested family before we're looking/saving into the cache, thus hitting the cached EngineData for: * quoted family names (eg. QFont("'Arial'")) * non-simplified family names (eg. QFont(" Arial ")) * substituted family names (\sa QFont::insertSubstitution()) * explicit fallback list, where possible (eg. QFont("Tahoma, Arial")) This also improves the cache hitting for the font engines in some cases. Change-Id: I18cdc3e8d669cccec961f84e9b27329402e2b7ed Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qfontcache/tst_qfontcache.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
index c92b7eed58..4d5ddfd523 100644
--- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
+++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
@@ -48,6 +48,9 @@ public:
virtual ~tst_QFontCache();
private slots:
+ void engineData_data();
+ void engineData();
+
void clear();
};
@@ -69,6 +72,52 @@ tst_QFontCache::~tst_QFontCache()
{
}
+void tst_QFontCache::engineData_data()
+{
+ QTest::addColumn<QString>("family");
+ QTest::addColumn<QString>("cacheKey");
+
+ QTest::newRow("unquoted-family-name") << QString("Times New Roman") << QString("Times New Roman");
+ QTest::newRow("quoted-family-name") << QString("'Times New Roman'") << QString("Times New Roman");
+ QTest::newRow("invalid") << QString("invalid") << QString("invalid");
+ QTest::newRow("multiple") << QString("invalid, Times New Roman") << QString("invalid,Times New Roman");
+ QTest::newRow("multiple spaces") << QString("invalid, Times New Roman ") << QString("invalid,Times New Roman");
+ QTest::newRow("multiple spaces quotes") << QString("'invalid', Times New Roman ") << QString("invalid,Times New Roman");
+ QTest::newRow("multiple2") << QString("invalid, Times New Roman , foobar, 'baz'") << QString("invalid,Times New Roman,foobar,baz");
+ QTest::newRow("invalid spaces") << QString("invalid spaces, Times New Roman ") << QString("invalid spaces,Times New Roman");
+ QTest::newRow("invalid spaces quotes") << QString("'invalid spaces', 'Times New Roman' ") << QString("invalid spaces,Times New Roman");
+}
+
+void tst_QFontCache::engineData()
+{
+ QFETCH(QString, family);
+ QFETCH(QString, cacheKey);
+
+ QFont f(family);
+ f.exactMatch(); // loads engine
+
+ QFontPrivate *d = QFontPrivate::get(f);
+
+ QFontDef req = d->request;
+ // copy-pasted from QFontDatabase::load(), to engineer the cache key
+ if (req.pixelSize == -1) {
+ req.pixelSize = std::floor(((req.pointSize * d->dpi) / 72) * 100 + 0.5) / 100;
+ req.pixelSize = qRound(req.pixelSize);
+ }
+ if (req.pointSize < 0)
+ req.pointSize = req.pixelSize*72.0/d->dpi;
+ if (req.weight == 0)
+ req.weight = QFont::Normal;
+ if (req.stretch == 0)
+ req.stretch = 100;
+
+ req.family = cacheKey;
+
+ QFontEngineData *engineData = QFontCache::instance()->findEngineData(req);
+
+ QCOMPARE(engineData, QFontPrivate::get(f)->engineData);
+}
+
void tst_QFontCache::clear()
{
#ifdef QT_BUILD_INTERNAL