From 3188615db63fcd8b975690144bb711544266f864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 24 Mar 2022 12:25:55 +0100 Subject: 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 --- src/plugins/platforms/ios/qiostheme.h | 3 +++ src/plugins/platforms/ios/qiostheme.mm | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/plugins/platforms/ios/qiostheme.h b/src/plugins/platforms/ios/qiostheme.h index 400637eca1..b457151b1c 100644 --- a/src/plugins/platforms/ios/qiostheme.h +++ b/src/plugins/platforms/ios/qiostheme.h @@ -44,6 +44,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QIOSTheme : public QPlatformTheme @@ -71,6 +73,7 @@ public: private: static QPalette s_systemPalette; + QMacNotificationObserver m_contentSizeCategoryObserver; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiostheme.mm b/src/plugins/platforms/ios/qiostheme.mm index 69416ec24a..588cf3f22d 100644 --- a/src/plugins/platforms/ios/qiostheme.mm +++ b/src/plugins/platforms/ios/qiostheme.mm @@ -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() -- cgit v1.2.3