void tst_QFontDatabase::localizedFonts() { QFontDatabase db; QVERIFY(db.hasFamily(QString::fromUtf8("ヒラギノ明朝 Pro"))); QVERIFY(!db.hasFamily(QString::fromUtf8("NotValidFont"))); }
void tst_QFont::defaultFamily() { QFETCH(QFont::StyleHint, styleHint); QFETCH(QString, defaultFamily); QFontDatabase db; if (!db.hasFamily(defaultFamily)) QSKIP("Font family is not available on the system"); QFont f; f.setStyleHint(styleHint); QCOMPARE(QFontDatabase::resolveFontFamilyAlias(f.defaultFamily()), QFontDatabase::resolveFontFamilyAlias(defaultFamily)); }
static QString defaultFontFamily() { if (Utils::HostOsInfo::isMacHost()) return QLatin1String("Monaco"); const QString sourceCodePro("Source Code Pro"); const QFontDatabase dataBase; if (dataBase.hasFamily(sourceCodePro)) return sourceCodePro; if (Utils::HostOsInfo::isAnyUnixHost()) return QLatin1String("Monospace"); return QLatin1String("Courier"); }
void tst_QFont::defaultFamily() { QFETCH(QFont::StyleHint, styleHint); QFETCH(QStringList, acceptableFamilies); QFont f; QFontDatabase db; f.setStyleHint(styleHint); const QString familyForHint(f.defaultFamily()); // it should at least return a family that is available. QVERIFY(db.hasFamily(familyForHint)); bool isAcceptable = false; Q_FOREACH (const QString& family, acceptableFamilies) { if (!familyForHint.compare(family, Qt::CaseInsensitive)) { isAcceptable = true; break; } } QVERIFY2(isAcceptable, msgNotAcceptableFont(familyForHint, acceptableFamilies)); }
void tst_QFontCache::clear() { #ifdef QT_BUILD_INTERNAL QFontEngine_startCollectingEngines(); #else // must not crash, at very least ;) #endif QFontEngine *fontEngine = 0; { // we're never caching the box (and the "test") font engines // let's ensure we're not leaking them as well as the cached ones qt_setQtEnableTestFont(true); QFont f; f.setFamily("__Qt__Box__Engine__"); f.exactMatch(); // loads engine } { QFontDatabase db; QFont f; f.setStyleHint(QFont::Serif); const QString familyForHint(f.defaultFamily()); // it should at least return a family that is available QVERIFY(db.hasFamily(familyForHint)); f.exactMatch(); // loads engine fontEngine = QFontPrivate::get(f)->engineForScript(QChar::Script_Common); QVERIFY(fontEngine); QVERIFY(QFontCache::instance()->engineCacheCount.value(fontEngine) > 0); // ensure it is cached // acquire the engine to use it somewhere else: // (e.g. like the we do in QFontSubset() or like QRawFont does in fromFont()) fontEngine->ref.ref(); // cache the engine once again; there is a special case when the engine is cached more than once QFontCache::instance()->insertEngine(QFontCache::Key(QFontDef(), 0, 0), fontEngine); } // use it: // e.g. fontEngine->stringToCMap(..); // and whilst it is alive, don't hesitate to add/remove the app-local fonts: // (QFontDatabase::{add,remove}ApplicationFont() clears the cache) QFontCache::instance()->clear(); // release the acquired engine: if (fontEngine) { if (!fontEngine->ref.deref()) delete fontEngine; fontEngine = 0; } // we may even exit the application now: QFontCache::instance()->cleanup(); #ifdef QT_BUILD_INTERNAL QList<QFontEngine *> leakedEngines = QFontEngine_stopCollectingEngines(); for (int i = 0; i < leakedEngines.size(); ++i) qWarning() << i << leakedEngines.at(i) << leakedEngines.at(i)->ref.load(); // and we are not leaking! QCOMPARE(leakedEngines.size(), 0); #endif }