Fix font fallback for an overridden Common script cases

Always prefer the requested font, even if it doesn't support the
script of interest, and fallback to a font that *does* support that
script, so that the best-matching font always takes a precedence.
The result looks much closer to what CT and GDI/DW does.

Task-number: QTBUG-35836
Task-number: QTBUG-39377
Task-number: QTBUG-43408
Change-Id: I6a89593565683f318f7292ec5ecf271dadc4142a
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Konstantin Ritt 2016-04-26 12:09:17 +04:00
parent 6e306e8d94
commit c003a18ee3
3 changed files with 17 additions and 2 deletions

View File

@ -2669,7 +2669,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
QtFontDesc desc;
QList<int> blackListed;
int index = match(script, request, family_name, foundry_name, &desc, blackListed);
int index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed);
if (index >= 0) {
engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size);
if (engine)
@ -2702,7 +2702,7 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script)
if (!engine) {
QtFontDesc desc;
do {
index = match(script, def, def.family, QLatin1String(""), &desc, blackListed);
index = match(multi ? QChar::Script_Common : script, def, def.family, QLatin1String(""), &desc, blackListed);
if (index >= 0) {
QFontDef loadDef = def;
if (loadDef.family.isEmpty())

View File

@ -167,6 +167,7 @@ private:
friend class QFontDialog;
friend class QFontDialogPrivate;
friend class QFontEngineMulti;
friend class QRawFont;
QFontDatabasePrivate *d;
};

View File

@ -700,6 +700,20 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
if (fe != 0 && fe->type() == QFontEngine::Multi) {
QFontEngineMulti *multiEngine = static_cast<QFontEngineMulti *>(fe);
fe = multiEngine->engine(0);
if (script > QChar::Script_Latin) {
// keep in sync with QFontEngineMulti::loadEngine()
QFontDef request(multiEngine->fontDef);
request.styleStrategy |= QFont::NoFontMerging;
if (QFontEngine *engine = QFontDatabase::findFont(request, script)) {
if (request.weight > QFont::Normal)
engine->fontDef.weight = request.weight;
if (request.style > QFont::StyleNormal)
engine->fontDef.style = request.style;
fe = engine;
}
}
Q_ASSERT(fe);
}