From 3797ee7747988c721740871f3a601d885d91d881 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 15 Oct 2014 16:02:06 +0200 Subject: CoreText font database: Use dynamic type on iOS to resolve theme fonts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use Dynamic Type to resolve theme fonts, so that we get the correct font sizes and styling based on user preferences in Settings app. Change-Id: I2222199a5ba21badb2e3696993eee503e720c476 Reviewed-by: Tor Arne Vestbø --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 50 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) (limited to 'src/platformsupport') diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 52cb928615..fc289579ea 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -759,6 +759,50 @@ static CTFontUIFontType fontTypeFromTheme(QPlatformTheme::Font f) } } +static CTFontDescriptorRef fontDescriptorFromTheme(QPlatformTheme::Font f) +{ +#ifdef Q_OS_IOS + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_7_0) { + // Use Dynamic Type to resolve theme fonts if possible, to get + // correct font sizes and style based on user configuration. + NSString *textStyle = 0; + switch (f) { + case QPlatformTheme::TitleBarFont: + case QPlatformTheme::HeaderViewFont: + textStyle = UIFontTextStyleHeadline; + break; + case QPlatformTheme::MdiSubWindowTitleFont: + textStyle = UIFontTextStyleSubheadline; + break; + case QPlatformTheme::TipLabelFont: + case QPlatformTheme::SmallFont: + textStyle = UIFontTextStyleFootnote; + break; + case QPlatformTheme::MiniFont: + textStyle = UIFontTextStyleCaption2; + break; + case QPlatformTheme::FixedFont: + // Fall back to regular code path, as iOS doesn't provide + // an appropriate text style for this theme font. + break; + default: + textStyle = UIFontTextStyleBody; + break; + } + + if (textStyle) { + UIFontDescriptor *desc = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle]; + return static_cast(CFBridgingRetain(desc)); + } + } +#endif // Q_OS_IOS + + // OSX default case and iOS fallback case + CTFontUIFontType fontType = fontTypeFromTheme(f); + QCFType ctFont = CTFontCreateUIFontForLanguage(fontType, 0.0, NULL); + return CTFontCopyFontDescriptor(ctFont); +} + const QHash &QCoreTextFontDatabase::themeFonts() const { if (m_themeFonts.isEmpty()) { @@ -773,11 +817,7 @@ const QHash &QCoreTextFontDatabase::themeFonts() QFont *QCoreTextFontDatabase::themeFont(QPlatformTheme::Font f) const { - CTFontUIFontType fontType = fontTypeFromTheme(f); - - QCFType ctFont = CTFontCreateUIFontForLanguage(fontType, 0.0, NULL); - CTFontDescriptorRef fontDesc = CTFontCopyFontDescriptor(ctFont); - + CTFontDescriptorRef fontDesc = fontDescriptorFromTheme(f); FontDescription fd; getFontDescription(fontDesc, &fd); m_systemFontDescriptors.insert(fontDesc); -- cgit v1.2.3