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:
parent
ba300f42bd
commit
4959e6af8e
@ -56,6 +56,7 @@
|
|||||||
#include "QtGui/qfont.h"
|
#include "QtGui/qfont.h"
|
||||||
#include "QtCore/qmap.h"
|
#include "QtCore/qmap.h"
|
||||||
#include "QtCore/qobject.h"
|
#include "QtCore/qobject.h"
|
||||||
|
#include "QtCore/qstringlist.h"
|
||||||
#include <private/qunicodetables_p.h>
|
#include <private/qunicodetables_p.h>
|
||||||
#include <QtGui/qfontdatabase.h>
|
#include <QtGui/qfontdatabase.h>
|
||||||
#include "private/qfixed_p.h"
|
#include "private/qfixed_p.h"
|
||||||
@ -79,6 +80,7 @@ struct QFontDef
|
|||||||
QString family;
|
QString family;
|
||||||
QString styleName;
|
QString styleName;
|
||||||
|
|
||||||
|
QStringList fallBackFamilies;
|
||||||
|
|
||||||
qreal pointSize;
|
qreal pointSize;
|
||||||
qreal pixelSize;
|
qreal pixelSize;
|
||||||
|
@ -317,7 +317,12 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
|
|||||||
|
|
||||||
if (!engine) {
|
if (!engine) {
|
||||||
if (!request.family.isEmpty()) {
|
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++) {
|
for (int i = 0; !engine && i < fallbacks.size(); i++) {
|
||||||
QFontDef def = request;
|
QFontDef def = request;
|
||||||
def.family = fallbacks.at(i);
|
def.family = fallbacks.at(i);
|
||||||
@ -386,7 +391,13 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
|
|||||||
QStringList family_list;
|
QStringList family_list;
|
||||||
|
|
||||||
if (!req.family.isEmpty()) {
|
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
|
// add the default family
|
||||||
QString defaultFamily = QGuiApplication::font().family();
|
QString defaultFamily = QGuiApplication::font().family();
|
||||||
@ -409,6 +420,9 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
|
|||||||
|
|
||||||
fe = 0;
|
fe = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No need to check requested fallback families again
|
||||||
|
req.fallBackFamilies.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) {
|
if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) {
|
||||||
|
@ -1592,11 +1592,6 @@ void tst_QCssParser::extractFontFamily()
|
|||||||
extractor.extractFont(&fnt, &adjustment);
|
extractor.extractFont(&fnt, &adjustment);
|
||||||
QFontInfo info(fnt);
|
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");
|
QTEST(info.family(), "expectedFamily");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user