From d5abda313dab0f83873d34b7c4ddbe8d8a06dacf Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 25 Sep 2019 15:11:29 +0200 Subject: iOS: Fix fallback fonts on iOS 13+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since iOS 13, the cascade list for the default UI font contains meta-families for several writing systems, such as CJK. Since these font families were never populated to the database, we ignored them in Qt, and thus got missing glyphs for the characters in question. The fix is to make sure these fonts are populated in the database. It contains a partial backport of 922d195020d54d7e599d135f6a5e0338100e08f1, which adds the qt_isFamilyPopulated() accessor to allow us to check if the family has been populated in the font database. In Qt 5.14, there is public API for this in QPlatformFontDatabase, so this is a temporary resolution until then. Fixes: QTBUG-77467 Change-Id: Ia9ebb8a19ad2367eb764ae1496a52966b465336b Reviewed-by: Tor Arne Vestbø --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 047773d8e3..e8ea194897 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -454,6 +454,9 @@ static void addExtraFallbacks(QStringList *fallbackList) #endif } +// ### Replace this with QPlatformFontDatabase::isFamilyPopulated() in Qt 5.14 +Q_GUI_EXPORT extern bool qt_isFontFamilyPopulated(const QString &familyName); + QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const { Q_UNUSED(style); @@ -481,7 +484,25 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo fallbackList.append(QString::fromCFString(fallbackFamilyName)); } + // .Apple Symbols Fallback will be at the beginning of the list and we will + // detect that this has glyphs for Arabic and other writing systems. + // Since it is a symbol font, it should be the last resort, so that + // the proper fonts for these writing systems are preferred. + int symbolIndex = fallbackList.indexOf(QLatin1String(".Apple Symbols Fallback")); + if (symbolIndex >= 0) + fallbackList.move(symbolIndex, fallbackList.size() - 1); + addExtraFallbacks(&fallbackList); + + // Since iOS 13, the cascade list may contain meta-fonts which have not been + // populated to the database, such as ".AppleJapaneseFont". It is important that we + // include this in the fallback list, in order to get fallback support for all + // languages + for (const QString &fallback : fallbackList) { + if (!qt_isFontFamilyPopulated(fallback)) + const_cast(this)->populateFamily(fallback); + } + extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &); fallbackList = qt_sort_families_by_writing_system(script, fallbackList); -- cgit v1.2.3