minimal QPA: Make font DB creation more flexible

Prioritize CoreText over Fontconfig since the former is the
native one on macOS, and any other native font DB on its
respective platform. We introduce a new 'fontconfig' option
to allow using Fontconfig instead. This works similarly to
'freetype' overriding the default font engine on Windows. A
propos of which, 'freetype' now does the same on macOS.

Change-Id: Ic8168820d1d01fddc2f26e046abb65b8ab765f89
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
Gabriel de Dietrich 2017-11-29 12:12:05 -08:00
parent e6aae7df04
commit 8d5842a2d8
3 changed files with 31 additions and 8 deletions

View File

@ -14,6 +14,8 @@ HEADERS = qminimalintegration.h \
OTHER_FILES += minimal.json OTHER_FILES += minimal.json
qtConfig(freetype): QMAKE_USE_PRIVATE += freetype
PLUGIN_TYPE = platforms PLUGIN_TYPE = platforms
PLUGIN_CLASS_NAME = QMinimalIntegrationPlugin PLUGIN_CLASS_NAME = QMinimalIntegrationPlugin
!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - !equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = -

View File

@ -54,11 +54,17 @@
# endif # endif
#elif defined(Q_OS_DARWIN) #elif defined(Q_OS_DARWIN)
# include <QtFontDatabaseSupport/private/qcoretextfontdatabase_p.h> # include <QtFontDatabaseSupport/private/qcoretextfontdatabase_p.h>
#elif QT_CONFIG(fontconfig) #endif
#if QT_CONFIG(fontconfig)
# include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> # include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h>
# include <qpa/qplatformfontdatabase.h> # include <qpa/qplatformfontdatabase.h>
#endif #endif
#if QT_CONFIG(freetype)
#include <QtFontDatabaseSupport/private/qfontengine_ft_p.h>
#endif
#if !defined(Q_OS_WIN) #if !defined(Q_OS_WIN)
#include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h>
#elif defined(Q_OS_WINRT) #elif defined(Q_OS_WINRT)
@ -81,6 +87,8 @@ static inline unsigned parseOptions(const QStringList &paramList)
options |= QMinimalIntegration::EnableFonts; options |= QMinimalIntegration::EnableFonts;
else if (param == QLatin1String("freetype")) else if (param == QLatin1String("freetype"))
options |= QMinimalIntegration::FreeTypeFontDatabase; options |= QMinimalIntegration::FreeTypeFontDatabase;
else if (param == QLatin1String("fontconfig"))
options |= QMinimalIntegration::FontconfigDatabase;
} }
return options; return options;
} }
@ -129,9 +137,7 @@ public:
QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const
{ {
if (!m_fontDatabase && (m_options & EnableFonts)) { if (!m_fontDatabase && (m_options & EnableFonts)) {
#if QT_CONFIG(fontconfig) #if defined(Q_OS_WINRT)
m_fontDatabase = new QGenericUnixFontDatabase;
#elif defined(Q_OS_WINRT)
m_fontDatabase = new QWinRTFontDatabase; m_fontDatabase = new QWinRTFontDatabase;
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
if (m_options & FreeTypeFontDatabase) { if (m_options & FreeTypeFontDatabase) {
@ -142,11 +148,25 @@ QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const
m_fontDatabase = new QWindowsFontDatabase; m_fontDatabase = new QWindowsFontDatabase;
} }
#elif defined(Q_OS_DARWIN) #elif defined(Q_OS_DARWIN)
if (!(m_options & FontconfigDatabase)) {
if (m_options & FreeTypeFontDatabase) {
# if QT_CONFIG(freetype)
m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QFontEngineFT>;
# endif // freetype
} else {
m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>; m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>;
}
}
#endif
if (!m_fontDatabase) {
#if QT_CONFIG(fontconfig)
m_fontDatabase = new QGenericUnixFontDatabase;
#else #else
m_fontDatabase = QPlatformIntegration::fontDatabase(); m_fontDatabase = QPlatformIntegration::fontDatabase();
#endif #endif
} }
}
if (!m_fontDatabase) if (!m_fontDatabase)
m_fontDatabase = new DummyFontDatabase; m_fontDatabase = new DummyFontDatabase;
return m_fontDatabase; return m_fontDatabase;

View File

@ -68,7 +68,8 @@ public:
enum Options { // Options to be passed on command line or determined from environment enum Options { // Options to be passed on command line or determined from environment
DebugBackingStore = 0x1, DebugBackingStore = 0x1,
EnableFonts = 0x2, EnableFonts = 0x2,
FreeTypeFontDatabase = 0x4 FreeTypeFontDatabase = 0x4,
FontconfigDatabase = 0x8
}; };
explicit QMinimalIntegration(const QStringList &parameters); explicit QMinimalIntegration(const QStringList &parameters);