From 261041eaf997fa1aede5707596434e7077ad01a1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 4 May 2014 18:28:42 +0530 Subject: [PATCH] The headless plugin can now locate all system fonts via fontconfig --- setup/build_environment.py | 3 +- setup/extensions.py | 9 ++--- .../headless/headless_backingstore.cpp | 2 +- src/calibre/headless/headless_integration.cpp | 33 +++---------------- src/calibre/headless/headless_integration.h | 10 ++---- src/calibre/test_build.py | 4 ++- 6 files changed, 18 insertions(+), 43 deletions(-) diff --git a/setup/build_environment.py b/setup/build_environment.py index ccb87362c0..ade6733021 100644 --- a/setup/build_environment.py +++ b/setup/build_environment.py @@ -106,7 +106,8 @@ def get_sip_dir(q): pyqt['pyqt_sip_dir'] = get_sip_dir(c.default_sip_dir) pyqt['sip_inc_dir'] = c.sip_inc_dir -glib_flags = subprocess.check_output([PKGCONFIG, '--libs', 'glib-2.0']) if islinux else '' +glib_flags = subprocess.check_output([PKGCONFIG, '--libs', 'glib-2.0']).strip() if islinux else '' +fontconfig_flags = subprocess.check_output([PKGCONFIG, '--libs', 'fontconfig']).strip() if islinux else '' qt_inc = pyqt['inc'] qt_lib = pyqt['lib'] ft_lib_dirs = [] diff --git a/setup/extensions.py b/setup/extensions.py index 6b45612210..3a42cba9f6 100644 --- a/setup/extensions.py +++ b/setup/extensions.py @@ -16,7 +16,7 @@ from setup.build_environment import (chmlib_inc_dirs, msvc, MT, win_inc, win_lib, win_ddk, magick_inc_dirs, magick_lib_dirs, magick_libs, chmlib_lib_dirs, sqlite_inc_dirs, icu_inc_dirs, icu_lib_dirs, win_ddk_lib_dirs, ft_libs, ft_lib_dirs, ft_inc_dirs, - zlib_libs, zlib_lib_dirs, zlib_inc_dirs, is64bit, glib_flags) + zlib_libs, zlib_lib_dirs, zlib_inc_dirs, is64bit, glib_flags, fontconfig_flags) MT isunix = islinux or isosx or isbsd @@ -515,7 +515,7 @@ class Build(Command): if not self.newer(target, headers + sources + others): return # Arch monkey patches qmake as a result of which it fails to add - # glib-2.0 to the list of library dependencies. Compiling QPA + # glib-2.0 and freetype2 to the list of library dependencies. Compiling QPA # plugins uses the static libQt5PlatformSupport.a which needs glib # to be specified after it for linking to succeed, so we add it to # QMAKE_LIBS_PRIVATE (we cannot use LIBS as that would put -lglib-2.0 @@ -533,9 +533,10 @@ class Build(Command): OTHER_FILES = {others} DESTDIR = {destdir} CONFIG -= create_cmake # Prevent qmake from generating a cmake build file which it puts in the calibre src directory - QMAKE_LIBS_PRIVATE += {glib} + QMAKE_LIBS_PRIVATE += {glib} {fontconfig} ''').format( - headers=' '.join(headers), sources=' '.join(sources), others=' '.join(others), destdir=self.d(target), glib=glib_flags) + headers=' '.join(headers), sources=' '.join(sources), others=' '.join(others), destdir=self.d( + target), glib=glib_flags, fontconfig=fontconfig_flags) bdir = self.j(self.d(self.SRC), 'build', 'headless') if not os.path.exists(bdir): os.makedirs(bdir) diff --git a/src/calibre/headless/headless_backingstore.cpp b/src/calibre/headless/headless_backingstore.cpp index d07e5681e3..f5962620c3 100644 --- a/src/calibre/headless/headless_backingstore.cpp +++ b/src/calibre/headless/headless_backingstore.cpp @@ -9,7 +9,7 @@ QT_BEGIN_NAMESPACE HeadlessBackingStore::HeadlessBackingStore(QWindow *window) : QPlatformBackingStore(window) - , mDebug(HeadlessIntegration::instance()->options() & HeadlessIntegration::DebugBackingStore) + , mDebug(0) { if (mDebug) qDebug() << "HeadlessBackingStore::HeadlessBackingStore:" << (quintptr)this; diff --git a/src/calibre/headless/headless_integration.cpp b/src/calibre/headless/headless_integration.cpp index 3fbed96d83..be63dfaa02 100644 --- a/src/calibre/headless/headless_integration.cpp +++ b/src/calibre/headless/headless_integration.cpp @@ -10,30 +10,13 @@ #include #include #include +#include QT_BEGIN_NAMESPACE -static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE"; - -static inline unsigned parseOptions(const QStringList ¶mList) -{ - unsigned options = 0; - foreach (const QString ¶m, paramList) { - if (param == QLatin1String("enable_fonts")) - options |= HeadlessIntegration::EnableFonts; - } - return options; -} - HeadlessIntegration::HeadlessIntegration(const QStringList ¶meters) - : m_dummyFontDatabase(0) - , m_options(parseOptions(parameters)) { - if (qEnvironmentVariableIsSet(debugBackingStoreEnvironmentVariable) - && qgetenv(debugBackingStoreEnvironmentVariable).toInt() > 0) { - m_options |= DebugBackingStore | EnableFonts; - } - + Q_UNUSED(parameters); HeadlessScreen *mPrimaryScreen = new HeadlessScreen(); mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320); @@ -41,11 +24,11 @@ HeadlessIntegration::HeadlessIntegration(const QStringList ¶meters) mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; screenAdded(mPrimaryScreen); + m_fontDatabase.reset(new QFontconfigDatabase()); } HeadlessIntegration::~HeadlessIntegration() { - delete m_dummyFontDatabase; } bool HeadlessIntegration::hasCapability(QPlatformIntegration::Capability cap) const @@ -68,11 +51,7 @@ public: QPlatformFontDatabase *HeadlessIntegration::fontDatabase() const { - if (m_options & EnableFonts) - return QPlatformIntegration::fontDatabase(); - if (!m_dummyFontDatabase) - m_dummyFontDatabase = new DummyFontDatabase; - return m_dummyFontDatabase; + return m_fontDatabase.data(); } QPlatformWindow *HeadlessIntegration::createPlatformWindow(QWindow *window) const @@ -90,11 +69,7 @@ QPlatformBackingStore *HeadlessIntegration::createPlatformBackingStore(QWindow * QAbstractEventDispatcher *HeadlessIntegration::createEventDispatcher() const { -#ifdef Q_OS_WIN - return new QEventDispatcherWin32; -#else return createUnixEventDispatcher(); -#endif } HeadlessIntegration *HeadlessIntegration::instance() diff --git a/src/calibre/headless/headless_integration.h b/src/calibre/headless/headless_integration.h index e504d41a5f..b07141e6c8 100644 --- a/src/calibre/headless/headless_integration.h +++ b/src/calibre/headless/headless_integration.h @@ -2,6 +2,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -25,10 +26,6 @@ public: class HeadlessIntegration : public QPlatformIntegration { public: - enum Options { // Options to be passed on command line or determined from environment - DebugBackingStore = 0x1, - EnableFonts = 0x2 - }; explicit HeadlessIntegration(const QStringList ¶meters); ~HeadlessIntegration(); @@ -40,13 +37,12 @@ public: QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QAbstractEventDispatcher *createEventDispatcher() const; - unsigned options() const { return m_options; } + unsigned options() const { return 0; } static HeadlessIntegration *instance(); private: - mutable QPlatformFontDatabase *m_dummyFontDatabase; - unsigned m_options; + QScopedPointer m_fontDatabase; }; QT_END_NAMESPACE diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 04679703d1..4623ccbc20 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -77,10 +77,12 @@ def test_apsw(): def test_qt(): from calibre.gui2 import Application - from PyQt5.Qt import (QImageReader, QNetworkAccessManager) + from PyQt5.Qt import (QImageReader, QNetworkAccessManager, QFontDatabase) from PyQt5.QtWebKitWidgets import QWebView os.environ.pop('DISPLAY', None) app = Application([], headless=islinux) + if len(QFontDatabase().families()) < 5: + raise RuntimeError('The QPA headless plugin is not able to locate enough system fonts via fontconfig') fmts = set(map(unicode, QImageReader.supportedImageFormats())) testf = set(['jpg', 'png', 'mng', 'svg', 'ico', 'gif']) if testf.intersection(fmts) != testf: