iOS: Make default system font Helvetica

Without a platform theme implementatin we were relying on
QCoreTextFontDatabase::defaultFont() to return the system font.

This didn't work because it reported the system font that iOS reports,
'.Helvetica Neue UI', which is a private font that does not get added
to our font database. The result was that we picked the first font in
the list of known fonts -- in this case 'Academy Engraved LET'.

We now implement QIOSTheme::font(), which takes precedence over the
font database's default font, and hard-code the system font to
'Helvetica', since Qt does not yet have the concept of private
system fonts.

Change-Id: I901cf9c2b662ea2795212376b84b8391be2efbbe
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
This commit is contained in:
Tor Arne Vestbø 2012-12-13 15:20:30 +01:00
parent 72c1ada86f
commit 70b21ec3c1
2 changed files with 29 additions and 0 deletions

View File

@ -54,6 +54,8 @@ public:
QVariant themeHint(ThemeHint hint) const;
const QFont *font(Font type = SystemFont) const;
static const char *name;
};

View File

@ -44,6 +44,11 @@
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtGui/QFont>
#include <UIKit/UIFont.h>
#include <UIKit/UIInterface.h>
QT_BEGIN_NAMESPACE
const char *QIOSTheme::name = "ios";
@ -66,4 +71,26 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const
}
}
const QFont *QIOSTheme::font(Font type) const
{
static QHash<QPlatformTheme::Font, QFont *> fonts;
if (fonts.isEmpty()) {
// The real system font on iOS is '.Helvetica Neue UI', as returned by both [UIFont systemFontOfSize]
// and CTFontCreateUIFontForLanguage(kCTFontSystemFontType, ...), but this font is not included when
// populating the available fonts in QCoreTextFontDatabase::populateFontDatabase(), since the font
// is internal to iOS and not supposed to be used by applications. We could potentially add this
// font to the font-database, but it would then show up when enumerating user fonts from Qt
// applications since we don't have a flag in Qt to mark a font as a private system font.
// For now we hard-code the font to Helvetica, which should be very close to the actual
// system font.
QLatin1String systemFontFamilyName("Helvetica");
fonts.insert(QPlatformTheme::SystemFont, new QFont(systemFontFamilyName, [UIFont systemFontSize]));
fonts.insert(QPlatformTheme::SmallFont, new QFont(systemFontFamilyName, [UIFont smallSystemFontSize]));
fonts.insert(QPlatformTheme::LabelFont, new QFont(systemFontFamilyName, [UIFont labelFontSize]));
fonts.insert(QPlatformTheme::PushButtonFont, new QFont(systemFontFamilyName, [UIFont buttonFontSize]));
}
return fonts.value(type, 0);
}
QT_END_NAMESPACE