Support specifying fallbacks in font request on QPA

Because the QPA font database would query fallback families inside
findFont(), support for requesting multiple font families in order
of preference (like QFont("Times New Roman, Arial")) did not work,
because the Arial fallback was never attempted. To fix this, we
pass in the queried fallbacks and make sure they are tried before
any platform specific fallbacks.

Task-number: QTBUG-20986
Change-Id: Idb2b717856f013ce2874f00a8debaff60176d2fc
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2012-05-10 16:50:33 +02:00 committed by Qt by Nokia
parent ba300f42bd
commit 4959e6af8e
3 changed files with 18 additions and 7 deletions

View File

@ -56,6 +56,7 @@
#include "QtGui/qfont.h"
#include "QtCore/qmap.h"
#include "QtCore/qobject.h"
#include "QtCore/qstringlist.h"
#include <private/qunicodetables_p.h>
#include <QtGui/qfontdatabase.h>
#include "private/qfixed_p.h"
@ -79,6 +80,7 @@ struct QFontDef
QString family;
QString styleName;
QStringList fallBackFamilies;
qreal pointSize;
qreal pixelSize;

View File

@ -317,7 +317,12 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
if (!engine) {
if (!request.family.isEmpty()) {
QStringList fallbacks = fallbackFamilies(request.family,QFont::Style(request.style),QFont::StyleHint(request.styleHint),QUnicodeTables::Script(script));
QStringList fallbacks = request.fallBackFamilies
+ fallbackFamilies(request.family,
QFont::Style(request.style),
QFont::StyleHint(request.styleHint),
QUnicodeTables::Script(script));
for (int i = 0; !engine && i < fallbacks.size(); i++) {
QFontDef def = request;
def.family = fallbacks.at(i);
@ -386,7 +391,13 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
QStringList family_list;
if (!req.family.isEmpty()) {
family_list = familyList(req);
QStringList familiesForRequest = familyList(req);
// Add primary selection
family_list << familiesForRequest.takeFirst();
// Fallbacks requested in font request
req.fallBackFamilies = familiesForRequest;
// add the default family
QString defaultFamily = QGuiApplication::font().family();
@ -409,6 +420,9 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
fe = 0;
}
// No need to check requested fallback families again
req.fallBackFamilies.clear();
}
if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) {

View File

@ -1592,11 +1592,6 @@ void tst_QCssParser::extractFontFamily()
extractor.extractFont(&fnt, &adjustment);
QFontInfo info(fnt);
// Note, we have to QSKIP rather than QEXPECT_FAIL because font lookup is broken
// such that it may work or not work depending on the order in which fonts were
// loaded from disk: ### fixme: Check platforms
QSKIP("QTBUG-20986 may fail on qpa");
QTEST(info.family(), "expectedFamily");
}