iOS: Handle changes in user font preferences by invalidating font database

The user may tweak the appearance of text rendering on iOS to aid a11y,
by making the text larger or smaller, or bold. This feature, known as
Dynamic Type, will be reflected in the preferred content size category
of the application.

When we detect changes in this preferred content size category we respond
by invalidating the font database, which will trigger the application
to re-evaluate the sizes and weights of the theme fonts.

Unfortunately we do not currently pick up or propagate the scaled font
metrics when an explicit point or pixel size has been set on a QFont,
but this problem exists regardless of whether we dynamically handle
changes to dynamic types or only pick them up after an application
restart.

Change-Id: I8c722d0bfb4b76eade47ebfb6512e6676a910d6a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Tor Arne Vestbø 2022-03-24 12:25:55 +01:00
parent d84018616a
commit 3188615db6
2 changed files with 9 additions and 0 deletions

View File

@ -44,6 +44,8 @@
#include <QtGui/QPalette>
#include <qpa/qplatformtheme.h>
#include <QtCore/private/qcore_mac_p.h>
QT_BEGIN_NAMESPACE
class QIOSTheme : public QPlatformTheme
@ -71,6 +73,7 @@ public:
private:
static QPalette s_systemPalette;
QMacNotificationObserver m_contentSizeCategoryObserver;
};
QT_END_NAMESPACE

View File

@ -66,6 +66,12 @@ const char *QIOSTheme::name = "ios";
QIOSTheme::QIOSTheme()
{
initializeSystemPalette();
m_contentSizeCategoryObserver = QMacNotificationObserver(nil,
UIContentSizeCategoryDidChangeNotification, [] {
qCDebug(lcQpaFonts) << "Contents size category changed to" << UIApplication.sharedApplication.preferredContentSizeCategory;
QPlatformFontDatabase::handleAvailableFontsChanged();
});
}
QIOSTheme::~QIOSTheme()