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()
|
QCoreTextFontDatabase::~QCoreTextFontDatabase()
|
||||||
{
|
{
|
||||||
|
qDeleteAll(m_themeFonts);
|
||||||
|
|
||||||
for (CTFontDescriptorRef ref : qAsConst(m_systemFontDescriptors))
|
for (CTFontDescriptorRef ref : qAsConst(m_systemFontDescriptors))
|
||||||
CFRelease(ref);
|
CFRelease(ref);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,6 @@ private:
|
|||||||
mutable QPalette *m_systemPalette;
|
mutable QPalette *m_systemPalette;
|
||||||
QMacNotificationObserver m_systemColorObserver;
|
QMacNotificationObserver m_systemColorObserver;
|
||||||
mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes;
|
mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes;
|
||||||
mutable QHash<QPlatformTheme::Font, QFont*> m_fonts;
|
|
||||||
QMacKeyValueObserver m_appearanceObserver;
|
QMacKeyValueObserver m_appearanceObserver;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -297,7 +297,6 @@ QCocoaTheme::QCocoaTheme()
|
|||||||
QCocoaTheme::~QCocoaTheme()
|
QCocoaTheme::~QCocoaTheme()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
qDeleteAll(m_fonts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCocoaTheme::reset()
|
void QCocoaTheme::reset()
|
||||||
@ -370,12 +369,9 @@ const QPalette *QCocoaTheme::palette(Palette type) const
|
|||||||
|
|
||||||
const QFont *QCocoaTheme::font(Font type) const
|
const QFont *QCocoaTheme::font(Font type) const
|
||||||
{
|
{
|
||||||
if (m_fonts.isEmpty()) {
|
|
||||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||||
const auto *coreTextFontDb = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||||
m_fonts = coreTextFontDb->themeFonts();
|
return coreTextFontDatabase->themeFonts().value(type, nullptr);
|
||||||
}
|
|
||||||
return m_fonts.value(type, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \internal
|
//! \internal
|
||||||
|
@ -68,8 +68,6 @@ public:
|
|||||||
static void initializeSystemPalette();
|
static void initializeSystemPalette();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QHash<QPlatformTheme::Font, QFont *> m_fonts;
|
|
||||||
|
|
||||||
static QPalette s_systemPalette;
|
static QPalette s_systemPalette;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@ QIOSTheme::QIOSTheme()
|
|||||||
|
|
||||||
QIOSTheme::~QIOSTheme()
|
QIOSTheme::~QIOSTheme()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_fonts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPalette QIOSTheme::s_systemPalette;
|
QPalette QIOSTheme::s_systemPalette;
|
||||||
@ -170,12 +169,9 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const
|
|||||||
|
|
||||||
const QFont *QIOSTheme::font(Font type) const
|
const QFont *QIOSTheme::font(Font type) const
|
||||||
{
|
{
|
||||||
if (m_fonts.isEmpty()) {
|
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||||
QCoreTextFontDatabase *ctfd = static_cast<QCoreTextFontDatabase *>(QGuiApplicationPrivate::platformIntegration()->fontDatabase());
|
const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
|
||||||
m_fonts = ctfd->themeFonts();
|
return coreTextFontDatabase->themeFonts().value(type, nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
return m_fonts.value(type, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
Reference in New Issue
Block a user