Fix fallback fonts for non-common writing system
When we request fallback fonts, we cannot discriminate the fonts based on the writing system support. This is especially important since common script is now merged with other scripts, meaning that a common script character will always go through the fallback mechanism when not supported by the main font. When drawing for instance a string of Devanagari characters on macOS, we would get a list of 33 fallback fonts, but almost all of them would be the default Devanagari font, since none of the other fallbacks would support that script. Meaning that we would just check the same font over and over, which makes no sense. The fallback list has been retrieved specifically for the given script, so we do not need to consider that when fetching the fonts. For most of the common set, we will not have noticed the bug, because at least one of the writing system-specific fallbacks will have had support for latin characters as well. But when trying to mix emojis and some non-common script, we would get a box in place of the emoji, which had been adopted to the main script and would only be looked for in the fonts supporting this. Note that this exposed an issue with the QRawFont test on some systems. When the sample text contained a space, it would be possible to get a fallback font for this character, since we now effectively support fallbacks. This is not the correct behavior, but it is unrelated to this fix, and it was not what the QRawFont::unsupportedWritingSystem() test was written to check. I have therefore removed the space from the sample text to make the test pass, and will make a separate task of fixing the issue of merging fonts for whitespace characters. [ChangeLog][QtGui][Text] Fixed a bug where mixing different writing systems with emojis could lead to missing glyphs. Task-number: QTBUG-61882 Change-Id: I00f6043bb01af1f2277723ccf643034aebf3e18f Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
parent
e586d9ea7f
commit
6ca48a847a
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2018 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
@ -1847,7 +1847,12 @@ QFontEngine *QFontEngineMulti::loadEngine(int at)
|
||||
request.styleStrategy |= QFont::NoFontMerging;
|
||||
request.family = fallbackFamilyAt(at - 1);
|
||||
|
||||
if (QFontEngine *engine = QFontDatabase::findFont(request, m_script)) {
|
||||
// At this point, the main script of the text has already been considered
|
||||
// when fetching the list of fallback families from the database, and the
|
||||
// info about the actual script of the characters may have been discarded,
|
||||
// so we do not check for writing system support, but instead just load
|
||||
// the family indiscriminately.
|
||||
if (QFontEngine *engine = QFontDatabase::findFont(request, QFontDatabase::Any)) {
|
||||
engine->fontDef.weight = request.weight;
|
||||
if (request.style > QFont::StyleNormal)
|
||||
engine->fontDef.style = request.style;
|
||||
|
@ -887,7 +887,7 @@ void tst_QRawFont::unsupportedWritingSystem()
|
||||
QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont"));
|
||||
QCOMPARE(rawFont.pixelSize(), 12.0);
|
||||
|
||||
QString arabicText = QFontDatabase::writingSystemSample(QFontDatabase::Arabic);
|
||||
QString arabicText = QFontDatabase::writingSystemSample(QFontDatabase::Arabic).simplified().remove(QLatin1Char(' '));
|
||||
|
||||
QTextLayout layout;
|
||||
layout.setFont(font);
|
||||
|
Loading…
Reference in New Issue
Block a user