summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/fontdatabases
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2014-10-15 16:02:06 +0200
committerRichard Moe Gustavsen <richard.gustavsen@digia.com>2014-10-19 00:56:04 +0200
commit3797ee7747988c721740871f3a601d885d91d881 (patch)
treeacef52bbaa948e78ed941b3b880c18bb5213bc35 /src/platformsupport/fontdatabases
parentfc567acefb9eddb4d52d7cbe6510364fa865f330 (diff)
CoreText font database: Use dynamic type on iOS to resolve theme fonts
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ø <tor.arne.vestbo@digia.com>
Diffstat (limited to 'src/platformsupport/fontdatabases')
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm50
1 files changed, 45 insertions, 5 deletions
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<CTFontDescriptorRef>(CFBridgingRetain(desc));
+ }
+ }
+#endif // Q_OS_IOS
+
+ // OSX default case and iOS fallback case
+ CTFontUIFontType fontType = fontTypeFromTheme(f);
+ QCFType<CTFontRef> ctFont = CTFontCreateUIFontForLanguage(fontType, 0.0, NULL);
+ return CTFontCopyFontDescriptor(ctFont);
+}
+
const QHash<QPlatformTheme::Font, QFont *> &QCoreTextFontDatabase::themeFonts() const
{
if (m_themeFonts.isEmpty()) {
@@ -773,11 +817,7 @@ const QHash<QPlatformTheme::Font, QFont *> &QCoreTextFontDatabase::themeFonts()
QFont *QCoreTextFontDatabase::themeFont(QPlatformTheme::Font f) const
{
- CTFontUIFontType fontType = fontTypeFromTheme(f);
-
- QCFType<CTFontRef> ctFont = CTFontCreateUIFontForLanguage(fontType, 0.0, NULL);
- CTFontDescriptorRef fontDesc = CTFontCopyFontDescriptor(ctFont);
-
+ CTFontDescriptorRef fontDesc = fontDescriptorFromTheme(f);
FontDescription fd;
getFontDescription(fontDesc, &fd);
m_systemFontDescriptors.insert(fontDesc);