Simplify QFontDatabase::findFont()

QFontDatabase::load() is the only caller that passes non-null
QFontPrivate* to QFontDatabase::findFont(), to adjust the pointSize
with regards to the font's dpi; do that right in QFontDatabase::load().
The `multi` param's meaning is, in fact, an absence of the
QFont::NoFontMerging flag,
so prefer the latter and prevent ambiguity in the future.

Change-Id: Icc7751044e454ca438e7627364faa415287bf1ae
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
Konstantin Ritt 2015-05-01 08:18:36 +04:00
parent 994a7476ef
commit c874e10cbc
3 changed files with 22 additions and 19 deletions

View File

@ -630,6 +630,7 @@ static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDe
} else {
fontDef->pixelSize = desc.size->pixelSize;
}
fontDef->pointSize = request.pointSize;
fontDef->styleHint = request.styleHint;
fontDef->styleStrategy = request.styleStrategy;
@ -2505,9 +2506,7 @@ bool QFontDatabase::supportsThreadedFontRendering()
/*!
\internal
*/
QFontEngine *
QFontDatabase::findFont(int script, const QFontPrivate *fp,
const QFontDef &request, bool multi)
QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
{
QMutexLocker locker(fontDatabaseMutex());
@ -2515,6 +2514,11 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
initializeDb();
QFontEngine *engine;
// Until we specifically asked not to, try looking for Multi font engine
// first, the last '1' indicates that we want Multi font engine instead
// of single ones
bool multi = !(request.styleStrategy & QFont::NoFontMerging);
QFontCache::Key key(request, script, multi ? 1 : 0);
engine = QFontCache::instance()->findEngine(key);
if (engine) {
@ -2529,6 +2533,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
if (qt_enable_test_font && request.family == QLatin1String("__Qt__Box__Engine__")) {
engine =new QTestFontEngine(request.pixelSize);
engine->fontDef = request;
return engine;
}
QtFontDesc desc;
@ -2537,7 +2542,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
if (index >= 0) {
engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size);
if (engine)
initFontDef(desc, request, &engine->fontDef, engine->type() == QFontEngine::Multi);
initFontDef(desc, request, &engine->fontDef, multi);
else
blackListed.append(index);
} else {
@ -2573,7 +2578,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
loadDef.family = desc.family->name;
engine = loadEngine(script, loadDef, desc.family, desc.foundry, desc.style, desc.size);
if (engine)
initFontDef(desc, loadDef, &engine->fontDef, engine->type() == QFontEngine::Multi);
initFontDef(desc, loadDef, &engine->fontDef, multi);
else
blackListed.append(index);
}
@ -2588,12 +2593,6 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
FM_DEBUG("returning box engine");
}
if (fp && fp->dpi > 0) {
engine->fontDef.pointSize = qreal(double((engine->fontDef.pixelSize * 72) / fp->dpi));
} else {
engine->fontDef.pointSize = request.pointSize;
}
return engine;
}
@ -2661,12 +2660,16 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
for (; !fe && it != end; ++it) {
req.family = *it;
fe = QFontDatabase::findFont(script, d, req, multi);
if (fe && (fe->type()==QFontEngine::Box) && !req.family.isEmpty()) {
fe = QFontDatabase::findFont(req, script);
if (fe) {
if (fe->type() == QFontEngine::Box && !req.family.isEmpty()) {
if (fe->ref.load() == 0)
delete fe;
fe = 0;
} else {
if (d->dpi > 0)
fe->fontDef.pointSize = qreal(double((fe->fontDef.pixelSize * 72) / d->dpi));
}
}
// No need to check requested fallback families again

View File

@ -153,7 +153,7 @@ private:
static void createDatabase();
static void parseFontName(const QString &name, QString &foundry, QString &family);
static QString resolveFontFamilyAlias(const QString &family);
static QFontEngine *findFont(int script, const QFontPrivate *fp, const QFontDef &request, bool multi = false);
static QFontEngine *findFont(const QFontDef &request, int script);
static void load(const QFontPrivate *d, int script);
friend struct QFontDef;

View File

@ -1641,7 +1641,7 @@ QFontEngine *QFontEngineMulti::loadEngine(int at)
request.styleStrategy |= QFont::NoFontMerging;
request.family = fallbackFamilyAt(at - 1);
if (QFontEngine *engine = QFontDatabase::findFont(m_script, /*fontprivate = */0, request, /*multi = */false)) {
if (QFontEngine *engine = QFontDatabase::findFont(request, m_script)) {
engine->fontDef = request;
return engine;
}