diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-10-03 16:51:19 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-10-14 09:04:29 +0200 |
commit | 253ce59c12d60ded2278e6d5bb8399e44bd4d302 (patch) | |
tree | 48ab421e5d8a77314fc6ffa327b3167e65d0d767 /src/platformsupport/fontdatabases/mac | |
parent | 66a9c4b0b259fe9a61150b7394af0f31ebfd38ac (diff) |
CoreText: Use StyleHint as fallback when family is not found
Change-Id: I11fb6cafe9d41c38eac6ca0695c89f30f998f257
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/platformsupport/fontdatabases/mac')
-rw-r--r-- | src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 4887a501ba..2e8e726c70 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -444,6 +444,14 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family) return QStringList(); } + // If the font is not available we want to fall back to the style hint. + // By creating a matching font descriptor we can verify whether the font + // is available or not, and avoid CTFontCreateWithFontDescriptor picking + // a default font for us based on incomplete information. + fontDescriptor = CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptor, 0); + if (!fontDescriptor) + return QStringList(); + QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0); if (!font) { qCWarning(lcQpaFonts) << "Failed to create fallback font for" << family; @@ -472,6 +480,10 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo { Q_UNUSED(style); + qCDebug(lcQpaFonts).nospace() << "Resolving fallbacks for" + << (!family.isEmpty() ? qPrintable(QLatin1String(" family '%1' with").arg(family)) : "") + << " style hint " << styleHint; + QMacAutoReleasePool pool; QStringList fallbackList = fallbacksForFamily(family); @@ -479,6 +491,9 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo if (fallbackList.isEmpty()) { // We were not able to find a fallback for the specific family, // or the family was empty, so we fall back to the style hint. + if (!family.isEmpty()) + qCDebug(lcQpaFonts) << "No fallbacks found. Using style hint instead"; + QString styleFamily = [styleHint]{ switch (styleHint) { case QFont::SansSerif: return QStringLiteral("Helvetica"); @@ -541,6 +556,8 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &); fallbackList = qt_sort_families_by_writing_system(script, fallbackList); + qCDebug(lcQpaFonts).nospace() << "Resolved fallbacks ordered by script " << script << ": " << fallbackList; + return fallbackList; } |