summaryrefslogtreecommitdiffstats
path: root/src/platformsupport/fontdatabases
diff options
context:
space:
mode:
Diffstat (limited to 'src/platformsupport/fontdatabases')
-rw-r--r--src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp69
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm185
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h11
3 files changed, 222 insertions, 43 deletions
diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
index 7b5f882982..13a4c13099 100644
--- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
+++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
@@ -516,7 +516,7 @@ QFontEngineMulti *QFontconfigDatabase::fontEngineMulti(QFontEngine *fontEngine,
}
namespace {
-QFontEngine::HintStyle defaultHintStyleFromMatch(QFont::HintingPreference hintingPreference, FcPattern *match)
+QFontEngine::HintStyle defaultHintStyleFromMatch(QFont::HintingPreference hintingPreference, FcPattern *match, bool useXftConf)
{
switch (hintingPreference) {
case QFont::PreferNoHinting:
@@ -529,8 +529,7 @@ QFontEngine::HintStyle defaultHintStyleFromMatch(QFont::HintingPreference hintin
break;
}
- const QPlatformServices *services = QGuiApplicationPrivate::platformIntegration()->services();
- if (services && (services->desktopEnvironment() == "GNOME" || services->desktopEnvironment() == "UNITY")) {
+ if (useXftConf) {
void *hintStyleResource =
QGuiApplication::platformNativeInterface()->nativeResourceForScreen("hintstyle",
QGuiApplication::primaryScreen());
@@ -558,8 +557,17 @@ QFontEngine::HintStyle defaultHintStyleFromMatch(QFont::HintingPreference hintin
return QFontEngine::HintFull;
}
-QFontEngine::SubpixelAntialiasingType subpixelTypeFromMatch(FcPattern *match)
+QFontEngine::SubpixelAntialiasingType subpixelTypeFromMatch(FcPattern *match, bool useXftConf)
{
+ if (useXftConf) {
+ void *subpixelTypeResource =
+ QGuiApplication::platformNativeInterface()->nativeResourceForScreen("subpixeltype",
+ QGuiApplication::primaryScreen());
+ int subpixelType = int(reinterpret_cast<qintptr>(subpixelTypeResource));
+ if (subpixelType > 0)
+ return QFontEngine::SubpixelAntialiasingType(subpixelType - 1);
+ }
+
int subpixel = FC_RGBA_UNKNOWN;
FcPatternGetInteger(match, FC_RGBA, 0, &subpixel);
@@ -596,8 +604,22 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, void *usrPtr)
fid.index = fontfile->indexValue;
bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);
+ bool forcedAntialiasSetting = !antialias;
engine = new QFontEngineFT(fontDef);
+ const QPlatformServices *services = QGuiApplicationPrivate::platformIntegration()->services();
+ bool useXftConf = (services && (services->desktopEnvironment() == "GNOME" || services->desktopEnvironment() == "UNITY"));
+ if (useXftConf) {
+ void *antialiasResource =
+ QGuiApplication::platformNativeInterface()->nativeResourceForScreen("antialiasingEnabled",
+ QGuiApplication::primaryScreen());
+ int antialiasingEnabled = int(reinterpret_cast<qintptr>(antialiasResource));
+ if (antialiasingEnabled > 0) {
+ antialias = antialiasingEnabled - 1;
+ forcedAntialiasSetting = true;
+ }
+ }
+
QFontEngine::GlyphFormat format;
// try and get the pattern
FcPattern *pattern = FcPatternCreate();
@@ -622,7 +644,7 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, void *usrPtr)
FcPattern *match = FcFontMatch(0, pattern, &result);
if (match) {
- engine->setDefaultHintStyle(defaultHintStyleFromMatch((QFont::HintingPreference)f.hintingPreference, match));
+ engine->setDefaultHintStyle(defaultHintStyleFromMatch((QFont::HintingPreference)f.hintingPreference, match, useXftConf));
FcBool fc_autohint;
if (FcPatternGetBool(match, FC_AUTOHINT,0, &fc_autohint) == FcResultMatch)
@@ -634,18 +656,16 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QFontDef &f, void *usrPtr)
engine->lcdFilterType = lcdFilter;
#endif
- if (antialias) {
- // If antialiasing is not fully disabled, fontconfig may still disable it on a font match basis.
+ if (!forcedAntialiasSetting) {
FcBool fc_antialias;
- if (FcPatternGetBool(match, FC_ANTIALIAS,0, &fc_antialias) != FcResultMatch)
- fc_antialias = true;
- antialias = fc_antialias;
+ if (FcPatternGetBool(match, FC_ANTIALIAS,0, &fc_antialias) == FcResultMatch)
+ antialias = fc_antialias;
}
if (antialias) {
QFontEngine::SubpixelAntialiasingType subpixelType = QFontEngine::Subpixel_None;
if (!(f.styleStrategy & QFont::NoSubpixelAntialias))
- subpixelType = subpixelTypeFromMatch(match);
+ subpixelType = subpixelTypeFromMatch(match, useXftConf);
engine->subpixelType = subpixelType;
format = (subpixelType == QFontEngine::Subpixel_None)
@@ -676,6 +696,20 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QByteArray &fontData, qreal p
QFontDef fontDef = engine->fontDef;
+ bool forcedAntialiasSetting = false;
+ const QPlatformServices *services = QGuiApplicationPrivate::platformIntegration()->services();
+ bool useXftConf = (services && (services->desktopEnvironment() == "GNOME" || services->desktopEnvironment() == "UNITY"));
+ if (useXftConf) {
+ void *antialiasResource =
+ QGuiApplication::platformNativeInterface()->nativeResourceForScreen("antialiasingEnabled",
+ QGuiApplication::primaryScreen());
+ int antialiasingEnabled = int(reinterpret_cast<qintptr>(antialiasResource));
+ if (antialiasingEnabled > 0) {
+ engine->antialias = antialiasingEnabled - 1;
+ forcedAntialiasSetting = true;
+ }
+ }
+
QFontEngine::GlyphFormat format;
// try and get the pattern
FcPattern *pattern = FcPatternCreate();
@@ -693,7 +727,7 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QByteArray &fontData, qreal p
FcPattern *match = FcFontMatch(0, pattern, &result);
if (match) {
- engine->setDefaultHintStyle(defaultHintStyleFromMatch(hintingPreference, match));
+ engine->setDefaultHintStyle(defaultHintStyleFromMatch(hintingPreference, match, useXftConf));
FcBool fc_autohint;
if (FcPatternGetBool(match, FC_AUTOHINT,0, &fc_autohint) == FcResultMatch)
@@ -705,13 +739,14 @@ QFontEngine *QFontconfigDatabase::fontEngine(const QByteArray &fontData, qreal p
engine->lcdFilterType = lcdFilter;
#endif
- FcBool fc_antialias;
- if (FcPatternGetBool(match, FC_ANTIALIAS,0, &fc_antialias) != FcResultMatch)
- fc_antialias = true;
- engine->antialias = fc_antialias;
+ if (!forcedAntialiasSetting) {
+ FcBool fc_antialias;
+ if (FcPatternGetBool(match, FC_ANTIALIAS,0, &fc_antialias) == FcResultMatch)
+ engine->antialias = fc_antialias;
+ }
if (engine->antialias) {
- QFontEngine::SubpixelAntialiasingType subpixelType = subpixelTypeFromMatch(match);
+ QFontEngine::SubpixelAntialiasingType subpixelType = subpixelTypeFromMatch(match, useXftConf);
engine->subpixelType = subpixelType;
format = subpixelType == QFontEngine::Subpixel_None
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
index 7ae72cc446..8e4c1c07a8 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
@@ -211,6 +211,13 @@ void QCoreTextFontDatabase::populateFontDatabase()
QPlatformFontDatabase::registerAliasToFontFamily(familyName, localizedFamilyName);
#endif
}
+
+ // Force creating the theme fonts to get the descriptors in m_systemFontDescriptors
+ if (m_themeFonts.isEmpty())
+ (void)themeFonts();
+
+ Q_FOREACH (CTFontDescriptorRef fontDesc, m_systemFontDescriptors)
+ populateFromDescriptor(fontDesc);
}
void QCoreTextFontDatabase::populateFamily(const QString &familyName)
@@ -231,67 +238,76 @@ void QCoreTextFontDatabase::populateFamily(const QString &familyName)
populateFromDescriptor(CTFontDescriptorRef(CFArrayGetValueAtIndex(matchingFonts, i)));
}
-void QCoreTextFontDatabase::populateFromDescriptor(CTFontDescriptorRef font)
+struct FontDescription {
+ QCFString familyName;
+ QCFString styleName;
+ QString foundryName;
+ QFont::Weight weight;
+ QFont::Style style;
+ QFont::Stretch stretch;
+ int pixelSize;
+ bool fixedPitch;
+ QSupportedWritingSystems writingSystems;
+};
+
+static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd)
{
- QString foundryName = QStringLiteral("CoreText");
- QCFString familyName = (CFStringRef) CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
- QCFString styleName = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontStyleNameAttribute);
QCFType<CFDictionaryRef> styles = (CFDictionaryRef) CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute);
- QFont::Weight weight = QFont::Normal;
- QFont::Style style = QFont::StyleNormal;
- QFont::Stretch stretch = QFont::Unstretched;
- bool fixedPitch = false;
+
+ fd->foundryName = QStringLiteral("CoreText");
+ fd->familyName = (CFStringRef) CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
+ fd->styleName = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontStyleNameAttribute);
+ fd->weight = QFont::Normal;
+ fd->style = QFont::StyleNormal;
+ fd->stretch = QFont::Unstretched;
+ fd->fixedPitch = false;
if (styles) {
if (CFNumberRef weightValue = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontWeightTrait)) {
- Q_ASSERT(CFNumberIsFloatType(weightValue));
double normalizedWeight;
if (CFNumberGetValue(weightValue, kCFNumberDoubleType, &normalizedWeight)) {
if (normalizedWeight >= 0.62)
- weight = QFont::Black;
+ fd->weight = QFont::Black;
else if (normalizedWeight >= 0.4)
- weight = QFont::Bold;
+ fd->weight = QFont::Bold;
else if (normalizedWeight >= 0.3)
- weight = QFont::DemiBold;
+ fd->weight = QFont::DemiBold;
else if (normalizedWeight == 0.0)
- weight = QFont::Normal;
+ fd->weight = QFont::Normal;
else if (normalizedWeight <= -0.4)
- weight = QFont::Light;
+ fd->weight = QFont::Light;
}
}
if (CFNumberRef italic = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontSlantTrait)) {
- Q_ASSERT(CFNumberIsFloatType(italic));
double d;
if (CFNumberGetValue(italic, kCFNumberDoubleType, &d)) {
if (d > 0.0)
- style = QFont::StyleItalic;
+ fd->style = QFont::StyleItalic;
}
}
if (CFNumberRef symbolic = (CFNumberRef) CFDictionaryGetValue(styles, kCTFontSymbolicTrait)) {
int d;
if (CFNumberGetValue(symbolic, kCFNumberSInt32Type, &d)) {
if (d & kCTFontMonoSpaceTrait)
- fixedPitch = true;
+ fd->fixedPitch = true;
if (d & kCTFontExpandedTrait)
- stretch = QFont::Expanded;
+ fd->stretch = QFont::Expanded;
else if (d & kCTFontCondensedTrait)
- stretch = QFont::Condensed;
+ fd->stretch = QFont::Condensed;
}
}
}
- int pixelSize = 0;
if (QCFType<CFNumberRef> size = (CFNumberRef) CTFontDescriptorCopyAttribute(font, kCTFontSizeAttribute)) {
if (CFNumberIsFloatType(size)) {
double d;
CFNumberGetValue(size, kCFNumberDoubleType, &d);
- pixelSize = d;
+ fd->pixelSize = d;
} else {
- CFNumberGetValue(size, kCFNumberIntType, &pixelSize);
+ CFNumberGetValue(size, kCFNumberIntType, &fd->pixelSize);
}
}
- QSupportedWritingSystems writingSystems;
if (QCFType<CFArrayRef> languages = (CFArrayRef) CTFontDescriptorCopyAttribute(font, kCTFontLanguagesAttribute)) {
CFIndex length = CFArrayGetCount(languages);
for (int i = 1; i < LanguageCount; ++i) {
@@ -299,14 +315,24 @@ void QCoreTextFontDatabase::populateFromDescriptor(CTFontDescriptorRef font)
continue;
QCFString lang = CFStringCreateWithCString(NULL, languageForWritingSystem[i], kCFStringEncodingASCII);
if (CFArrayContainsValue(languages, CFRangeMake(0, length), lang))
- writingSystems.setSupported(QFontDatabase::WritingSystem(i));
+ fd->writingSystems.setSupported(QFontDatabase::WritingSystem(i));
}
}
+}
+void QCoreTextFontDatabase::populateFromDescriptor(CTFontDescriptorRef font)
+{
+ FontDescription fd;
+ getFontDescription(font, &fd);
+ populateFromFontDescription(font, fd);
+}
+
+void QCoreTextFontDatabase::populateFromFontDescription(CTFontDescriptorRef font, const FontDescription &fd)
+{
CFRetain(font);
- QPlatformFontDatabase::registerFont(familyName, styleName, foundryName, weight, style, stretch,
+ QPlatformFontDatabase::registerFont(fd.familyName, fd.styleName, fd.foundryName, fd.weight, fd.style, fd.stretch,
true /* antialiased */, true /* scalable */,
- pixelSize, fixedPitch, writingSystems, (void *) font);
+ fd.pixelSize, fd.fixedPitch, fd.writingSystems, (void *) font);
}
void QCoreTextFontDatabase::releaseHandle(void *handle)
@@ -612,6 +638,113 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData
return families;
}
+bool QCoreTextFontDatabase::isPrivateFontFamily(const QString &family) const
+{
+ if (family.startsWith(QLatin1Char('.')))
+ return true;
+
+ return QPlatformFontDatabase::isPrivateFontFamily(family);
+}
+
+static CTFontUIFontType fontTypeFromTheme(QPlatformTheme::Font f)
+{
+ switch (f) {
+ case QPlatformTheme::SystemFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::MenuFont:
+ case QPlatformTheme::MenuBarFont:
+ case QPlatformTheme::MenuItemFont:
+ return kCTFontMenuItemFontType;
+
+ case QPlatformTheme::MessageBoxFont:
+ return kCTFontEmphasizedSystemFontType;
+
+ case QPlatformTheme::LabelFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::TipLabelFont:
+ return kCTFontToolTipFontType;
+
+ case QPlatformTheme::StatusBarFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::TitleBarFont:
+ return kCTFontWindowTitleFontType;
+
+ case QPlatformTheme::MdiSubWindowTitleFont:
+ case QPlatformTheme::DockWidgetTitleFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::PushButtonFont:
+ return kCTFontPushButtonFontType;
+
+ case QPlatformTheme::CheckBoxFont:
+ case QPlatformTheme::RadioButtonFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::ToolButtonFont:
+ return kCTFontSmallToolbarFontType;
+
+ case QPlatformTheme::ItemViewFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::ListViewFont:
+ return kCTFontViewsFontType;
+
+ case QPlatformTheme::HeaderViewFont:
+ return kCTFontSmallSystemFontType;
+
+ case QPlatformTheme::ListBoxFont:
+ return kCTFontViewsFontType;
+
+ case QPlatformTheme::ComboMenuItemFont:
+ return kCTFontSystemFontType;
+
+ case QPlatformTheme::ComboLineEditFont:
+ return kCTFontViewsFontType;
+
+ case QPlatformTheme::SmallFont:
+ return kCTFontSmallSystemFontType;
+
+ case QPlatformTheme::MiniFont:
+ return kCTFontMiniSystemFontType;
+
+ case QPlatformTheme::FixedFont:
+ return kCTFontUserFixedPitchFontType;
+
+ default:
+ return kCTFontSystemFontType;
+ }
+}
+
+const QHash<QPlatformTheme::Font, QFont *> &QCoreTextFontDatabase::themeFonts() const
+{
+ if (m_themeFonts.isEmpty()) {
+ for (long f = QPlatformTheme::SystemFont; f < QPlatformTheme::NFonts; f++) {
+ QPlatformTheme::Font ft = static_cast<QPlatformTheme::Font>(f);
+ m_themeFonts.insert(ft, themeFont(ft));
+ }
+ }
+
+ return m_themeFonts;
+}
+
+QFont *QCoreTextFontDatabase::themeFont(QPlatformTheme::Font f) const
+{
+ CTFontUIFontType fontType = fontTypeFromTheme(f);
+
+ QCFType<CTFontRef> ctFont = CTFontCreateUIFontForLanguage(fontType, 0.0, NULL);
+ CTFontDescriptorRef fontDesc = CTFontCopyFontDescriptor(ctFont);
+
+ FontDescription fd;
+ getFontDescription(fontDesc, &fd);
+ m_systemFontDescriptors.insert(fontDesc);
+
+ QFont *font = new QFont(fd.familyName, fd.pixelSize, fd.weight, fd.style == QFont::StyleItalic);
+ return font;
+}
+
QFont QCoreTextFontDatabase::defaultFont() const
{
if (defaultFontName.isEmpty()) {
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h
index c73f4a32ca..a3da27b28d 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h
@@ -47,6 +47,7 @@
#define HAVE_ATS QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_5, __IPHONE_NA)
#include <qpa/qplatformfontdatabase.h>
+#include <qpa/qplatformtheme.h>
#include <private/qcore_mac_p.h>
#ifndef Q_OS_IOS
@@ -66,6 +67,8 @@ Q_DECLARE_METATYPE(ATSFontContainerRef);
QT_BEGIN_NAMESPACE
+struct FontDescription;
+
class QCoreTextFontDatabase : public QPlatformFontDatabase
{
public:
@@ -79,17 +82,25 @@ public:
QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const;
QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName);
void releaseHandle(void *handle);
+ bool isPrivateFontFamily(const QString &family) const;
QFont defaultFont() const;
QList<int> standardSizes() const;
+ // For iOS and OS X platform themes
+ QFont *themeFont(QPlatformTheme::Font) const;
+ const QHash<QPlatformTheme::Font, QFont *> &themeFonts() const;
+
private:
void populateFromDescriptor(CTFontDescriptorRef font);
+ void populateFromFontDescription(CTFontDescriptorRef font, const FontDescription &fd);
mutable QString defaultFontName;
void removeApplicationFonts();
QVector<QVariant> m_applicationFonts;
+ mutable QSet<CTFontDescriptorRef> m_systemFontDescriptors;
+ mutable QHash<QPlatformTheme::Font, QFont *> m_themeFonts;
};
QT_END_NAMESPACE