CoreText: Make population of theme fonts explicit
Pick-to: 6.2 6.3 Change-Id: I95e6b535e8ec98ca13c9a58f1e4ae4358ed9f028 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>bb10
parent
8e08286d45
commit
1ab928c7f6
|
|
@ -128,11 +128,7 @@ void QCoreTextFontDatabase::populateFontDatabase()
|
|||
|
||||
qCDebug(lcQpaFonts) << "Populating available families took" << elapsed.restart() << "ms";
|
||||
|
||||
// Force creating the theme fonts to get the descriptors in m_systemFontDescriptors
|
||||
if (m_themeFonts.isEmpty())
|
||||
(void)themeFonts();
|
||||
|
||||
qCDebug(lcQpaFonts) << "Resolving theme fonts took" << elapsed.restart() << "ms";
|
||||
populateThemeFonts();
|
||||
|
||||
for (CTFontDescriptorRef fontDesc : m_systemFontDescriptors)
|
||||
populateFromDescriptor(fontDesc);
|
||||
|
|
@ -752,31 +748,43 @@ static CTFontDescriptorRef fontDescriptorFromTheme(QPlatformTheme::Font f)
|
|||
return descriptorForFontType(fontTypeFromTheme(f));
|
||||
}
|
||||
|
||||
const QHash<QPlatformTheme::Font, QFont *> &QCoreTextFontDatabase::themeFonts() const
|
||||
void QCoreTextFontDatabase::populateThemeFonts()
|
||||
{
|
||||
if (m_themeFonts.isEmpty()) {
|
||||
for (long f = QPlatformTheme::SystemFont; f < QPlatformTheme::NFonts; f++) {
|
||||
QPlatformTheme::Font ft = static_cast<QPlatformTheme::Font>(f);
|
||||
m_themeFonts.insert(ft, themeFont(ft));
|
||||
}
|
||||
if (!m_themeFonts.isEmpty())
|
||||
return;
|
||||
|
||||
QElapsedTimer elapsed;
|
||||
if (lcQpaFonts().isDebugEnabled())
|
||||
elapsed.start();
|
||||
|
||||
qCDebug(lcQpaFonts) << "Populating theme fonts...";
|
||||
|
||||
for (long f = QPlatformTheme::SystemFont; f < QPlatformTheme::NFonts; f++) {
|
||||
QPlatformTheme::Font themeFont = static_cast<QPlatformTheme::Font>(f);
|
||||
CTFontDescriptorRef fontDescriptor = fontDescriptorFromTheme(themeFont);
|
||||
FontDescription fd;
|
||||
getFontDescription(fontDescriptor, &fd);
|
||||
|
||||
if (!m_systemFontDescriptors.contains(fontDescriptor))
|
||||
m_systemFontDescriptors.insert(fontDescriptor);
|
||||
else
|
||||
CFRelease(fontDescriptor);
|
||||
|
||||
QFont *font = new QFont(fd.familyName, fd.pointSize, fd.weight, fd.style == QFont::StyleItalic);
|
||||
m_themeFonts.insert(themeFont, font);
|
||||
}
|
||||
|
||||
return m_themeFonts;
|
||||
qCDebug(lcQpaFonts) << "Populating theme fonts took" << elapsed.restart() << "ms";
|
||||
}
|
||||
|
||||
QFont *QCoreTextFontDatabase::themeFont(QPlatformTheme::Font f) const
|
||||
{
|
||||
CTFontDescriptorRef fontDesc = fontDescriptorFromTheme(f);
|
||||
FontDescription fd;
|
||||
getFontDescription(fontDesc, &fd);
|
||||
// The code paths via QFontDatabase::systemFont() or QPlatformTheme::font()
|
||||
// do not ensure that the font database has been populated, so we need to
|
||||
// manually populate the theme fonts lazily here just in case.
|
||||
const_cast<QCoreTextFontDatabase*>(this)->populateThemeFonts();
|
||||
|
||||
if (!m_systemFontDescriptors.contains(fontDesc))
|
||||
m_systemFontDescriptors.insert(fontDesc);
|
||||
else
|
||||
CFRelease(fontDesc);
|
||||
|
||||
QFont *font = new QFont(fd.familyName, fd.pointSize, fd.weight, fd.style == QFont::StyleItalic);
|
||||
return font;
|
||||
return m_themeFonts.value(f, nullptr);
|
||||
}
|
||||
|
||||
QFont QCoreTextFontDatabase::defaultFont() const
|
||||
|
|
|
|||
|
|
@ -83,20 +83,20 @@ public:
|
|||
bool fontsAlwaysScalable() const override;
|
||||
QList<int> standardSizes() const override;
|
||||
|
||||
// For iOS and OS X platform themes
|
||||
// For iOS and macOS platform themes
|
||||
QFont *themeFont(QPlatformTheme::Font) const;
|
||||
const QHash<QPlatformTheme::Font, QFont *> &themeFonts() const;
|
||||
|
||||
protected:
|
||||
mutable QSet<CTFontDescriptorRef> m_systemFontDescriptors;
|
||||
|
||||
private:
|
||||
void populateThemeFonts();
|
||||
void populateFromDescriptor(CTFontDescriptorRef font, const QString &familyName = QString(), QFontDatabasePrivate::ApplicationFont *applicationFont = nullptr);
|
||||
static CFArrayRef fallbacksForFamily(const QString &family);
|
||||
|
||||
mutable QString defaultFontName;
|
||||
|
||||
mutable QHash<QPlatformTheme::Font, QFont *> m_themeFonts;
|
||||
QHash<QPlatformTheme::Font, QFont *> m_themeFonts;
|
||||
bool m_hasPopulatedAliases;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ const QFont *QCocoaTheme::font(Font type) const
|
|||
{
|
||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||
const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||
return coreTextFontDatabase->themeFonts().value(type, nullptr);
|
||||
return coreTextFontDatabase->themeFont(type);
|
||||
}
|
||||
|
||||
//! \internal
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ const QFont *QIOSTheme::font(Font type) const
|
|||
{
|
||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||
const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||
return coreTextFontDatabase->themeFonts().value(type, nullptr);
|
||||
return coreTextFontDatabase->themeFont(type);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue