CoreText: Maintain theme fonts in the font database instead of themes
The ownership of the fonts were handled in the iOS and macOS themes, but the CoreText font database also kept a reference to these fonts. As there was no way for the themes to reset the font database references we could potentially end up in a situation where the font database had stale references. And as the font database would not rebuild the theme fonts once populated the themes then would not be able to build a new list of theme fonts. Moving the ownership to the font database makes semantics and management of the fonts clearer. Pick-to: 6.3 6.2 Change-Id: I61756abaf5487f28d520dfa1cf7a8ee2d716cce6 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
8c4894f94b
commit
ee15aa7482
@ -109,6 +109,8 @@ QCoreTextFontDatabase::QCoreTextFontDatabase()
|
||||
|
||||
QCoreTextFontDatabase::~QCoreTextFontDatabase()
|
||||
{
|
||||
qDeleteAll(m_themeFonts);
|
||||
|
||||
for (CTFontDescriptorRef ref : qAsConst(m_systemFontDescriptors))
|
||||
CFRelease(ref);
|
||||
}
|
||||
|
@ -89,7 +89,6 @@ private:
|
||||
mutable QPalette *m_systemPalette;
|
||||
QMacNotificationObserver m_systemColorObserver;
|
||||
mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes;
|
||||
mutable QHash<QPlatformTheme::Font, QFont*> m_fonts;
|
||||
QMacKeyValueObserver m_appearanceObserver;
|
||||
};
|
||||
|
||||
|
@ -297,7 +297,6 @@ QCocoaTheme::QCocoaTheme()
|
||||
QCocoaTheme::~QCocoaTheme()
|
||||
{
|
||||
reset();
|
||||
qDeleteAll(m_fonts);
|
||||
}
|
||||
|
||||
void QCocoaTheme::reset()
|
||||
@ -370,12 +369,9 @@ const QPalette *QCocoaTheme::palette(Palette type) const
|
||||
|
||||
const QFont *QCocoaTheme::font(Font type) const
|
||||
{
|
||||
if (m_fonts.isEmpty()) {
|
||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||
const auto *coreTextFontDb = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||
m_fonts = coreTextFontDb->themeFonts();
|
||||
}
|
||||
return m_fonts.value(type, nullptr);
|
||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||
const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||
return coreTextFontDatabase->themeFonts().value(type, nullptr);
|
||||
}
|
||||
|
||||
//! \internal
|
||||
|
@ -68,8 +68,6 @@ public:
|
||||
static void initializeSystemPalette();
|
||||
|
||||
private:
|
||||
mutable QHash<QPlatformTheme::Font, QFont *> m_fonts;
|
||||
|
||||
static QPalette s_systemPalette;
|
||||
};
|
||||
|
||||
|
@ -70,7 +70,6 @@ QIOSTheme::QIOSTheme()
|
||||
|
||||
QIOSTheme::~QIOSTheme()
|
||||
{
|
||||
qDeleteAll(m_fonts);
|
||||
}
|
||||
|
||||
QPalette QIOSTheme::s_systemPalette;
|
||||
@ -170,12 +169,9 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const
|
||||
|
||||
const QFont *QIOSTheme::font(Font type) const
|
||||
{
|
||||
if (m_fonts.isEmpty()) {
|
||||
QCoreTextFontDatabase *ctfd = static_cast<QCoreTextFontDatabase *>(QGuiApplicationPrivate::platformIntegration()->fontDatabase());
|
||||
m_fonts = ctfd->themeFonts();
|
||||
}
|
||||
|
||||
return m_fonts.value(type, 0);
|
||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||
const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||
return coreTextFontDatabase->themeFonts().value(type, nullptr);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user