From f4fff02cbb1f9399f407c15a27741c6cd1a17133 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 10 Oct 2016 16:09:32 +0200 Subject: QXcbShmImage: don't use shmget()'s return unless it succeeds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When shmget() failed, we didn't set m_shm_info.shmid (not even to the -1 failure id) but did pass it (i.e. uninitialized noise) to shmat(), among other related functions. Guard against this; handle failure gracefully. Task-number: QTBUG-56419 Change-Id: Ie823c36c2ede03af6cb5d94ce7b4b5cd543c1008 Reviewed-by: Timur Pocheptsov Reviewed-by: Błażej Szczygieł Reviewed-by: Shawn Rutledge Reviewed-by: Joni Poikelin Reviewed-by: Laszlo Agocs --- src/plugins/platforms/xcb/qxcbbackingstore.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 3b04c59e28..0b76830d8e 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -150,12 +150,13 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QI return; int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0600); - if (id == -1) + if (id == -1) { qWarning("QXcbShmImage: shmget() failed (%d: %s) for size %d (%dx%d)", errno, strerror(errno), segmentSize, size.width(), size.height()); - else - m_shm_info.shmid = id; - m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0); + } else { + m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat(id, 0, 0); + } + m_shm_info.shmid = id; m_shm_info.shmseg = xcb_generate_id(xcb_connection()); const xcb_query_extension_reply_t *shm_reply = xcb_get_extension_data(xcb_connection(), &xcb_shm_id); @@ -166,9 +167,10 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QI if (!shm_present || error || id == -1) { free(error); - shmdt(m_shm_info.shmaddr); - shmctl(m_shm_info.shmid, IPC_RMID, 0); - + if (id != -1) { + shmdt(m_shm_info.shmaddr); + shmctl(m_shm_info.shmid, IPC_RMID, 0); + } m_shm_info.shmaddr = 0; m_xcb_image->data = (uint8_t *)malloc(segmentSize); -- cgit v1.2.3 From dde86ebb9b020811a731a180c4f4d98f3b60728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Thu, 6 Oct 2016 18:34:10 +0200 Subject: Android: Don't update offscreen windows Offscreen windows should not be handle by the platform plugin. Task-number: QTBUG-50973 Change-Id: I719a24b9bbcaad460d78fdc4095e86d615357cd2 Reviewed-by: Laszlo Agocs --- src/plugins/platforms/android/androidjnimain.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index fe2401f561..69c590940f 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -621,7 +621,12 @@ static void updateWindow(JNIEnv */*env*/, jobject /*thiz*/) if (QGuiApplication::instance() != nullptr) { foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QRect availableGeometry = w->screen()->availableGeometry(); + + // Skip non-platform windows, e.g., offscreen windows. + if (!w->handle()) + continue; + + QRect availableGeometry = w->screen()->availableGeometry(); if (w->geometry().width() > 0 && w->geometry().height() > 0 && availableGeometry.width() > 0 && availableGeometry.height() > 0) QWindowSystemInterface::handleExposeEvent(w, QRegion(QRect(QPoint(), w->geometry().size()))); } -- cgit v1.2.3 From 815341dbec1fd4f04fe76fc438cc9b3308ffafe9 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 11 Oct 2016 16:42:11 +0200 Subject: eglfs: Fix deformed mouse cursor image In 5.8 cr got changed to QRect from QRectF. This is incorrect without adjusting the calculations based on it since QRect and QRectF's right() and bottom() differs by 1. Switch back to QRectF. Task-number: QTBUG-56478 Change-Id: I5bde4ee59ca9bbf62f65493c66f42707032bfc80 Reviewed-by: Andy Nichols --- src/plugins/platforms/eglfs/api/qeglfscursor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/eglfs/api/qeglfscursor.cpp b/src/plugins/platforms/eglfs/api/qeglfscursor.cpp index 1b3446c4ac..2b54251a06 100644 --- a/src/plugins/platforms/eglfs/api/qeglfscursor.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfscursor.cpp @@ -341,14 +341,16 @@ void QEglFSCursor::paintOnScreen() if (!m_visible) return; - QRect cr = cursorRect(); // hotspot included + // cr must be a QRectF, otherwise cr.right() and bottom() would be off by + // one in the calculations below. + QRectF cr = cursorRect(); // hotspot included // Support virtual desktop too. Backends with multi-screen support (e.g. all // variants of KMS/DRM) will enable this by default. In this case all // screens are siblings of each other. When not enabled, the sibling list // only contains m_screen itself. for (QPlatformScreen *screen : m_screen->virtualSiblings()) { - if (screen->geometry().contains(cr.topLeft() + m_cursor.hotSpot) + if (screen->geometry().contains(cr.topLeft().toPoint() + m_cursor.hotSpot) && QOpenGLContext::currentContext()->screen() == screen->screen()) { cr.translate(-screen->geometry().topLeft()); -- cgit v1.2.3 From d8c72f41548a01bf39f82e77da01a2be57a06d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 11 Oct 2016 16:43:42 +0200 Subject: iOS: Take advantage of new synchronous API for QPA event delivery By using the SynchronousDelivery specialization instead of flushing all window system events, we remove the risk of flushing an event that was added without our knowledge. For example, QGuiApplicationPrivate::processMouseEvent() used to prepend a mouse move event to the QPA queue, which is why we had a check for QWidgetWindow when flushing geometry changes. processMouseEvent no longer sends the move event via the QPA queue, so that's no longer an issue, but if it were to be reintroduced, we wouldn't need to check for QWidgetWindow, as we're not flushing all events anymore. Change-Id: Ib346ea9501cd88ddda6c2137981d3eb0922192a0 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Simon Hausmann Reviewed-by: Laszlo Agocs --- src/plugins/platforms/ios/quiview.mm | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index 5c493617b1..2a1444e9e5 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -164,8 +164,7 @@ requestedGeometry : qt_window_private(m_qioswindow->window())->geometry; QWindow *window = m_qioswindow->window(); - QWindowSystemInterface::handleGeometryChange(window, actualGeometry, previousGeometry); - QWindowSystemInterface::flushWindowSystemEvents(window->inherits("QWidgetWindow") ? QEventLoop::ExcludeUserInputEvents : QEventLoop::AllEvents); + QWindowSystemInterface::handleGeometryChange(window, actualGeometry, previousGeometry); if (actualGeometry.size() != previousGeometry.size()) { // Trigger expose event on resize @@ -197,8 +196,7 @@ region = QRect(QPoint(), bounds); } - QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), region); - QWindowSystemInterface::flushWindowSystemEvents(); + QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), region); } // ------------------------------------------------------------------------- @@ -223,13 +221,10 @@ qImDebug() << m_qioswindow->window() << "became first responder"; - if (qGuiApp->focusWindow() != m_qioswindow->window()) { - QWindowSystemInterface::handleWindowActivated(m_qioswindow->window()); - QWindowSystemInterface::flushWindowSystemEvents(); - } else { - qImDebug() << m_qioswindow->window() - << "already active, not sending window activation"; - } + if (qGuiApp->focusWindow() != m_qioswindow->window()) + QWindowSystemInterface::handleWindowActivated(m_qioswindow->window()); + else + qImDebug() << m_qioswindow->window() << "already active, not sending window activation"; return YES; } @@ -264,10 +259,8 @@ qImDebug() << m_qioswindow->window() << "resigned first responder"; UIResponder *newResponder = FirstResponderCandidate::currentCandidate(); - if ([self responderShouldTriggerWindowDeactivation:newResponder]) { - QWindowSystemInterface::handleWindowActivated(0); - QWindowSystemInterface::flushWindowSystemEvents(); - } + if ([self responderShouldTriggerWindowDeactivation:newResponder]) + QWindowSystemInterface::handleWindowActivated(0); return YES; } @@ -357,10 +350,8 @@ - (void)sendTouchEventWithTimestamp:(ulong)timeStamp { - // Send touch event synchronously QIOSIntegration *iosIntegration = QIOSIntegration::instance(); - QWindowSystemInterface::handleTouchEvent(m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); - QWindowSystemInterface::flushWindowSystemEvents(); + QWindowSystemInterface::handleTouchEvent(m_qioswindow->window(), timeStamp, iosIntegration->touchDevice(), m_activeTouches.values()); } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event @@ -438,10 +429,8 @@ NSTimeInterval timestamp = event ? event.timestamp : [[NSProcessInfo processInfo] systemUptime]; - // Send cancel touch event synchronously QIOSIntegration *iosIntegration = static_cast(QGuiApplicationPrivate::platformIntegration()); - QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); - QWindowSystemInterface::flushWindowSystemEvents(); + QWindowSystemInterface::handleTouchCancelEvent(m_qioswindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); } - (int)mapPressTypeToKey:(UIPress*)press @@ -464,14 +453,12 @@ // When handling the event (for example, as a back button), both press and // release events must be handled accordingly. - QScopedValueRollback syncRollback(QWindowSystemInterfacePrivate::synchronousWindowSystemEvents, true); - bool handled = false; for (UIPress* press in presses) { int key = [self mapPressTypeToKey:press]; if (key == Qt::Key_unknown) continue; - if (QWindowSystemInterface::handleKeyEvent(m_qioswindow->window(), type, key, Qt::NoModifier)) + if (QWindowSystemInterface::handleKeyEvent(m_qioswindow->window(), type, key, Qt::NoModifier)) handled = true; } -- cgit v1.2.3 From 9ebfacb6883a5ed0095b1c816f3441eab8b675aa Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 4 Oct 2016 16:58:47 +0200 Subject: Android: Re-enable asset extraction for styling When the new configure system was introduced, it accidentally disabled automatic extraction of style assets on Android. This patch puts it back in. Note that the style extraction is not specific to Qt Widgets, but rather Qt Gui, like other QPA options. Task-number: QTBUG-56328 Change-Id: Ica33c3562c6dd6483050075f5c8ed5d28cd621a4 Reviewed-by: Lars Knoll Reviewed-by: Oswald Buddenhagen --- src/plugins/platforms/android/android.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 045e55ec65..544b2ca63a 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -72,7 +72,7 @@ HEADERS += $$PWD/qandroidplatformintegration.h \ $$PWD/qandroidplatformforeignwindow.h \ $$PWD/qandroideventdispatcher.h -android-style-assets: SOURCES += $$PWD/extract.cpp +qtConfig(android-style-assets): SOURCES += $$PWD/extract.cpp else: SOURCES += $$PWD/extract-dummy.cpp PLUGIN_TYPE = platforms -- cgit v1.2.3 From 2b9fe7d42d3e143edf8879c7af7725713611b0d3 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 4 Oct 2016 10:32:20 +0200 Subject: eglfs: clean up includes in the shared kms code Avoid unnecessary EGL and eglfs-specific includes in order to have a clearer view of the dependencies. Change-Id: Ifbd7dc4bd64024cc1ee48cd9f2607d1b5cdda1a2 Reviewed-by: Andy Nichols --- .../deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp index 6c30e8f930..5368a6d031 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsintegration.cpp @@ -42,15 +42,12 @@ #include "qeglfskmsintegration.h" #include "qeglfskmsdevice.h" #include "qeglfskmsscreen.h" -#include "private/qeglfswindow_p.h" -#include "private/qeglfscursor_p.h" -#include #include #include #include +#include #include -#include #include #include -- cgit v1.2.3 From e9110b162cad1c07341fa3ed424484a58f9c642a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 14 Oct 2016 16:44:47 +0200 Subject: iOS: Report correct physical DPI for iPhone 7 Plus Task-number: QTBUG-56509 Change-Id: Ibae94262c2a4c917aeca00cb1a1c28e5ae60f0c4 Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/qiosscreen.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 4018a02f8d..7d1c01f36b 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -201,8 +201,8 @@ QIOSScreen::QIOSScreen(UIScreen *screen) else m_depth = 24; - if (deviceIdentifier.contains(QRegularExpression("^iPhone(7,1|8,2)$"))) { - // iPhone 6 Plus or iPhone 6S Plus + if (deviceIdentifier.contains(QRegularExpression("^iPhone(7,1|8,2|9,2|9,4)$"))) { + // iPhone Plus models m_physicalDpi = 401; } else if (deviceIdentifier.contains(QRegularExpression("^iPad(1,1|2,[1-4]|3,[1-6]|4,[1-3]|5,[3-4]|6,[7-8])$"))) { // All iPads except the iPad Mini series -- cgit v1.2.3 From 9a088e78690a3052f9c2d7e388e37957c2470ab1 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 30 Sep 2016 20:53:53 +0200 Subject: use helper libs via QMAKE_USE for that, qt_help_lib.prf gains the ability to write "external module pri" files that contain suitable information for QMAKE_USE. these files have a bunch of limitations: - they are not installed, because a) they are not relocatable and b) the helper libs' headers are not installed, either - it won't work with qmake -r, which is ok, as qt5 does not build with qmake -r anyway - deps are not transitive, neither at build nor at use time the freetype, harfbuzz-ng, pcre, and png helper libs have been adjusted accordingly, and their uses replaced with QMAKE_USE instances. this also allowed inlining the now trivial {harfbuzz,pcrc,png}_dependency.pri files. freetype_dependency.pri remains due to its funkiness. Change-Id: I16890eecb122e34ec49f3d3e68380d1ea71a198a Reviewed-by: Jake Petroules --- .../platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri | 5 +---- src/plugins/platforms/xcb/xcb-static/xcb-static.pro | 6 ++++-- src/plugins/platforms/xcb/xcb_qpa_lib.pro | 5 +---- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri index a3813ef993..a94815dfbd 100644 --- a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri +++ b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri @@ -22,10 +22,7 @@ CONFIG += qpa/genericunixfontdatabase !qtConfig(system-xcb) { DEFINES += XCB_USE_RENDER - XCB_DIR = $$clean_path($$PWD/../../../../3rdparty/xcb) - INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/include/xcb $$XCB_DIR/sysinclude - LIBS += -L$$MODULE_BASE_OUTDIR/lib -lxcb-static$$qtPlatformTargetSuffix() - QMAKE_USE += xcb + QMAKE_USE += xcb-static xcb } else { qtConfig(xkb): QMAKE_USE += xcb_xkb # to support custom cursors with depth > 1 diff --git a/src/plugins/platforms/xcb/xcb-static/xcb-static.pro b/src/plugins/platforms/xcb/xcb-static/xcb-static.pro index a1dec2b0b5..f3e54813ee 100644 --- a/src/plugins/platforms/xcb/xcb-static/xcb-static.pro +++ b/src/plugins/platforms/xcb/xcb-static/xcb-static.pro @@ -5,11 +5,11 @@ # libxcb-xinerama # CONFIG += static -load(qt_helper_lib) XCB_DIR = ../../../../3rdparty/xcb -INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/include/xcb $$XCB_DIR/sysinclude +MODULE_INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/sysinclude +INCLUDEPATH += $$XCB_DIR/include/xcb QMAKE_USE += xcb/nolink @@ -75,3 +75,5 @@ SOURCES += \ OTHER_FILES = $$XCB_DIR/README TR_EXCLUDE += $$XCB_DIR/* + +load(qt_helper_lib) diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index 246bb1f118..69d2e35606 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -68,10 +68,7 @@ CONFIG += qpa/genericunixfontdatabase !qtConfig(system-xcb) { DEFINES += XCB_USE_RENDER - XCB_DIR = ../../../3rdparty/xcb - INCLUDEPATH += $$XCB_DIR/include $$XCB_DIR/sysinclude - LIBS += -L$$MODULE_BASE_OUTDIR/lib -lxcb-static$$qtPlatformTargetSuffix() - QMAKE_USE += xcb + QMAKE_USE += xcb-static xcb } else { LIBS += -lxcb-xinerama ### there is no configure test for this! qtConfig(xkb): QMAKE_USE += xcb_xkb -- cgit v1.2.3 From ec774500fb964f039bc47abce67e655699d374f7 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 12 Oct 2016 11:39:26 +0200 Subject: cleanup related to transitive dependencies public uses of external libraries are automatically transitive now, so we can remove some parts which were only meant to pull in transitive dependencies manually. this is particularly good for includes() of parts of QtPlatformSupport, which actually redundantly pulled in the library's sources. this required making the freetype and fontconfig dependencies public, which is ok, as in the end, they are used only by platform plugins, so there is no point in making them private, as plugins are not linked against anyway (except statically, but there public vs. private doesn't apply anyway). Change-Id: Ia2a32f50dc0f8472285675a0903e6ecd142a03b2 Reviewed-by: Jake Petroules --- src/plugins/platforms/haiku/haiku.pro | 2 -- src/plugins/platforms/qnx/qnx.pro | 5 ----- src/plugins/platforms/windows/windows.pri | 5 ----- src/plugins/platforms/winrt/winrt.pro | 1 - 4 files changed, 13 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/haiku/haiku.pro b/src/plugins/platforms/haiku/haiku.pro index ea5bb632db..931dfb28a8 100644 --- a/src/plugins/platforms/haiku/haiku.pro +++ b/src/plugins/platforms/haiku/haiku.pro @@ -36,8 +36,6 @@ LIBS += -lbe OTHER_FILES += haiku.json -include (../../../platformsupport/fontdatabases/fontdatabases.pri) - PLUGIN_TYPE = platforms PLUGIN_CLASS_NAME = QHaikuIntegrationPlugin load(qt_plugin) diff --git a/src/plugins/platforms/qnx/qnx.pro b/src/plugins/platforms/qnx/qnx.pro index e47731476f..a726980f5b 100644 --- a/src/plugins/platforms/qnx/qnx.pro +++ b/src/plugins/platforms/qnx/qnx.pro @@ -121,11 +121,6 @@ lgmon { OTHER_FILES += qnx.json -QMAKE_CXXFLAGS += -I./private - -include (../../../platformsupport/eglconvenience/eglconvenience.pri) -include (../../../platformsupport/fontdatabases/fontdatabases.pri) - PLUGIN_TYPE = platforms PLUGIN_CLASS_NAME = QQnxIntegrationPlugin !equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri index 6929f7365f..411c9e032b 100644 --- a/src/plugins/platforms/windows/windows.pri +++ b/src/plugins/platforms/windows/windows.pri @@ -114,11 +114,6 @@ RESOURCES += $$PWD/openglblacklists.qrc qtConfig(freetype) { HEADERS += $$PWD/qwindowsfontdatabase_ft.h SOURCES += $$PWD/qwindowsfontdatabase_ft.cpp - qtConfig(system-freetype) { - include($$QT_SOURCE_TREE/src/platformsupport/fontdatabases/basic/basic.pri) - } else { - include($$QT_SOURCE_TREE/src/3rdparty/freetype_dependency.pri) - } } qtConfig(accessibility): include($$PWD/accessible/accessible.pri) diff --git a/src/plugins/platforms/winrt/winrt.pro b/src/plugins/platforms/winrt/winrt.pro index 28456f66ec..174b0362b4 100644 --- a/src/plugins/platforms/winrt/winrt.pro +++ b/src/plugins/platforms/winrt/winrt.pro @@ -7,7 +7,6 @@ QT += core-private gui-private platformsupport-private DEFINES *= QT_NO_CAST_FROM_ASCII __WRL_NO_DEFAULT_LIB__ LIBS += $$QMAKE_LIBS_CORE -ldwrite -ld3d11 -INCLUDEPATH += $$QT_SOURCE_TREE/src/3rdparty/freetype/include SOURCES = \ main.cpp \ -- cgit v1.2.3 From 135fcd599200cdacf637b5c77824776c3fb181d1 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 30 Sep 2016 13:08:03 +0200 Subject: port to modularized platformsupport libraries Change-Id: I20eb0e33abfd70b6a5240e7b6b0aa0425f2d2ee7 Reviewed-by: Jake Petroules --- src/plugins/platforms/android/android.pro | 5 +++- .../platforms/android/androidjniaccessibility.cpp | 2 +- .../platforms/android/qandroideventdispatcher.h | 2 +- .../android/qandroidplatformfontdatabase.h | 2 +- .../android/qandroidplatformintegration.cpp | 2 +- .../android/qandroidplatformopenglcontext.cpp | 2 +- .../android/qandroidplatformopenglcontext.h | 2 +- .../android/qandroidplatformopenglwindow.cpp | 2 +- src/plugins/platforms/bsdfb/bsdfb.pro | 8 ++++++- src/plugins/platforms/bsdfb/qbsdfbintegration.cpp | 16 ++++++------- src/plugins/platforms/bsdfb/qbsdfbscreen.cpp | 4 ++-- src/plugins/platforms/bsdfb/qbsdfbscreen.h | 2 +- src/plugins/platforms/cocoa/cocoa.pro | 5 +++- .../platforms/cocoa/qcocoaaccessibilityelement.mm | 2 +- src/plugins/platforms/cocoa/qcocoabackingstore.h | 2 +- src/plugins/platforms/cocoa/qcocoaglcontext.mm | 2 +- src/plugins/platforms/cocoa/qcocoaintegration.h | 2 +- src/plugins/platforms/cocoa/qcocoamimetypes.mm | 2 +- src/plugins/platforms/cocoa/qcocoatheme.mm | 4 ++-- src/plugins/platforms/cocoa/qmacclipboard.h | 2 +- src/plugins/platforms/direct2d/direct2d.pro | 6 ++--- .../direct2d/qwindowsdirect2dintegration.cpp | 2 +- src/plugins/platforms/directfb/directfb.pro | 5 +++- src/plugins/platforms/directfb/qdirectfb_egl.cpp | 6 ++--- .../platforms/directfb/qdirectfbintegration.cpp | 6 ++--- src/plugins/platforms/eglfs/api/qeglfscontext.cpp | 4 ++-- src/plugins/platforms/eglfs/api/qeglfscontext_p.h | 2 +- .../eglfs/api/qeglfsdeviceintegration.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfsglobal_p.h | 2 +- .../platforms/eglfs/api/qeglfsintegration.cpp | 28 +++++++++++----------- .../platforms/eglfs/api/qeglfsoffscreenwindow.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfsscreen.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfswindow.cpp | 4 ++-- src/plugins/platforms/eglfs/api/qeglfswindow_p.h | 2 +- .../deviceintegration/eglfs_brcm/eglfs_brcm.pro | 2 +- .../deviceintegration/eglfs_kms/eglfs_kms.pro | 2 +- .../eglfs_kms/qeglfskmsgbmintegration.cpp | 2 +- .../eglfs_kms/qeglfskmsgbmscreen.cpp | 2 +- .../eglfs_kms_egldevice/eglfs_kms_egldevice.pro | 2 +- .../qeglfskmsegldeviceintegration.cpp | 2 +- .../qeglfskmsegldeviceintegration.h | 2 +- .../eglfs_kms_support/eglfs_kms_support.pro | 2 +- .../eglfs_kms_support/qeglfskmsscreen.cpp | 2 +- .../deviceintegration/eglfs_mali/eglfs_mali.pro | 2 +- .../deviceintegration/eglfs_viv/eglfs_viv.pro | 2 +- .../eglfs_viv_wl/eglfs_viv_wl.pro | 2 +- .../deviceintegration/eglfs_x11/eglfs_x11.pro | 2 +- src/plugins/platforms/eglfs/eglfs-plugin.pro | 2 +- .../platforms/eglfs/eglfsdeviceintegration.pro | 14 ++++++++++- src/plugins/platforms/haiku/haiku.pro | 2 +- src/plugins/platforms/haiku/qhaikuintegration.cpp | 2 +- src/plugins/platforms/integrity/integrity.pro | 5 +++- .../integrity/qintegrityfbintegration.cpp | 12 +++++----- .../platforms/integrity/qintegrityfbscreen.cpp | 4 ++-- .../platforms/integrity/qintegrityfbscreen.h | 2 +- src/plugins/platforms/ios/ios.pro | 5 +++- src/plugins/platforms/ios/qiosbackingstore.h | 2 +- src/plugins/platforms/ios/qiosclipboard.mm | 2 +- src/plugins/platforms/ios/qiosintegration.mm | 4 ++-- src/plugins/platforms/ios/qiostheme.mm | 2 +- src/plugins/platforms/linuxfb/linuxfb.pro | 8 ++++++- .../platforms/linuxfb/qlinuxfbintegration.cpp | 24 +++++++++---------- src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp | 4 ++-- src/plugins/platforms/linuxfb/qlinuxfbscreen.h | 2 +- src/plugins/platforms/minimal/minimal.pro | 4 +++- .../platforms/minimal/qminimalintegration.cpp | 6 ++--- src/plugins/platforms/minimalegl/minimalegl.pro | 4 +++- .../minimalegl/qminimaleglintegration.cpp | 8 +++---- .../platforms/minimalegl/qminimaleglscreen.cpp | 4 ++-- .../platforms/minimalegl/qminimaleglscreen.h | 2 +- src/plugins/platforms/mirclient/mirclient.pro | 5 +++- .../platforms/mirclient/qmirclientglcontext.cpp | 2 +- .../platforms/mirclient/qmirclientintegration.cpp | 4 ++-- .../mirclient/qmirclientplatformservices.h | 4 ++-- .../platforms/mirclient/qmirclientscreen.cpp | 2 +- src/plugins/platforms/mirclient/qmirclienttheme.h | 2 +- src/plugins/platforms/offscreen/offscreen.pro | 5 +++- .../platforms/offscreen/qoffscreenintegration.cpp | 6 ++--- .../offscreen/qoffscreenintegration_x11.cpp | 2 +- src/plugins/platforms/openwfd/openwf.pro | 4 +++- .../platforms/openwfd/qopenwfdintegration.cpp | 4 ++-- src/plugins/platforms/qnx/qnx.pro | 4 +++- src/plugins/platforms/vnc/qvncintegration.cpp | 14 +++++------ src/plugins/platforms/vnc/qvncscreen.cpp | 4 ++-- src/plugins/platforms/vnc/qvncscreen.h | 2 +- src/plugins/platforms/vnc/vnc.pro | 8 ++++++- .../platforms/windows/accessible/iaccessible2.cpp | 2 +- .../platforms/windows/qwindowsclipboard.cpp | 2 +- src/plugins/platforms/windows/qwindowscontext.cpp | 2 +- .../platforms/windows/qwindowsfontdatabase_ft.h | 2 +- .../platforms/windows/qwindowsintegration.cpp | 2 +- .../platforms/windows/qwindowskeymapper.cpp | 2 +- src/plugins/platforms/windows/qwindowstheme.cpp | 2 +- src/plugins/platforms/windows/windows.pro | 7 +++--- src/plugins/platforms/winrt/qwinrteglcontext.cpp | 4 ++-- src/plugins/platforms/winrt/qwinrtfontdatabase.h | 2 +- src/plugins/platforms/winrt/qwinrtintegration.cpp | 2 +- src/plugins/platforms/winrt/qwinrtwindow.cpp | 2 +- src/plugins/platforms/winrt/winrt.pro | 4 +++- .../gl_integrations_plugin_base.pri | 2 +- .../xcb/gl_integrations/xcb_egl/qxcbeglcontext.h | 4 ++-- .../xcb/gl_integrations/xcb_egl/qxcbeglinclude.h | 2 +- .../gl_integrations/xcb_egl/qxcbeglintegration.cpp | 2 +- .../xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp | 4 ++-- .../xcb/gl_integrations/xcb_egl/xcb_egl.pro | 1 + .../gl_integrations/xcb_glx/qglxintegration.cpp | 2 +- .../xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp | 2 +- .../xcb/gl_integrations/xcb_glx/xcb_glx.pro | 1 + src/plugins/platforms/xcb/qxcbintegration.cpp | 8 +++---- src/plugins/platforms/xcb/xcb-plugin.pro | 2 +- src/plugins/platforms/xcb/xcb_qpa_lib.pro | 8 ++++++- 111 files changed, 254 insertions(+), 184 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 544b2ca63a..5912edc847 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -6,7 +6,10 @@ DEFINES += QT_STATICPLUGIN LIBS += -ljnigraphics -landroid -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private accessibility_support-private \ + fontdatabase_support-private egl_support-private CONFIG += qpa/genericunixfontdatabase diff --git a/src/plugins/platforms/android/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp index e8536235d7..a987092862 100644 --- a/src/plugins/platforms/android/androidjniaccessibility.cpp +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp @@ -41,7 +41,7 @@ #include "androidjnimain.h" #include "qandroidplatformintegration.h" #include "qpa/qplatformaccessibility.h" -#include +#include #include "qguiapplication.h" #include "qwindow.h" #include "qrect.h" diff --git a/src/plugins/platforms/android/qandroideventdispatcher.h b/src/plugins/platforms/android/qandroideventdispatcher.h index 227027f3c3..86a7e460b3 100644 --- a/src/plugins/platforms/android/qandroideventdispatcher.h +++ b/src/plugins/platforms/android/qandroideventdispatcher.h @@ -42,7 +42,7 @@ #include #include -#include +#include class QAndroidEventDispatcher : public QUnixEventDispatcherQPA { diff --git a/src/plugins/platforms/android/qandroidplatformfontdatabase.h b/src/plugins/platforms/android/qandroidplatformfontdatabase.h index a00a3730fb..b20fd75cb2 100644 --- a/src/plugins/platforms/android/qandroidplatformfontdatabase.h +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.h @@ -40,7 +40,7 @@ #ifndef QANDROIDPLATFORMFONTDATABASE_H #define QANDROIDPLATFORMFONTDATABASE_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index e10bd95e12..6669ee3176 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 80693acf88..2644fa27f6 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -42,7 +42,7 @@ #include "qandroidplatformopenglwindow.h" #include "qandroidplatformintegration.h" -#include +#include #include #include diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.h b/src/plugins/platforms/android/qandroidplatformopenglcontext.h index c88dbf327b..d3f6cf13a4 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.h +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.h @@ -41,7 +41,7 @@ #ifndef QANDROIDPLATFORMOPENGLCONTEXT_H #define QANDROIDPLATFORMOPENGLCONTEXT_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp index 7801629633..3e1cfe305d 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/bsdfb/bsdfb.pro b/src/plugins/platforms/bsdfb/bsdfb.pro index c24d8dd9e5..294edcd35d 100644 --- a/src/plugins/platforms/bsdfb/bsdfb.pro +++ b/src/plugins/platforms/bsdfb/bsdfb.pro @@ -1,6 +1,12 @@ TARGET = qbsdfb -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + service_support-private eventdispatcher_support-private \ + fontdatabase_support-private fb_support-private + +qtHaveModule(input_support-private): \ + QT += input_support-private SOURCES = main.cpp qbsdfbintegration.cpp qbsdfbscreen.cpp HEADERS = qbsdfbintegration.h qbsdfbscreen.h diff --git a/src/plugins/platforms/bsdfb/qbsdfbintegration.cpp b/src/plugins/platforms/bsdfb/qbsdfbintegration.cpp index 9c25076c9c..1fa13183f8 100644 --- a/src/plugins/platforms/bsdfb/qbsdfbintegration.cpp +++ b/src/plugins/platforms/bsdfb/qbsdfbintegration.cpp @@ -35,21 +35,21 @@ #include "qbsdfbintegration.h" #include "qbsdfbscreen.h" -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #if QT_CONFIG(tslib) -#include +#include #endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/bsdfb/qbsdfbscreen.cpp b/src/plugins/platforms/bsdfb/qbsdfbscreen.cpp index ee2dce6867..0ef57d37e5 100644 --- a/src/plugins/platforms/bsdfb/qbsdfbscreen.cpp +++ b/src/plugins/platforms/bsdfb/qbsdfbscreen.cpp @@ -33,8 +33,8 @@ ****************************************************************************/ #include "qbsdfbscreen.h" -#include -#include +#include +#include #include #include diff --git a/src/plugins/platforms/bsdfb/qbsdfbscreen.h b/src/plugins/platforms/bsdfb/qbsdfbscreen.h index 0d9964afd5..3e244e3460 100644 --- a/src/plugins/platforms/bsdfb/qbsdfbscreen.h +++ b/src/plugins/platforms/bsdfb/qbsdfbscreen.h @@ -35,7 +35,7 @@ #ifndef QBSDFBSCREEN_H #define QBSDFBSCREEN_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index d9d3cb1627..0664841c2d 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -81,7 +81,10 @@ RESOURCES += qcocoaresources.qrc LIBS += -framework AppKit -framework Carbon -framework IOKit -lcups -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + accessibility_support-private clipboard_support-private theme_support-private \ + fontdatabase_support-private graphics_support-private cgl_support-private qtHaveModule(widgets) { OBJECTIVE_SOURCES += \ diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index 9c410506b0..97bd402b73 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -41,7 +41,7 @@ #include "qcocoahelpers.h" #include "qcocoawindow.h" #include "private/qaccessiblecache_p.h" -#include +#include #include #import diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h index 562be2be8f..5ed455fd71 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.h +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h @@ -40,7 +40,7 @@ #ifndef QBACKINGSTORE_COCOA_H #define QBACKINGSTORE_COCOA_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index 31b93be136..a7cc19b3bf 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -42,7 +42,7 @@ #include "qcocoahelpers.h" #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 85ea2d8ba9..32f6fe0af1 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -54,7 +54,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoamimetypes.mm b/src/plugins/platforms/cocoa/qcocoamimetypes.mm index c109eb7bf4..093f86da6e 100644 --- a/src/plugins/platforms/cocoa/qcocoamimetypes.mm +++ b/src/plugins/platforms/cocoa/qcocoamimetypes.mm @@ -38,7 +38,7 @@ ****************************************************************************/ #include "qcocoamimetypes.h" -#include +#include #include "qcocoahelpers.h" #include diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 03ad15a381..4d74c11581 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -58,8 +58,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/src/plugins/platforms/cocoa/qmacclipboard.h b/src/plugins/platforms/cocoa/qmacclipboard.h index 2ee0cb91e4..1d229a55d2 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.h +++ b/src/plugins/platforms/cocoa/qmacclipboard.h @@ -41,7 +41,7 @@ #define QMACCLIPBOARD_H #include -#include +#include #import diff --git a/src/plugins/platforms/direct2d/direct2d.pro b/src/plugins/platforms/direct2d/direct2d.pro index f4c3b5cc3b..83c4a730f4 100644 --- a/src/plugins/platforms/direct2d/direct2d.pro +++ b/src/plugins/platforms/direct2d/direct2d.pro @@ -1,8 +1,8 @@ TARGET = qdirect2d -QT *= core-private -QT *= gui-private -QT *= platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private LIBS += -ldwmapi -ld2d1 -ld3d11 -ldwrite -lVersion -lgdi32 diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp index deabe98fbe..1d24247d75 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/directfb/directfb.pro b/src/plugins/platforms/directfb/directfb.pro index de0344ff5c..da7634856c 100644 --- a/src/plugins/platforms/directfb/directfb.pro +++ b/src/plugins/platforms/directfb/directfb.pro @@ -1,6 +1,9 @@ TARGET = qdirectfb -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private service_support-private \ + fontdatabase_support-private egl_support-private QMAKE_USE += directfb diff --git a/src/plugins/platforms/directfb/qdirectfb_egl.cpp b/src/plugins/platforms/directfb/qdirectfb_egl.cpp index 2a04c0bba3..dad553c890 100644 --- a/src/plugins/platforms/directfb/qdirectfb_egl.cpp +++ b/src/plugins/platforms/directfb/qdirectfb_egl.cpp @@ -46,10 +46,10 @@ #include #include -#include -#include +#include +#include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.cpp b/src/plugins/platforms/directfb/qdirectfbintegration.cpp index 506432f886..cdf340da7a 100644 --- a/src/plugins/platforms/directfb/qdirectfbintegration.cpp +++ b/src/plugins/platforms/directfb/qdirectfbintegration.cpp @@ -44,9 +44,9 @@ #include "qdirectfbcursor.h" #include "qdirectfbwindow.h" -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/plugins/platforms/eglfs/api/qeglfscontext.cpp b/src/plugins/platforms/eglfs/api/qeglfscontext.cpp index 1a33215295..c5cef34d8e 100644 --- a/src/plugins/platforms/eglfs/api/qeglfscontext.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfscontext.cpp @@ -39,8 +39,8 @@ #include "qeglfsglobal_p.h" #include -#include -#include +#include +#include #include "qeglfscontext_p.h" #include "qeglfswindow_p.h" diff --git a/src/plugins/platforms/eglfs/api/qeglfscontext_p.h b/src/plugins/platforms/eglfs/api/qeglfscontext_p.h index 65af3a7cee..ab5bf99c3c 100644 --- a/src/plugins/platforms/eglfs/api/qeglfscontext_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfscontext_p.h @@ -52,7 +52,7 @@ // #include "qeglfsglobal_p.h" -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp index 9f05767366..48e0af5479 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp @@ -44,7 +44,7 @@ #include "qeglfsscreen_p.h" #include "qeglfshooks_p.h" -#include +#include #include #include #include diff --git a/src/plugins/platforms/eglfs/api/qeglfsglobal_p.h b/src/plugins/platforms/eglfs/api/qeglfsglobal_p.h index bad5095d21..8d76ff5ee0 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsglobal_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfsglobal_p.h @@ -53,7 +53,7 @@ #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp index 4974499e0a..733f0bd139 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include "qeglfsintegration_p.h" #include "qeglfswindow_p.h" @@ -58,30 +57,31 @@ #include "qeglfsoffscreenwindow_p.h" #include "qeglfscursor_p.h" -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #if QT_CONFIG(libinput) -#include +#include #endif #if QT_CONFIG(evdev) -#include -#include -#include +#include +#include +#include #endif #if QT_CONFIG(tslib) -#include +#include #endif #include diff --git a/src/plugins/platforms/eglfs/api/qeglfsoffscreenwindow.cpp b/src/plugins/platforms/eglfs/api/qeglfsoffscreenwindow.cpp index 7de5379ae3..864271cd3a 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsoffscreenwindow.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsoffscreenwindow.cpp @@ -40,7 +40,7 @@ #include "qeglfsoffscreenwindow_p.h" #include "qeglfshooks_p.h" #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp b/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp index b0c32e5176..5613179041 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsscreen.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include "qeglfsscreen_p.h" #include "qeglfswindow_p.h" diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow.cpp b/src/plugins/platforms/eglfs/api/qeglfswindow.cpp index 5ce88e6bd8..e79b377d40 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfswindow.cpp @@ -43,8 +43,8 @@ #include #include #include -#include -#include +#include +#include #include "qeglfswindow_p.h" #include "qeglfscursor_p.h" diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h index 6e752b8f79..0889f27ae3 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h @@ -56,7 +56,7 @@ #include "qeglfsscreen_p.h" #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro index 7f1e7b9f59..fee67da2de 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-brcm-integration -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private +QT += core-private gui-private eglfsdeviceintegration-private INCLUDEPATH += $$PWD/../../api CONFIG += egl diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro index 10571dc978..255db824b7 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro @@ -4,7 +4,7 @@ PLUGIN_TYPE = egldeviceintegrations PLUGIN_CLASS_NAME = QEglFSKmsGbmIntegrationPlugin load(qt_plugin) -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private eglfs_kms_support-private +QT += core-private gui-private eglfsdeviceintegration-private eglfs_kms_support-private INCLUDEPATH += $$PWD/../../api $$PWD/../eglfs_kms_support diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp index a5ab73cca4..a78f445995 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp @@ -45,7 +45,7 @@ #include "qeglfskmsgbmcursor.h" #include "private/qeglfscursor_p.h" -#include +#include #include #include #include diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp index 75ff3ac749..bed775ff81 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmscreen.cpp @@ -47,7 +47,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro index 582982df76..a625021aba 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-kms-egldevice-integration -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private eglfs_kms_support-private +QT += core-private gui-private eglfsdeviceintegration-private eglfs_kms_support-private INCLUDEPATH += $$PWD/../../api $$PWD/../eglfs_kms_support diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp index ddb2499751..d0c9c9565e 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ #include "qeglfskmsegldeviceintegration.h" -#include +#include #include "private/qeglfswindow_p.h" #include "private/qeglfscursor_p.h" #include "qeglfskmsegldevice.h" diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h index 375c388548..cddfdbd5c6 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldeviceintegration.h @@ -46,7 +46,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro index f88a7c847e..487edb569e 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro @@ -2,7 +2,7 @@ TARGET = QtEglFsKmsSupport CONFIG += no_module_headers internal_module load(qt_module) -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private +QT += core-private gui-private eglfsdeviceintegration-private INCLUDEPATH += $$PWD/../../api diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp index e4b6c67f28..4021609407 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/qeglfskmsscreen.cpp @@ -46,7 +46,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro index e72f5bdd14..5e6f636e2b 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-mali-integration -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private +QT += core-private gui-private eglfsdeviceintegration-private # Avoid X11 header collision, use generic EGL native types DEFINES += QT_EGL_NO_X11 diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro index 364812ec60..f9cce8d48b 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-viv-integration -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private +QT += core-private gui-private eglfsdeviceintegration-private INCLUDEPATH += $$PWD/../../api CONFIG += egl diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro index ccdf20b417..f934fd85ed 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-viv-wl-integration -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private +QT += core-private gui-private eglfsdeviceintegration-private INCLUDEPATH += $$PWD/../../api CONFIG += egl diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro index 51a026e2cf..391f63615b 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro @@ -1,6 +1,6 @@ TARGET = qeglfs-x11-integration -QT += core-private gui-private platformsupport-private eglfsdeviceintegration-private +QT += core-private gui-private eglfsdeviceintegration-private # Avoid X11 header collision, use generic EGL native types DEFINES += QT_EGL_NO_X11 diff --git a/src/plugins/platforms/eglfs/eglfs-plugin.pro b/src/plugins/platforms/eglfs/eglfs-plugin.pro index d8adc13226..cf4863975a 100644 --- a/src/plugins/platforms/eglfs/eglfs-plugin.pro +++ b/src/plugins/platforms/eglfs/eglfs-plugin.pro @@ -1,6 +1,6 @@ TARGET = qeglfs -QT += platformsupport-private eglfsdeviceintegration-private +QT += eglfsdeviceintegration-private SOURCES += $$PWD/qeglfsmain.cpp diff --git a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro index 15a825a7b0..638d12a368 100644 --- a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro +++ b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro @@ -8,7 +8,15 @@ TARGET = QtEglFSDeviceIntegration CONFIG += internal_module MODULE = eglfsdeviceintegration -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + devicediscovery_support-private eventdispatcher_support-private \ + service_support-private theme_support-private fontdatabase_support-private \ + fb_support-private egl_support-private platformcompositor_support-private + +qtHaveModule(input_support-private): \ + QT += input_support-private + LIBS += $$QMAKE_LIBS_DYNLOAD # Avoid X11 header collision, use generic EGL native types @@ -33,6 +41,10 @@ QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF CONFIG += egl qpa/genericunixfontdatabase +# Prevent gold linker from crashing. +# This started happening when QtPlatformSupport was modularized. +use_gold_linker: CONFIG += no_linker_version_script + !contains(DEFINES, QT_NO_CURSOR): RESOURCES += $$PWD/cursor.qrc load(qt_module) diff --git a/src/plugins/platforms/haiku/haiku.pro b/src/plugins/platforms/haiku/haiku.pro index 931dfb28a8..fd1f47b963 100644 --- a/src/plugins/platforms/haiku/haiku.pro +++ b/src/plugins/platforms/haiku/haiku.pro @@ -1,6 +1,6 @@ TARGET = qhaiku -QT += platformsupport-private core-private gui-private +QT += core-private gui-private eventdistpatcher_support-private SOURCES = \ main.cpp \ diff --git a/src/plugins/platforms/haiku/qhaikuintegration.cpp b/src/plugins/platforms/haiku/qhaikuintegration.cpp index d239380866..d46d77ff18 100644 --- a/src/plugins/platforms/haiku/qhaikuintegration.cpp +++ b/src/plugins/platforms/haiku/qhaikuintegration.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include diff --git a/src/plugins/platforms/integrity/integrity.pro b/src/plugins/platforms/integrity/integrity.pro index 07dbf4093d..178fc1b882 100644 --- a/src/plugins/platforms/integrity/integrity.pro +++ b/src/plugins/platforms/integrity/integrity.pro @@ -1,6 +1,9 @@ TARGET = integrityfb -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private service_support-private \ + fontdatabase_support-private fb_support-private SOURCES = \ main.cpp \ diff --git a/src/plugins/platforms/integrity/qintegrityfbintegration.cpp b/src/plugins/platforms/integrity/qintegrityfbintegration.cpp index 5332718c5e..a88c85e30d 100644 --- a/src/plugins/platforms/integrity/qintegrityfbintegration.cpp +++ b/src/plugins/platforms/integrity/qintegrityfbintegration.cpp @@ -35,13 +35,13 @@ #include "qintegrityfbscreen.h" #include "qintegrityhidmanager.h" -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/plugins/platforms/integrity/qintegrityfbscreen.cpp b/src/plugins/platforms/integrity/qintegrityfbscreen.cpp index e043da7786..256cc117a2 100644 --- a/src/plugins/platforms/integrity/qintegrityfbscreen.cpp +++ b/src/plugins/platforms/integrity/qintegrityfbscreen.cpp @@ -32,8 +32,8 @@ ****************************************************************************/ #include "qintegrityfbscreen.h" -#include -#include +#include +#include #include #include diff --git a/src/plugins/platforms/integrity/qintegrityfbscreen.h b/src/plugins/platforms/integrity/qintegrityfbscreen.h index 2a83f3426f..5b4d900a4b 100644 --- a/src/plugins/platforms/integrity/qintegrityfbscreen.h +++ b/src/plugins/platforms/integrity/qintegrityfbscreen.h @@ -34,7 +34,7 @@ #ifndef QINTEGRITYFBSCREEN_H #define QINTEGRITYFBSCREEN_H -#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/ios/ios.pro b/src/plugins/platforms/ios/ios.pro index 2c85a68f0b..56efd12435 100644 --- a/src/plugins/platforms/ios/ios.pro +++ b/src/plugins/platforms/ios/ios.pro @@ -1,6 +1,9 @@ TARGET = qios -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + clipboard_support-private fontdatabase_support-private graphics_support-private + LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AudioToolbox OBJECTIVE_SOURCES = \ diff --git a/src/plugins/platforms/ios/qiosbackingstore.h b/src/plugins/platforms/ios/qiosbackingstore.h index 5c37be5d38..1c072c0935 100644 --- a/src/plugins/platforms/ios/qiosbackingstore.h +++ b/src/plugins/platforms/ios/qiosbackingstore.h @@ -42,7 +42,7 @@ #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosclipboard.mm b/src/plugins/platforms/ios/qiosclipboard.mm index 960c9f39db..ef3b453bbf 100644 --- a/src/plugins/platforms/ios/qiosclipboard.mm +++ b/src/plugins/platforms/ios/qiosclipboard.mm @@ -41,7 +41,7 @@ #ifndef QT_NO_CLIPBOARD -#include +#include #include #include diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 94dd643116..82b5f3b755 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -57,8 +57,8 @@ #include #include -#include -#include +#include +#include #include #import diff --git a/src/plugins/platforms/ios/qiostheme.mm b/src/plugins/platforms/ios/qiostheme.mm index 83a8176478..91980d3f35 100644 --- a/src/plugins/platforms/ios/qiostheme.mm +++ b/src/plugins/platforms/ios/qiostheme.mm @@ -44,7 +44,7 @@ #include -#include +#include #include #include diff --git a/src/plugins/platforms/linuxfb/linuxfb.pro b/src/plugins/platforms/linuxfb/linuxfb.pro index db365ce739..a752f95917 100644 --- a/src/plugins/platforms/linuxfb/linuxfb.pro +++ b/src/plugins/platforms/linuxfb/linuxfb.pro @@ -2,7 +2,13 @@ TARGET = qlinuxfb DEFINES += QT_NO_FOREACH -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + service_support-private eventdispatcher_support-private \ + fontdatabase_support-private fb_support-private + +qtHaveModule(input_support-private): \ + QT += input_support-private SOURCES = main.cpp qlinuxfbintegration.cpp qlinuxfbscreen.cpp HEADERS = qlinuxfbintegration.h qlinuxfbscreen.h diff --git a/src/plugins/platforms/linuxfb/qlinuxfbintegration.cpp b/src/plugins/platforms/linuxfb/qlinuxfbintegration.cpp index 707301487d..893205177d 100644 --- a/src/plugins/platforms/linuxfb/qlinuxfbintegration.cpp +++ b/src/plugins/platforms/linuxfb/qlinuxfbintegration.cpp @@ -40,30 +40,30 @@ #include "qlinuxfbintegration.h" #include "qlinuxfbscreen.h" -#include -#include -#include +#include +#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #if QT_CONFIG(libinput) -#include +#include #endif #if QT_CONFIG(evdev) && !defined(Q_OS_ANDROID) -#include -#include -#include +#include +#include +#include #endif #if QT_CONFIG(tslib) && !defined(Q_OS_ANDROID) -#include +#include #endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp index a2e09611b4..246c959fd3 100644 --- a/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp @@ -38,8 +38,8 @@ ****************************************************************************/ #include "qlinuxfbscreen.h" -#include -#include +#include +#include #include #include #include diff --git a/src/plugins/platforms/linuxfb/qlinuxfbscreen.h b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h index ada9c4d830..1e98191569 100644 --- a/src/plugins/platforms/linuxfb/qlinuxfbscreen.h +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h @@ -40,7 +40,7 @@ #ifndef QLINUXFBSCREEN_H #define QLINUXFBSCREEN_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/minimal/minimal.pro b/src/plugins/platforms/minimal/minimal.pro index d4627605bb..0fffb24d24 100644 --- a/src/plugins/platforms/minimal/minimal.pro +++ b/src/plugins/platforms/minimal/minimal.pro @@ -1,6 +1,8 @@ TARGET = qminimal -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private fontdatabase_support-private DEFINES += QT_NO_FOREACH diff --git a/src/plugins/platforms/minimal/qminimalintegration.cpp b/src/plugins/platforms/minimal/qminimalintegration.cpp index 558089dfce..03c72502cb 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.cpp +++ b/src/plugins/platforms/minimal/qminimalintegration.cpp @@ -45,15 +45,15 @@ #include #if defined(Q_OS_WIN) -#include +#include #elif QT_CONFIG(fontconfig) -#include +#include #else #include #endif #if !defined(Q_OS_WIN) -#include +#include #elif defined(Q_OS_WINRT) #include #else diff --git a/src/plugins/platforms/minimalegl/minimalegl.pro b/src/plugins/platforms/minimalegl/minimalegl.pro index b8a91729fd..46334a0250 100644 --- a/src/plugins/platforms/minimalegl/minimalegl.pro +++ b/src/plugins/platforms/minimalegl/minimalegl.pro @@ -1,6 +1,8 @@ TARGET = qminimalegl -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private fontdatabase_support-private egl_support-private #DEFINES += QEGL_EXTRA_DEBUG diff --git a/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp b/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp index b1d3691a10..2afe42532e 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp +++ b/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp @@ -42,15 +42,15 @@ #include "qminimaleglwindow.h" #include "qminimaleglbackingstore.h" -#include +#include #if defined(Q_OS_UNIX) -# include +# include #elif defined(Q_OS_WINRT) # include # include #elif defined(Q_OS_WIN) -# include +# include #endif #include @@ -58,7 +58,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/minimalegl/qminimaleglscreen.cpp b/src/plugins/platforms/minimalegl/qminimaleglscreen.cpp index e8a9641224..d3d091fab7 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglscreen.cpp +++ b/src/plugins/platforms/minimalegl/qminimaleglscreen.cpp @@ -40,8 +40,8 @@ #include "qminimaleglscreen.h" #include "qminimaleglwindow.h" -#include -#include +#include +#include #ifdef Q_OPENKODE #include diff --git a/src/plugins/platforms/minimalegl/qminimaleglscreen.h b/src/plugins/platforms/minimalegl/qminimaleglscreen.h index 4b53bbd39a..ba605835a8 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglscreen.h +++ b/src/plugins/platforms/minimalegl/qminimaleglscreen.h @@ -44,7 +44,7 @@ #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/mirclient/mirclient.pro b/src/plugins/platforms/mirclient/mirclient.pro index d5d35f1632..054fe74a46 100644 --- a/src/plugins/platforms/mirclient/mirclient.pro +++ b/src/plugins/platforms/mirclient/mirclient.pro @@ -1,6 +1,9 @@ TARGET = qmirclient -QT += core-private gui-private platformsupport-private dbus +QT += \ + core-private gui-private dbus \ + theme_support-private eventdispatcher_support-private \ + fontdatabase_support-private egl_support-private CONFIG += qpa/genericunixfontdatabase diff --git a/src/plugins/platforms/mirclient/qmirclientglcontext.cpp b/src/plugins/platforms/mirclient/qmirclientglcontext.cpp index 4092669cfc..38eb0a4609 100644 --- a/src/plugins/platforms/mirclient/qmirclientglcontext.cpp +++ b/src/plugins/platforms/mirclient/qmirclientglcontext.cpp @@ -41,7 +41,7 @@ #include "qmirclientglcontext.h" #include "qmirclientwindow.h" #include "qmirclientlogging.h" -#include +#include #include #include diff --git a/src/plugins/platforms/mirclient/qmirclientintegration.cpp b/src/plugins/platforms/mirclient/qmirclientintegration.cpp index cfbcdc937e..2c8740f070 100644 --- a/src/plugins/platforms/mirclient/qmirclientintegration.cpp +++ b/src/plugins/platforms/mirclient/qmirclientintegration.cpp @@ -56,8 +56,8 @@ #include #include #include -#include -#include +#include +#include #include // platform-api diff --git a/src/plugins/platforms/mirclient/qmirclientplatformservices.h b/src/plugins/platforms/mirclient/qmirclientplatformservices.h index 46cf4300f8..a1cd5758ca 100644 --- a/src/plugins/platforms/mirclient/qmirclientplatformservices.h +++ b/src/plugins/platforms/mirclient/qmirclientplatformservices.h @@ -42,8 +42,8 @@ #define QMIRCLIENTPLATFORMSERVICES_H #include -#include -#include +#include +#include class QMirClientPlatformServices : public QPlatformServices { public: diff --git a/src/plugins/platforms/mirclient/qmirclientscreen.cpp b/src/plugins/platforms/mirclient/qmirclientscreen.cpp index ca0c3e4733..0a2253e9e2 100644 --- a/src/plugins/platforms/mirclient/qmirclientscreen.cpp +++ b/src/plugins/platforms/mirclient/qmirclientscreen.cpp @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include diff --git a/src/plugins/platforms/mirclient/qmirclienttheme.h b/src/plugins/platforms/mirclient/qmirclienttheme.h index 19728741e3..4bab1d0ee0 100644 --- a/src/plugins/platforms/mirclient/qmirclienttheme.h +++ b/src/plugins/platforms/mirclient/qmirclienttheme.h @@ -41,7 +41,7 @@ #ifndef QMIRCLIENTTHEME_H #define QMIRCLIENTTHEME_H -#include +#include class QMirClientTheme : public QGenericUnixTheme { diff --git a/src/plugins/platforms/offscreen/offscreen.pro b/src/plugins/platforms/offscreen/offscreen.pro index fbaa853c41..6652cefd86 100644 --- a/src/plugins/platforms/offscreen/offscreen.pro +++ b/src/plugins/platforms/offscreen/offscreen.pro @@ -1,6 +1,8 @@ TARGET = qoffscreen -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private fontdatabase_support-private DEFINES += QT_NO_FOREACH @@ -18,6 +20,7 @@ OTHER_FILES += offscreen.json qtConfig(xlib):qtConfig(opengl):!qtConfig(opengles2) { SOURCES += qoffscreenintegration_x11.cpp HEADERS += qoffscreenintegration_x11.h + QT += glx_support-private system(echo "Using X11 offscreen integration with GLX") } else { SOURCES += qoffscreenintegration_dummy.cpp diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp index 4c3d62a53b..56e6075cb2 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp @@ -42,14 +42,14 @@ #include "qoffscreencommon.h" #if defined(Q_OS_UNIX) -#include +#include #if defined(Q_OS_MAC) #include #else -#include +#include #endif #elif defined(Q_OS_WIN) -#include +#include #ifndef Q_OS_WINRT #include #else diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp index 2187eceed4..b46d94dfd3 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration_x11.cpp @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/openwfd/openwf.pro b/src/plugins/platforms/openwfd/openwf.pro index 79f349f472..747cbf404a 100644 --- a/src/plugins/platforms/openwfd/openwf.pro +++ b/src/plugins/platforms/openwfd/openwf.pro @@ -1,6 +1,8 @@ TARGET = qopenwf -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private fontdatabase_support-private CONFIG += qpa/genericunixfontdatabase diff --git a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp index 71e2b381fc..9ed61f7b2e 100644 --- a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp +++ b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp @@ -51,8 +51,8 @@ #include #include -#include -#include +#include +#include #include diff --git a/src/plugins/platforms/qnx/qnx.pro b/src/plugins/platforms/qnx/qnx.pro index a726980f5b..9da3d6811b 100644 --- a/src/plugins/platforms/qnx/qnx.pro +++ b/src/plugins/platforms/qnx/qnx.pro @@ -1,6 +1,8 @@ TARGET = qqnx -QT += platformsupport-private core-private gui-private +QT += \ + core-private gui-private \ + fontdatabase_support-private eventdispatcher_support-private egl_support-private # Uncomment this to build with support for IMF once it becomes available in the BBNDK #CONFIG += qqnx_imf diff --git a/src/plugins/platforms/vnc/qvncintegration.cpp b/src/plugins/platforms/vnc/qvncintegration.cpp index 3227478ebe..025112c790 100644 --- a/src/plugins/platforms/vnc/qvncintegration.cpp +++ b/src/plugins/platforms/vnc/qvncintegration.cpp @@ -38,19 +38,19 @@ #include "qvncscreen.h" #include "qvnc_p.h" -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #include #include #include #if QT_CONFIG(libinput) -#include +#include #endif #include diff --git a/src/plugins/platforms/vnc/qvncscreen.cpp b/src/plugins/platforms/vnc/qvncscreen.cpp index 6d117c62bf..34def45767 100644 --- a/src/plugins/platforms/vnc/qvncscreen.cpp +++ b/src/plugins/platforms/vnc/qvncscreen.cpp @@ -39,8 +39,8 @@ #include "qvncscreen.h" #include "qvnc_p.h" -#include -#include +#include +#include #include #include diff --git a/src/plugins/platforms/vnc/qvncscreen.h b/src/plugins/platforms/vnc/qvncscreen.h index e3c6651781..785abd6dc2 100644 --- a/src/plugins/platforms/vnc/qvncscreen.h +++ b/src/plugins/platforms/vnc/qvncscreen.h @@ -40,7 +40,7 @@ #ifndef QVncScreen_H #define QVncScreen_H -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/vnc/vnc.pro b/src/plugins/platforms/vnc/vnc.pro index 1817e15201..15407f9298 100644 --- a/src/plugins/platforms/vnc/vnc.pro +++ b/src/plugins/platforms/vnc/vnc.pro @@ -5,7 +5,13 @@ PLUGIN_CLASS_NAME = QVncIntegrationPlugin !equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - load(qt_plugin) -QT += core-private gui-private platformsupport-private network +QT += \ + core-private network gui-private \ + service_support-private theme_support-private fb_support-private \ + eventdispatcher_support-private fontdatabase_support-private + +qtHaveModule(input_support-private): \ + QT += input_support-private DEFINES += QT_NO_FOREACH diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp index 5ba49a8a98..d5cd9ac6db 100644 --- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp +++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp @@ -41,7 +41,7 @@ #include "iaccessible2.h" #include "qwindowsaccessibility.h" -#include +#include #include #include #include diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index 21bc9d7377..d4a7e27762 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -53,7 +53,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index d4cdf3ef3c..bc317c7f5d 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -72,7 +72,7 @@ #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h index fa8f777133..90008e20a4 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h @@ -40,7 +40,7 @@ #ifndef QWINDOWSFONTDATABASEFT_H #define QWINDOWSFONTDATABASEFT_H -#include +#include #include #include diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index b9a63c7a89..16a2b56774 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -72,7 +72,7 @@ #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index fd7eca9e32..b8c4f0b736 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #if defined(WM_APPCOMMAND) # ifndef FAPPCOMMAND_MOUSE diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 841464391d..fe67c0ce37 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -68,7 +68,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/windows/windows.pro b/src/plugins/platforms/windows/windows.pro index adafa830d5..23168c10dc 100644 --- a/src/plugins/platforms/windows/windows.pro +++ b/src/plugins/platforms/windows/windows.pro @@ -1,8 +1,9 @@ TARGET = qwindows -QT *= core-private -QT *= gui-private -QT *= platformsupport-private +QT += \ + core-private gui-private \ + eventdispatcher_support-private accessibility_support-private \ + fontdatabase_support-private theme_support-private LIBS += -lgdi32 -ldwmapi diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.cpp b/src/plugins/platforms/winrt/qwinrteglcontext.cpp index 5c3ecd8726..8a250c516a 100644 --- a/src/plugins/platforms/winrt/qwinrteglcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrteglcontext.cpp @@ -51,8 +51,8 @@ #include #include -#include -#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtfontdatabase.h b/src/plugins/platforms/winrt/qwinrtfontdatabase.h index 8539bcb9db..8fed4a3fa7 100644 --- a/src/plugins/platforms/winrt/qwinrtfontdatabase.h +++ b/src/plugins/platforms/winrt/qwinrtfontdatabase.h @@ -40,7 +40,7 @@ #ifndef QWINRTFONTDATABASE_H #define QWINRTFONTDATABASE_H -#include +#include #include struct IDWriteFontFile; diff --git a/src/plugins/platforms/winrt/qwinrtintegration.cpp b/src/plugins/platforms/winrt/qwinrtintegration.cpp index 32edf2b1a2..7a0c95e6c1 100644 --- a/src/plugins/platforms/winrt/qwinrtintegration.cpp +++ b/src/plugins/platforms/winrt/qwinrtintegration.cpp @@ -56,7 +56,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/plugins/platforms/winrt/qwinrtwindow.cpp b/src/plugins/platforms/winrt/qwinrtwindow.cpp index 5b82183d40..297e6618d1 100644 --- a/src/plugins/platforms/winrt/qwinrtwindow.cpp +++ b/src/plugins/platforms/winrt/qwinrtwindow.cpp @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/plugins/platforms/winrt/winrt.pro b/src/plugins/platforms/winrt/winrt.pro index 174b0362b4..8fd2a83a16 100644 --- a/src/plugins/platforms/winrt/winrt.pro +++ b/src/plugins/platforms/winrt/winrt.pro @@ -2,7 +2,9 @@ TARGET = qwinrt CONFIG -= precompile_header -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + fontdatabase_support-private egl_support-private DEFINES *= QT_NO_CAST_FROM_ASCII __WRL_NO_DEFAULT_LIB__ diff --git a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri index a94815dfbd..b44e4ecaa9 100644 --- a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri +++ b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri @@ -1,4 +1,4 @@ -QT += core-private gui-private platformsupport-private xcb_qpa_lib-private +QT += core-private gui-private xcb_qpa_lib-private INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD/../ diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h index 64e9bec6db..48e774bbb2 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglcontext.h @@ -41,8 +41,8 @@ #define QXCBEGLCONTEXT_H #include "qxcbeglwindow.h" -#include -#include +#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h index 7c6524c8ee..a5a47dd0bb 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglinclude.h @@ -46,7 +46,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp index 00f64e3c40..4852d38f7e 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglintegration.cpp @@ -42,7 +42,7 @@ #include "qxcbeglcontext.h" #include -#include +#include #include "qxcbeglnativeinterfacehandler.h" diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp index 69b7dfbdbf..3f7ef94238 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/qxcbeglwindow.cpp @@ -41,8 +41,8 @@ #include "qxcbeglintegration.h" -#include -#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro index 6b3f9b171a..1c193849ca 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_egl/xcb_egl.pro @@ -1,6 +1,7 @@ TARGET = qxcb-egl-integration include(../gl_integrations_plugin_base.pri) +QT += egl_support-private CONFIG += egl diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp index 5580f81a7a..dc720c090f 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp @@ -51,7 +51,7 @@ #include #include "qglxintegration.h" -#include +#include #include #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp index 8ae83b8084..e534ae13c6 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp @@ -40,7 +40,7 @@ #include "qxcbglxwindow.h" #include "qxcbscreen.h" -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro index e52677d091..8aa6e1febd 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/xcb_glx.pro @@ -1,6 +1,7 @@ TARGET = qxcb-glx-integration include(../gl_integrations_plugin_base.pri) +QT += glx_support-private #should be removed from the sources DEFINES += XCB_USE_GLX XCB_USE_XLIB diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index b0c5ac79f9..f4da7ba033 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -55,9 +55,9 @@ #include -#include -#include -#include +#include +#include +#include #include @@ -77,7 +77,7 @@ #ifndef QT_NO_ACCESSIBILITY #include #ifndef QT_NO_ACCESSIBILITY_ATSPI_BRIDGE -#include "../../../platformsupport/linuxaccessibility/bridge_p.h" +#include #endif #endif diff --git a/src/plugins/platforms/xcb/xcb-plugin.pro b/src/plugins/platforms/xcb/xcb-plugin.pro index d7f150f276..01d493156d 100644 --- a/src/plugins/platforms/xcb/xcb-plugin.pro +++ b/src/plugins/platforms/xcb/xcb-plugin.pro @@ -1,6 +1,6 @@ TARGET = qxcb -QT += core-private gui-private platformsupport-private xcb_qpa_lib-private +QT += core-private gui-private xcb_qpa_lib-private DEFINES += QT_NO_FOREACH diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index 69d2e35606..37556baa1d 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -2,7 +2,13 @@ TARGET = QtXcbQpa CONFIG += no_module_headers internal_module DEFINES += QT_NO_FOREACH -QT += core-private gui-private platformsupport-private +QT += \ + core-private gui-private \ + service_support-private theme_support-private \ + eventdispatcher_support-private fontdatabase_support-private + +qtHaveModule(linuxaccessibility_support-private): \ + QT += linuxaccessibility_support-private SOURCES = \ qxcbclipboard.cpp \ -- cgit v1.2.3 From f25afef61da17088fc9cdeb15be7144ef0c7c867 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 12 Oct 2016 12:08:33 +0200 Subject: rely on transitive library dependencies for freetype/fontconfig so far, we have been delaying the linking, because we didn't want to make the monolithic platformsupport module pull in spurious dependencies. however, now that the module was split, there is no need to play such games any more. a nice effect of this is that the hideous qpa/*unixfontdatabase.prf files disappear, and finally freetype_dependency.pri also becomes trivial and is thus inlined. Change-Id: I255376d592625542310a31222eb6ac965943df99 Reviewed-by: Jake Petroules --- src/plugins/platforms/android/android.pro | 2 -- src/plugins/platforms/bsdfb/bsdfb.pro | 2 -- src/plugins/platforms/directfb/directfb.pro | 3 --- src/plugins/platforms/eglfs/eglfsdeviceintegration.pro | 2 +- src/plugins/platforms/integrity/integrity.pro | 2 -- src/plugins/platforms/linuxfb/linuxfb.pro | 2 -- src/plugins/platforms/minimal/minimal.pro | 2 -- src/plugins/platforms/minimalegl/minimalegl.pro | 2 +- src/plugins/platforms/mirclient/mirclient.pro | 2 -- src/plugins/platforms/openwfd/openwf.pro | 2 -- src/plugins/platforms/vnc/vnc.pro | 2 -- .../platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri | 2 -- src/plugins/platforms/xcb/xcb_qpa_lib.pro | 2 -- 13 files changed, 2 insertions(+), 25 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 5912edc847..bd3fe5a6cc 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -11,8 +11,6 @@ QT += \ eventdispatcher_support-private accessibility_support-private \ fontdatabase_support-private egl_support-private -CONFIG += qpa/genericunixfontdatabase - OTHER_FILES += $$PWD/android.json INCLUDEPATH += \ diff --git a/src/plugins/platforms/bsdfb/bsdfb.pro b/src/plugins/platforms/bsdfb/bsdfb.pro index 294edcd35d..770145a8ff 100644 --- a/src/plugins/platforms/bsdfb/bsdfb.pro +++ b/src/plugins/platforms/bsdfb/bsdfb.pro @@ -11,8 +11,6 @@ qtHaveModule(input_support-private): \ SOURCES = main.cpp qbsdfbintegration.cpp qbsdfbscreen.cpp HEADERS = qbsdfbintegration.h qbsdfbscreen.h -CONFIG += qpa/genericunixfontdatabase - OTHER_FILES += bsdfb.json PLUGIN_TYPE = platforms diff --git a/src/plugins/platforms/directfb/directfb.pro b/src/plugins/platforms/directfb/directfb.pro index da7634856c..406b89e3b2 100644 --- a/src/plugins/platforms/directfb/directfb.pro +++ b/src/plugins/platforms/directfb/directfb.pro @@ -44,9 +44,6 @@ qtConfig(directfb_egl) { SOURCES += qdirectfbeglhooks_stub.cpp } - -CONFIG += qpa/genericunixfontdatabase - OTHER_FILES += directfb.json PLUGIN_TYPE = platforms diff --git a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro index 638d12a368..35af3615bd 100644 --- a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro +++ b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro @@ -39,7 +39,7 @@ QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF DEFINES += EGLFS_PREFERRED_PLUGIN=$$EGLFS_DEVICE_INTEGRATION } -CONFIG += egl qpa/genericunixfontdatabase +CONFIG += egl # Prevent gold linker from crashing. # This started happening when QtPlatformSupport was modularized. diff --git a/src/plugins/platforms/integrity/integrity.pro b/src/plugins/platforms/integrity/integrity.pro index 178fc1b882..0fb256793d 100644 --- a/src/plugins/platforms/integrity/integrity.pro +++ b/src/plugins/platforms/integrity/integrity.pro @@ -16,8 +16,6 @@ HEADERS = \ qintegrityfbscreen.h \ qintegrityhidmanager.h -CONFIG += qpa/genericunixfontdatabase - OTHER_FILES += integrity.json PLUGIN_TYPE = platforms diff --git a/src/plugins/platforms/linuxfb/linuxfb.pro b/src/plugins/platforms/linuxfb/linuxfb.pro index a752f95917..e2fa31211d 100644 --- a/src/plugins/platforms/linuxfb/linuxfb.pro +++ b/src/plugins/platforms/linuxfb/linuxfb.pro @@ -13,8 +13,6 @@ qtHaveModule(input_support-private): \ SOURCES = main.cpp qlinuxfbintegration.cpp qlinuxfbscreen.cpp HEADERS = qlinuxfbintegration.h qlinuxfbscreen.h -CONFIG += qpa/genericunixfontdatabase - OTHER_FILES += linuxfb.json PLUGIN_TYPE = platforms diff --git a/src/plugins/platforms/minimal/minimal.pro b/src/plugins/platforms/minimal/minimal.pro index 0fffb24d24..8cfb68824e 100644 --- a/src/plugins/platforms/minimal/minimal.pro +++ b/src/plugins/platforms/minimal/minimal.pro @@ -14,8 +14,6 @@ HEADERS = qminimalintegration.h \ OTHER_FILES += minimal.json -CONFIG += qpa/genericunixfontdatabase - PLUGIN_TYPE = platforms PLUGIN_CLASS_NAME = QMinimalIntegrationPlugin !equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - diff --git a/src/plugins/platforms/minimalegl/minimalegl.pro b/src/plugins/platforms/minimalegl/minimalegl.pro index 46334a0250..88466e7f36 100644 --- a/src/plugins/platforms/minimalegl/minimalegl.pro +++ b/src/plugins/platforms/minimalegl/minimalegl.pro @@ -22,7 +22,7 @@ HEADERS = qminimaleglintegration.h \ qminimaleglbackingstore.h \ qminimaleglscreen.h -CONFIG += egl qpa/genericunixfontdatabase +CONFIG += egl OTHER_FILES += \ minimalegl.json diff --git a/src/plugins/platforms/mirclient/mirclient.pro b/src/plugins/platforms/mirclient/mirclient.pro index 054fe74a46..623f7bf97b 100644 --- a/src/plugins/platforms/mirclient/mirclient.pro +++ b/src/plugins/platforms/mirclient/mirclient.pro @@ -5,8 +5,6 @@ QT += \ theme_support-private eventdispatcher_support-private \ fontdatabase_support-private egl_support-private -CONFIG += qpa/genericunixfontdatabase - DEFINES += MESA_EGL_NO_X11_HEADERS # CONFIG += c++11 # only enables C++0x QMAKE_CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11 -Werror -Wall diff --git a/src/plugins/platforms/openwfd/openwf.pro b/src/plugins/platforms/openwfd/openwf.pro index 747cbf404a..6012731b65 100644 --- a/src/plugins/platforms/openwfd/openwf.pro +++ b/src/plugins/platforms/openwfd/openwf.pro @@ -4,8 +4,6 @@ QT += \ core-private gui-private \ eventdispatcher_support-private fontdatabase_support-private -CONFIG += qpa/genericunixfontdatabase - HEADERS += \ qopenwfddevice.h \ qopenwfdintegration.h \ diff --git a/src/plugins/platforms/vnc/vnc.pro b/src/plugins/platforms/vnc/vnc.pro index 15407f9298..3cd7e9b160 100644 --- a/src/plugins/platforms/vnc/vnc.pro +++ b/src/plugins/platforms/vnc/vnc.pro @@ -28,6 +28,4 @@ HEADERS = \ qvnc_p.h \ qvncclient.h -CONFIG += qpa/genericunixfontdatabase - OTHER_FILES += vnc.json diff --git a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri index b44e4ecaa9..4ab406acb9 100644 --- a/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri +++ b/src/plugins/platforms/xcb/gl_integrations/gl_integrations_plugin_base.pri @@ -18,8 +18,6 @@ qtConfig(xcb-sm) { DEFINES += XCB_USE_SM } -CONFIG += qpa/genericunixfontdatabase - !qtConfig(system-xcb) { DEFINES += XCB_USE_RENDER QMAKE_USE += xcb-static xcb diff --git a/src/plugins/platforms/xcb/xcb_qpa_lib.pro b/src/plugins/platforms/xcb/xcb_qpa_lib.pro index 37556baa1d..6db0c76dea 100644 --- a/src/plugins/platforms/xcb/xcb_qpa_lib.pro +++ b/src/plugins/platforms/xcb/xcb_qpa_lib.pro @@ -70,8 +70,6 @@ qtConfig(xcb-sm) { include(gl_integrations/gl_integrations.pri) -CONFIG += qpa/genericunixfontdatabase - !qtConfig(system-xcb) { DEFINES += XCB_USE_RENDER QMAKE_USE += xcb-static xcb -- cgit v1.2.3 From b00565bc2803bb783e8f2b0d02becfa73323e283 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 15 Jun 2016 14:07:33 +0200 Subject: iOS: check if qApp is still valid before accessing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the application quits, the iOS plugin can be told to delete after qApp has been set to null. So we need to add a check for this, to avoid error messages. Change-Id: I687e0b26e0c54fdd5a8539fe0f31b2e756ea92d8 Reviewed-by: Tor Arne Vestbø Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/qiostextinputoverlay.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index d930965bde..54c2e98d71 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -994,7 +994,8 @@ QIOSTextInputOverlay::QIOSTextInputOverlay() QIOSTextInputOverlay::~QIOSTextInputOverlay() { - disconnect(qApp, 0, this, 0); + if (qApp) + disconnect(qApp, 0, this, 0); } void QIOSTextInputOverlay::updateFocusObject() -- cgit v1.2.3 From 1cc6cc56e16a8fd4fd22dfa187bbb92433a8dba1 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 14 Oct 2016 08:49:54 -0700 Subject: Fix tvOS build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I128605050b68787f8c9671f4aa8de0a1667301d8 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosviewcontroller.h | 2 -- src/plugins/platforms/ios/qiosviewcontroller.mm | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h index f7b190ba22..07d5535e1a 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.h +++ b/src/plugins/platforms/ios/qiosviewcontroller.h @@ -53,11 +53,9 @@ QT_END_NAMESPACE #ifndef Q_OS_TVOS @property (nonatomic, assign) UIInterfaceOrientation lockedOrientation; -#endif // UIViewController @property (nonatomic, assign) BOOL prefersStatusBarHidden; -#ifndef Q_OS_TVOS @property (nonatomic, assign) UIStatusBarAnimation preferredStatusBarUpdateAnimation; @property (nonatomic, assign) UIStatusBarStyle preferredStatusBarStyle; #endif diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index 0478c5b8c8..c47b6d68b1 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -229,9 +229,11 @@ @implementation QIOSViewController +#ifndef Q_OS_TVOS @synthesize prefersStatusBarHidden; @synthesize preferredStatusBarUpdateAnimation; @synthesize preferredStatusBarStyle; +#endif - (id)initWithQIOSScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen { -- cgit v1.2.3 From 9d696af6cd45ee95c155829999b8184229f9bc72 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 11 Oct 2016 11:24:37 +0200 Subject: Disable WindowsContextHelpButtonHint for Dialogs that are not QWidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not set WindowsContextHelpButtonHint directly in Windows QPA plugin, but instead rely on logic in QWidgetPrivate::adjustFlags for widgets. If WindowsContextHelpButtonHint is set, a '?' button is shown in the windows decoration. If pressed, an EnterWhatsThisMode event is generated that is consumed in QApplication that then calls into the QWhatsThis singleton, which changes the mouse cursor, and informs the top-level QWidgets about the state change etc. For QGuiApplications though the event is not generated, which makes the button useless by default. In addition, QWhatsThis only works with top level QWidgets, not e.g. QQuickWindows. So for apps using QApplication and QtQuick.Controls this means that the "What's this mode" is never exited. Given that the paradigm is somewhat outdated on the desktop it is unlikely that Qt Quick Controls will implement support for What's this. Anyhow, QWidgetPrivate::adjustFlags sets the hint for Qt::Dialogs, too, so there's no need to set it the Windows QPA plugin. [ChangeLog][Windows] 'What's this' button is now shown by default only for QWidget dialogs. Task-number: QTBUG-56239 Change-Id: I1ea3e92ade723b5865c8f2e19674413433658942 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/windows/qwindowswindow.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 7289f8de6d..0ebed59a1d 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -424,11 +424,9 @@ static inline void fixTopLevelWindowFlags(Qt::WindowFlags &flags) |Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint; break; case Qt::Dialog: - flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint; - break; case Qt::Tool: - flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; - break; + flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; + break; default: break; } -- cgit v1.2.3 From ce2ae6ebd8cfebf9edbb0b5653e80de029669548 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 17 Oct 2016 13:35:45 +0200 Subject: Windows: Fix rendering of MingLiU fonts at some scales At certain sizes and scales, GDI will clip away the bottom line of pixels when rendering the MingLiU fonts. Since DirectWrite renders it correctly, we force the use of DirectWrite in this case. This also requires supporting classic GDI rendering in the DirectWrite engine, to make sure the rendering still looks correct. Note that this does not cover the corner case where the font is loaded directly from data with QRawFont. [ChangeLog][QtGui][Windows] Fixed rendering error when using the MingLiU fonts at certain combinations of pixel size and scale. Task-number: QTBUG-49346 Change-Id: Ie026c0d5932717858c4536dae077013eb6a1eafc Reviewed-by: Konstantin Ritt Reviewed-by: Simon Hausmann --- .../platforms/windows/qwindowsfontdatabase.cpp | 12 ++++++++++-- .../windows/qwindowsfontenginedirectwrite.cpp | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp index 4f022141cf..1630b80306 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp @@ -110,13 +110,21 @@ static void createDirectWriteFactory(IDWriteFactory **factory) *factory = static_cast(result); } -static inline bool useDirectWrite(QFont::HintingPreference hintingPreference, bool isColorFont = false) +static inline bool useDirectWrite(QFont::HintingPreference hintingPreference, + const QString &familyName = QString(), + bool isColorFont = false) { const unsigned options = QWindowsIntegration::instance()->options(); if (Q_UNLIKELY(options & QWindowsIntegration::DontUseDirectWriteFonts)) return false; if (isColorFont) return (options & QWindowsIntegration::DontUseColorFonts) == 0; + + // At some scales, GDI will misrender the MingLiU font, so we force use of + // DirectWrite to work around the issue. + if (Q_UNLIKELY(familyName.startsWith(QLatin1String("MingLiU")))) + return true; + return hintingPreference == QFont::PreferNoHinting || hintingPreference == QFont::PreferVerticalHinting || (QHighDpiScaling::isActive() && hintingPreference == QFont::PreferDefaultHinting); @@ -1875,7 +1883,7 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, #endif const QFont::HintingPreference hintingPreference = static_cast(request.hintingPreference); - const bool useDw = useDirectWrite(hintingPreference, isColorFont); + const bool useDw = useDirectWrite(hintingPreference, fam, isColorFont); qCDebug(lcQpaFonts) << __FUNCTION__ << request.family << request.pointSize << "pt" << "hintingPreference=" << hintingPreference << "color=" << isColorFont << dpi << "dpi" << "useDirectWrite=" << useDw; diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp index 66cc08f9fa..334e9cb8b9 100644 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp @@ -185,6 +185,18 @@ namespace { } +static DWRITE_RENDERING_MODE hintingPreferenceToRenderingMode(QFont::HintingPreference hintingPreference) +{ + switch (hintingPreference) { + case QFont::PreferNoHinting: + return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; + case QFont::PreferVerticalHinting: + return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL; + default: + return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC; + } +} + /*! \class QWindowsFontEngineDirectWrite \brief Windows font engine using Direct Write. @@ -661,9 +673,7 @@ QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, transform.m22 = xform.m22(); DWRITE_RENDERING_MODE renderMode = - fontDef.hintingPreference == QFont::PreferNoHinting - ? DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC - : DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL; + hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; HRESULT hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( @@ -950,9 +960,7 @@ glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph transform.m22 = matrix.m22(); DWRITE_RENDERING_MODE renderMode = - fontDef.hintingPreference == QFont::PreferNoHinting - ? DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC - : DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL; + hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; HRESULT hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( -- cgit v1.2.3 From 4a4368df5663729a34761c394a6f02b72071e89c Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 18 Oct 2016 13:17:53 +0300 Subject: QAndroidPlatformTheme: wrap char* in QL1S to avoid warnings Change-Id: Idcc70038051b03366aa447f3a4c48912d3f911d5 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/qandroidplatformtheme.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp index 9350a15721..801bb78436 100644 --- a/src/plugins/platforms/android/qandroidplatformtheme.cpp +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp @@ -458,9 +458,9 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const case StyleNames: if (qEnvironmentVariableIntValue("QT_USE_ANDROID_NATIVE_STYLE") && m_androidStyleData) { - return QStringList("android"); + return QStringList(QLatin1String("android")); } - return QStringList("fusion"); + return QStringList(QLatin1String("fusion")); case MouseDoubleClickDistance: { -- cgit v1.2.3 From 6a7b683817e7427cf952130b7726833fd5be74ce Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 17 Oct 2016 18:54:26 +0300 Subject: Plugins: optimize string usage Prefer QStringRef methods to avoid allocations. Use startsWith/endsWith rather than comparing substrings; and avoid substrings where references suffice. Use new QStringList::join(QL1S). Change-Id: I46c44aca96578633370006d613eb0ac13f7cfc03 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/plugins/platforms/android/qandroidinputcontext.cpp | 11 +++++------ src/plugins/platforms/qnx/qqnxscreen.cpp | 2 +- src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp | 6 +++--- src/plugins/platforms/xcb/qxcbmime.cpp | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 06a9c8c488..2656d45d5f 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -866,7 +866,7 @@ const QAndroidInputContext::ExtractedText &QAndroidInputContext::getExtractedTex if (composeLength > 0) { //Qt doesn't give us the preedit text, so we have to insert it at the correct position int localComposePos = m_composingTextStart - blockPos; - blockText = blockText.left(localComposePos) + m_composingText + blockText.mid(localComposePos); + blockText = blockText.leftRef(localComposePos) + m_composingText + blockText.midRef(localComposePos); } int cpos = localPos + composeLength; //actual cursor pos relative to the current block @@ -930,9 +930,8 @@ QString QAndroidInputContext::getTextAfterCursor(jint length, jint /*flags*/) QString QAndroidInputContext::getTextBeforeCursor(jint length, jint /*flags*/) { QVariant textBefore = queryFocusObjectThreadSafe(Qt::ImTextBeforeCursor, QVariant(length)); - if (textBefore.isValid()) { - return textBefore.toString().right(length) + m_composingText; - } + if (textBefore.isValid()) + return textBefore.toString().rightRef(length) + m_composingText; //compatibility code for old controls that do not implement the new API QSharedPointer query = focusObjectInputMethodQueryThreadSafe(); @@ -946,9 +945,9 @@ QString QAndroidInputContext::getTextBeforeCursor(jint length, jint /*flags*/) //### the preedit text does not need to be immediately before the cursor if (cursorPos <= length) - return text.left(cursorPos) + m_composingText; + return text.leftRef(cursorPos) + m_composingText; else - return text.mid(cursorPos - length, length) + m_composingText; + return text.midRef(cursorPos - length, length) + m_composingText; } /* diff --git a/src/plugins/platforms/qnx/qqnxscreen.cpp b/src/plugins/platforms/qnx/qqnxscreen.cpp index f8ae5121d1..46df500330 100644 --- a/src/plugins/platforms/qnx/qqnxscreen.cpp +++ b/src/plugins/platforms/qnx/qqnxscreen.cpp @@ -90,7 +90,7 @@ static QSize determineScreenSize(screen_display_t display, bool primaryScreen) { const QString envPhySizeStr = qgetenv("QQNX_PHYSICAL_SCREEN_SIZE"); if (!envPhySizeStr.isEmpty()) { - const QStringList envPhySizeStrList = envPhySizeStr.split(QLatin1Char(',')); + const auto envPhySizeStrList = envPhySizeStr.splitRef(QLatin1Char(',')); const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1; const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1; diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp index f7c8dbdf23..bc0e5cc523 100644 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp @@ -137,10 +137,10 @@ static FontKeys &fontKeys() QString realKey = registryFontKey; realKey.remove(trueType); realKey.remove(sizeListMatch); - const QStringList fontNames = realKey.trimmed().split(QLatin1Char('&')); + const auto fontNames = QStringRef(&realKey).trimmed().split(QLatin1Char('&')); fontKey.fontNames.reserve(fontNames.size()); - foreach (const QString &fontName, fontNames) - fontKey.fontNames.append(fontName.trimmed()); + for (const QStringRef &fontName : fontNames) + fontKey.fontNames.append(fontName.trimmed().toString()); result.append(fontKey); } } diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index f71c5464d0..3e9b0e1e4a 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -208,10 +208,10 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, reinterpret_cast(data.constData()), data.size() / 2); if (!str.isNull()) { if (format == QLatin1String("text/uri-list")) { - const QStringList urls = str.split(QLatin1Char('\n')); + const auto urls = str.splitRef(QLatin1Char('\n')); QList list; - for (const QString &s : urls) { - const QUrl url(s.trimmed()); + for (const QStringRef &s : urls) { + const QUrl url(s.trimmed().toString()); if (url.isValid()) list.append(url); } -- cgit v1.2.3 From ee22c6505a1f7cf52a862b1bd9219511db893417 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Tue, 30 Aug 2016 07:52:17 -0600 Subject: xcb: fix passing of focus from child to its top level QWindow With the client message _NET_ACTIVE_WINDOW, not all window managers will pass focus from a child window to its root window, Detect this child-to-root case, and use xcb_set_input_focus() instead. Task-number: QTBUG-39362 Change-Id: Ib32193018e3b725b323f87d7306c9ae9493d78a7 Reviewed-by: Shawn Rutledge Reviewed-by: Edward Welbourne Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/xcb/qxcbwindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 5f402b6eca..25a8b41195 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -1698,9 +1698,11 @@ void QXcbWindow::requestActivateWindow() m_deferredActivation = false; updateNetWmUserTime(connection()->time()); + QWindow *focusWindow = QGuiApplication::focusWindow(); if (window()->isTopLevel() && !(window()->flags() & Qt::X11BypassWindowManagerHint) + && (!focusWindow || !window()->isAncestorOf(focusWindow)) && connection()->wmSupport()->isSupportedByWM(atom(QXcbAtom::_NET_ACTIVE_WINDOW))) { xcb_client_message_event_t event; @@ -1711,7 +1713,6 @@ void QXcbWindow::requestActivateWindow() event.type = atom(QXcbAtom::_NET_ACTIVE_WINDOW); event.data.data32[0] = 1; event.data.data32[1] = connection()->time(); - QWindow *focusWindow = QGuiApplication::focusWindow(); event.data.data32[2] = focusWindow ? focusWindow->winId() : XCB_NONE; event.data.data32[3] = 0; event.data.data32[4] = 0; -- cgit v1.2.3 From cd081ca96a5387abe36f46a347363e07edcdcd67 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 19 Sep 2016 12:13:33 +0200 Subject: macOS: Only show menu and allow dragging on proxy when a file path is set If there is no file path set then it should not be possible to see a menu or to drag from a proxy icon in the titlebar. Task-number: QTBUG-56082 Change-Id: Ib8305bcab5717bc8cb7ddabbb079f152debbdded Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 2 ++ src/plugins/platforms/cocoa/qnswindowdelegate.h | 3 ++- src/plugins/platforms/cocoa/qnswindowdelegate.mm | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 9fcb221d37..9cf6328281 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -346,6 +346,7 @@ public: // for QNSView // This object is tracked by QCocoaWindowPointer, // preventing the use of dangling pointers. QObject sentinel; + bool m_hasWindowFilePath; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index c0d5904367..977a5ae657 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -379,6 +379,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) , m_topContentBorderThickness(0) , m_bottomContentBorderThickness(0) , m_normalGeometry(QRect(0,0,-1,-1)) + , m_hasWindowFilePath(false) { #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG qDebug() << "QCocoaWindow::QCocoaWindow" << this; @@ -941,6 +942,7 @@ void QCocoaWindow::setWindowFilePath(const QString &filePath) QFileInfo fi(filePath); [m_nsWindow setRepresentedFilename: fi.exists() ? QCFString::toNSString(filePath) : @""]; + m_hasWindowFilePath = fi.exists(); } void QCocoaWindow::setWindowIcon(const QIcon &icon) diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.h b/src/plugins/platforms/cocoa/qnswindowdelegate.h index b8d344aa0e..a5f3dca68c 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.h +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.h @@ -51,7 +51,8 @@ - (void)windowWillMove:(NSNotification *)notification; - (BOOL)windowShouldClose:(NSNotification *)notification; - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; - +- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu; +- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard; @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSWindowDelegate); diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm index 015274cac7..a26f381ddb 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm @@ -109,4 +109,19 @@ return YES; } +- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu +{ + Q_UNUSED(window); + Q_UNUSED(menu); + return m_cocoaWindow && m_cocoaWindow->m_hasWindowFilePath; +} + +- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard +{ + Q_UNUSED(window); + Q_UNUSED(event); + Q_UNUSED(dragImageLocation); + Q_UNUSED(pasteboard); + return m_cocoaWindow && m_cocoaWindow->m_hasWindowFilePath; +} @end -- cgit v1.2.3 From b6df7257501b54521c25587c3c5e600b2c9393d1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 20 Oct 2016 18:31:10 +0200 Subject: Fix UB (ininited pointer read) in qt_egl_device_integration() The m_integration member of DeviceIntegration, a naked pointer, was checked for nullptr in the DeviceIntegration ctor, but never set to nullptr. Fix by init'ing it to nullptr in the ctor-init-list. Coverity-Id: 172056 Change-Id: Ia1dc9b67b9d16a991bba82338eedb19de68f91d8 Reviewed-by: Thiago Macieira --- src/plugins/platforms/eglfs/qeglfshooks.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/eglfs/qeglfshooks.cpp b/src/plugins/platforms/eglfs/qeglfshooks.cpp index cf016d1b01..638960d998 100644 --- a/src/plugins/platforms/eglfs/qeglfshooks.cpp +++ b/src/plugins/platforms/eglfs/qeglfshooks.cpp @@ -61,6 +61,7 @@ private: Q_GLOBAL_STATIC(DeviceIntegration, deviceIntegration) DeviceIntegration::DeviceIntegration() + : m_integration(Q_NULLPTR) { QStringList pluginKeys = QEGLDeviceIntegrationFactory::keys(); if (!pluginKeys.isEmpty()) { -- cgit v1.2.3 From 016b5bc949b6dfb2f76db2e8b40a40e7eaee6828 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 19 Oct 2016 12:20:10 +0300 Subject: Plugins: use reserve() to optimize memory allocations Change-Id: Id78ce43137e352292a9933222fe2f92d4ff4d69b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/plugins/platforms/mirclient/qmirclientinput.cpp | 1 + src/plugins/platforms/openwfd/qopenwfdintegration.cpp | 1 + src/plugins/platforms/qnx/qqnxbuttoneventnotifier.cpp | 1 + src/plugins/platforms/xcb/qxcbmime.cpp | 1 + 4 files changed, 4 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/mirclient/qmirclientinput.cpp b/src/plugins/platforms/mirclient/qmirclientinput.cpp index 4817185d41..b3b21ae0e3 100644 --- a/src/plugins/platforms/mirclient/qmirclientinput.cpp +++ b/src/plugins/platforms/mirclient/qmirclientinput.cpp @@ -347,6 +347,7 @@ void QMirClientInput::dispatchTouchEvent(QMirClientWindow *window, const MirInpu // TODO: Is it worth setting the Qt::TouchPointStationary ones? Currently they are left // as Qt::TouchPointMoved const unsigned int kPointerCount = mir_touch_event_point_count(tev); + touchPoints.reserve(int(kPointerCount)); for (unsigned int i = 0; i < kPointerCount; ++i) { QWindowSystemInterface::TouchPoint touchPoint; diff --git a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp index 9ed61f7b2e..4850ca2e45 100644 --- a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp +++ b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp @@ -68,6 +68,7 @@ QOpenWFDIntegration::QOpenWFDIntegration() int actualNumberOfDevices = wfdEnumerateDevices(devices,numberOfDevices,0); Q_ASSERT(actualNumberOfDevices == numberOfDevices); + mDevices.reserve(actualNumberOfDevices); for (int i = 0; i < actualNumberOfDevices; i++) { mDevices.append(new QOpenWFDDevice(this,devices[i])); } diff --git a/src/plugins/platforms/qnx/qqnxbuttoneventnotifier.cpp b/src/plugins/platforms/qnx/qqnxbuttoneventnotifier.cpp index 90a09d3087..a6236f2376 100644 --- a/src/plugins/platforms/qnx/qqnxbuttoneventnotifier.cpp +++ b/src/plugins/platforms/qnx/qqnxbuttoneventnotifier.cpp @@ -67,6 +67,7 @@ QQnxButtonEventNotifier::QQnxButtonEventNotifier(QObject *parent) // fetch the new button ids int enumeratorIndex = QQnxButtonEventNotifier::staticMetaObject.indexOfEnumerator(QByteArrayLiteral("ButtonId")); QMetaEnum enumerator = QQnxButtonEventNotifier::staticMetaObject.enumerator(enumeratorIndex); + m_buttonKeys.reserve(ButtonCount - bid_minus); for (int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) { m_buttonKeys.append(enumerator.valueToKey(buttonId)); m_state[buttonId] = ButtonUp; diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 3e9b0e1e4a..3643b3e975 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -210,6 +210,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, if (format == QLatin1String("text/uri-list")) { const auto urls = str.splitRef(QLatin1Char('\n')); QList list; + list.reserve(urls.size()); for (const QStringRef &s : urls) { const QUrl url(s.trimmed().toString()); if (url.isValid()) -- cgit v1.2.3 From 10b9321c1dc19236620ba20bdf54cae73891d1ef Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 19 Oct 2016 15:30:58 +0300 Subject: qxcbconnection.cpp: fix warning about unused function isXIEvent() is used iff XCB_USE_XINPUT2 is defined. So move declaration of the function in XCB_USE_XINPUT2 define scope. Change-Id: I6f045cd07d572ee7425ee6edc5ac73dcf0afdb37 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/plugins/platforms/xcb/qxcbconnection.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index c533a2a5f5..3d808d1d37 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -110,6 +110,7 @@ Q_LOGGING_CATEGORY(lcQpaScreen, "qt.qpa.screen") #define XCB_GE_GENERIC 35 #endif +#if defined(XCB_USE_XINPUT2) // Starting from the xcb version 1.9.3 struct xcb_ge_event_t has changed: // - "pad0" became "extension" // - "pad1" and "pad" became "pad0" @@ -127,6 +128,7 @@ static inline bool isXIEvent(xcb_generic_event_t *event, int opCode) qt_xcb_ge_event_t *e = (qt_xcb_ge_event_t *)event; return e->extension == opCode; } +#endif // XCB_USE_XINPUT2 #ifdef XCB_USE_XLIB static const char * const xcbConnectionErrors[] = { -- cgit v1.2.3 From 33aa2fdd08880d2d6e2a4ff658b34c3a81c0b4ea Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 19 Sep 2016 21:41:36 -0700 Subject: Fix change-of-sign warnings caught by ICC 17 error #68: integer conversion resulted in a change of sign Change-Id: I33dc971f005a4848bb8ffffd1475ee53d394acf6 Reviewed-by: Andrew Knight Reviewed-by: Laszlo Agocs --- .../deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp | 2 +- src/plugins/platforms/vnc/qvnc.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp index 55d5941e5f..1f672afeb4 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevicescreen.cpp @@ -88,7 +88,7 @@ void QEglFSKmsEglDeviceScreen::waitForFlip() qCDebug(qLcEglfsKmsDebug, "Setting mode"); int ret = drmModeSetCrtc(device()->fd(), output().crtc_id, - -1, 0, 0, + uint32_t(-1), 0, 0, &output().connector_id, 1, &output().modes[output().mode]); if (ret) diff --git a/src/plugins/platforms/vnc/qvnc.cpp b/src/plugins/platforms/vnc/qvnc.cpp index b3613cf18f..f386be193d 100644 --- a/src/plugins/platforms/vnc/qvnc.cpp +++ b/src/plugins/platforms/vnc/qvnc.cpp @@ -41,6 +41,7 @@ #include "qvncclient.h" #include "QtNetwork/qtcpserver.h" #include "QtNetwork/qtcpsocket.h" +#include #include #include @@ -554,7 +555,7 @@ void QVncClientCursor::write(QVncClient *client) const htons(cursor.height()) }; socket->write((char*)tmp, sizeof(tmp)); - const quint32 encoding = htonl(-239); + const qint32 encoding = qToBigEndian(-239); socket->write((char*)(&encoding), sizeof(encoding)); } -- cgit v1.2.3 From 391741bd7b9d07a6c3fd2e5c0bc70d3c00f29ac8 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 19 Oct 2016 17:50:52 +0200 Subject: Cocoa integration - remove erroneous warning The conditional statement checks/allows only right/left mouse buttons in handleMouseDraggedEvent and generates a lot of useless/misleading warnings in case we press (for example) a middle mouse button (when we're also moving mouse cursor, intentionally or not). Task-number: QTBUG-54160 Task-number: QTBUG-42846 Change-Id: I5c54b6204cb90036c7d98724537f1c985b40d9cc Reviewed-by: Shawn Rutledge --- src/plugins/platforms/cocoa/qnsview.mm | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 51a69be759..0e46c3150b 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -892,11 +892,6 @@ QT_WARNING_POP if (!(m_acceptedMouseDowns & button) == button) return false; - if (!(m_buttons & (m_sendUpAsRightButton ? Qt::RightButton : Qt::LeftButton))) { - qCWarning(lcQpaCocoaWindow) << "QNSView mouseDragged: Internal mouse button tracking" - << "invalid (missing Qt::LeftButton)"; - } - [self handleMouseEvent:theEvent]; return true; } -- cgit v1.2.3 From 9c83d7f871f95b1cc03fb404bd602df32056b9cb Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 30 Sep 2016 15:39:03 -0700 Subject: QCocoaMenuBar: Update even if no window is attached Then we need to check if the current active (or focused) window has any menubar associated. In case there isn't, and the menubar has no window associated, then we should update immediately. The previous condition is still valid. Change-Id: I4532ccc87354d91c76b53f5433dc3944b9e29584 Task-number: QTBUG-56275 Reviewed-by: Erik Verbruggen --- src/plugins/platforms/cocoa/qcocoamenubar.h | 1 + src/plugins/platforms/cocoa/qcocoamenubar.mm | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h index e84da7aeb0..2865dd2460 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.h +++ b/src/plugins/platforms/cocoa/qcocoamenubar.h @@ -70,6 +70,7 @@ private: static QCocoaWindow *findWindowForMenubar(); static QCocoaMenuBar *findGlobalMenubar(); + bool needsImmediateUpdate(); bool shouldDisable(QCocoaWindow *active) const; NSMenuItem *nativeItemForMenu(QCocoaMenu *menu) const; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 3523182e6d..82aebf8cf3 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -89,6 +89,32 @@ QCocoaMenuBar::~QCocoaMenuBar() } } +bool QCocoaMenuBar::needsImmediateUpdate() +{ + if (m_window && m_window->window()->isActive()) { + return true; + } else if (!m_window) { + // Only update if the focus/active window has no + // menubar, which means it'll be using this menubar. + // This is to avoid a modification in a parentless + // menubar to affect a window-assigned menubar. + QWindow *fw = QGuiApplication::focusWindow(); + if (!fw) { + // Same if there's no focus window, BTW. + return true; + } else { + QCocoaWindow *cw = static_cast(fw->handle()); + if (cw && !cw->menubar()) + return true; + } + } + + // Either the menubar is attached to a non-active window, + // or the application's focus window has its own menubar + // (which is different from this one) + return false; +} + void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *before) { QCocoaMenu *menu = static_cast(platformMenu); @@ -129,7 +155,7 @@ void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *befor syncMenu(menu); - if (m_window && m_window->window()->isActive()) + if (needsImmediateUpdate()) updateMenuBarImmediately(); } -- cgit v1.2.3 From 26ac91c832c2a8db1327e24e6ff88eef82cc4530 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 19 Oct 2016 12:59:18 +0300 Subject: qwindowsdirect2dintegration.cpp: replace QVector with QVarLengthArray QVector was used as just RAII for local array. It's inefficient usage of CoW type. So use QVarLengthArray instead. Change-Id: I494ecc49af9049569a65e258581137bad3ce7dc7 Reviewed-by: Edward Welbourne Reviewed-by: Marc Mutz --- src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp index 1d24247d75..da4a4e6ce6 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp @@ -52,6 +52,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QWindowsDirect2DEventDispatcher : public QWindowsGuiEventDispatcher @@ -106,7 +108,7 @@ public: if (_tcscat_s(filename, bufSize, __TEXT("\\d2d1.dll")) == 0) { DWORD versionInfoSize = GetFileVersionInfoSize(filename, NULL); if (versionInfoSize) { - QVector info(versionInfoSize); + QVarLengthArray info(versionInfoSize); if (GetFileVersionInfo(filename, NULL, versionInfoSize, info.data())) { UINT size; DWORD *fi; -- cgit v1.2.3 From c30e62c7750b804bfe6f3ed29914ebb42890230d Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 19 Oct 2016 14:27:51 +0300 Subject: Plugins: use const (and const APIs) more For CoW types, prefer const methods to avoid needless detach()ing. Change-Id: I625d57c0c19e87ac2de681bb16d0cc5a7a59b366 Reviewed-by: Edward Welbourne --- src/plugins/platforms/android/androidjnimain.cpp | 2 +- src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp | 2 +- .../eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp | 2 +- src/plugins/platforms/qnx/qqnxwindow.cpp | 2 +- src/plugins/platforms/xcb/qxcbmime.cpp | 2 +- src/plugins/platforms/xcb/qxcbsessionmanager.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index c79198d7fe..370c3426f5 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -514,7 +514,7 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para if (m_applicationParams.length()) { // Obtain a handle to the main library (the library that contains the main() function). // This library should already be loaded, and calling dlopen() will just return a reference to it. - m_mainLibraryHnd = dlopen(m_applicationParams.first().data(), 0); + m_mainLibraryHnd = dlopen(m_applicationParams.constFirst().data(), 0); if (Q_UNLIKELY(!m_mainLibraryHnd)) { qCritical() << "dlopen failed:" << dlerror(); return false; diff --git a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp index 48e0af5479..3e1e93f1e4 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp @@ -199,7 +199,7 @@ void QEglFSDeviceIntegration::screenDestroy() QEglFSIntegration *platformIntegration = static_cast( QGuiApplicationPrivate::platformIntegration()); while (!app->screens().isEmpty()) - platformIntegration->removeScreen(app->screens().last()->handle()); + platformIntegration->removeScreen(app->screens().constLast()->handle()); } QSizeF QEglFSDeviceIntegration::physicalScreenSize() const diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp index a78f445995..38419a55c8 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp @@ -126,7 +126,7 @@ QEglFSKmsDevice *QEglFSKmsGbmIntegration::createDevice(const QString &devicePath } else { QDeviceDiscovery *d = QDeviceDiscovery::create(QDeviceDiscovery::Device_VideoMask); - QStringList devices = d->scanConnectedDevices(); + const QStringList devices = d->scanConnectedDevices(); qCDebug(qLcEglfsKmsDebug) << "Found the following video devices:" << devices; d->deleteLater(); diff --git a/src/plugins/platforms/qnx/qqnxwindow.cpp b/src/plugins/platforms/qnx/qqnxwindow.cpp index 7b3a5ec70c..6fd0191e43 100644 --- a/src/plugins/platforms/qnx/qqnxwindow.cpp +++ b/src/plugins/platforms/qnx/qqnxwindow.cpp @@ -569,7 +569,7 @@ void QQnxWindow::requestActivateWindow() for (int i = 1; i < windowList.size(); ++i) windowList.at(i-1)->setFocus(windowList.at(i)->nativeHandle()); - windowList.last()->setFocus(windowList.last()->nativeHandle()); + windowList.last()->setFocus(windowList.constLast()->nativeHandle()); } screen_flush_context(m_screenContext, 0); diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 3643b3e975..7592eb2887 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -220,7 +220,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, // The atomName variable is not used because mimeAtomToString() // converts "text/x-moz-url" to "text/uri-list". if (!list.isEmpty() && connection->atomName(a) == "text/x-moz-url") - return list.first(); + return list.constFirst(); return list; } else { return str; diff --git a/src/plugins/platforms/xcb/qxcbsessionmanager.cpp b/src/plugins/platforms/xcb/qxcbsessionmanager.cpp index 8744fcba3e..2303ccf806 100644 --- a/src/plugins/platforms/xcb/qxcbsessionmanager.cpp +++ b/src/plugins/platforms/xcb/qxcbsessionmanager.cpp @@ -146,7 +146,7 @@ static void sm_setProperty(const QString &name, const QStringList &value) for (QStringList::ConstIterator it = value.begin(); it != value.end(); ++it) { prop[count].length = (*it).length(); vl.append((*it).toUtf8()); - prop[count].value = (char*)vl.last().data(); + prop[count].value = (char*)vl.constLast().data(); ++count; } sm_setProperty(name.toLatin1().data(), SmLISTofARRAY8, count, prop); -- cgit v1.2.3 From 99ce5d5e85007cb656cd48ab161be14af8f16238 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 28 Sep 2016 13:58:56 +0200 Subject: iOS: refactor usage of photos into optional plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting from iOS 10, apps that tries to access photos on the device need to specify the reason for this up front by adding the key 'NSPhotoLibraryUsageDescription' into Info.plist. If the key is missing, the app will be rejected from AppStore. This causes problems for the iOS plugin as it stands since parts of it already tries to access photos, e.g to show an image picker dialog if a file dialog is set to open QStandardPaths::PicturesLocation. This means that currently, all apps written with Qt will be rejected from AppStore unless the developer adds this key, whether he tries to access photos or not. To solve this, we choose to split the plugin into two parts, one that contains the core functionality, and one that contains optional support. The latter will need to be enabled explicit by the developer in the pro file, or in this case, indirectly by adding the right key to the Info.plist. This patch refactors the code in the plugin that gives access to photos into a separate optional plugin called 'nsphotolibrarysupport'. Change-Id: Ic4351eb0bbfffdf840fd88cd00bb29a25907798f Reviewed-by: Tor Arne Vestbø Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/ios.pro | 63 +-- src/plugins/platforms/ios/kernel.pro | 58 +++ .../nsphotolibrarysupport.pro | 22 + .../ios/optional/nsphotolibrarysupport/plugin.json | 3 + .../ios/optional/nsphotolibrarysupport/plugin.mm | 64 +++ .../qiosfileengineassetslibrary.h | 76 ++++ .../qiosfileengineassetslibrary.mm | 469 +++++++++++++++++++++ .../nsphotolibrarysupport/qiosfileenginefactory.h | 55 +++ .../qiosimagepickercontroller.h | 42 ++ .../qiosimagepickercontroller.mm | 66 +++ src/plugins/platforms/ios/optional/optional.pro | 2 + src/plugins/platforms/ios/qiosfiledialog.h | 2 + src/plugins/platforms/ios/qiosfiledialog.mm | 79 ++-- .../platforms/ios/qiosfileengineassetslibrary.h | 76 ---- .../platforms/ios/qiosfileengineassetslibrary.mm | 469 --------------------- src/plugins/platforms/ios/qiosfileenginefactory.h | 55 --- src/plugins/platforms/ios/qiosintegration.h | 7 +- src/plugins/platforms/ios/qiosintegration.mm | 8 + .../platforms/ios/qiosoptionalplugininterface.h | 59 +++ 19 files changed, 966 insertions(+), 709 deletions(-) create mode 100644 src/plugins/platforms/ios/kernel.pro create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm create mode 100644 src/plugins/platforms/ios/optional/optional.pro delete mode 100644 src/plugins/platforms/ios/qiosfileengineassetslibrary.h delete mode 100644 src/plugins/platforms/ios/qiosfileengineassetslibrary.mm delete mode 100644 src/plugins/platforms/ios/qiosfileenginefactory.h create mode 100644 src/plugins/platforms/ios/qiosoptionalplugininterface.h (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/ios.pro b/src/plugins/platforms/ios/ios.pro index 545db8c093..594ccefcf1 100644 --- a/src/plugins/platforms/ios/ios.pro +++ b/src/plugins/platforms/ios/ios.pro @@ -1,61 +1,2 @@ -TARGET = qios - -QT += core-private gui-private platformsupport-private -LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AssetsLibrary - -OBJECTIVE_SOURCES = \ - plugin.mm \ - qiosintegration.mm \ - qioseventdispatcher.mm \ - qioswindow.mm \ - qiosscreen.mm \ - qiosbackingstore.mm \ - qiosapplicationdelegate.mm \ - qiosapplicationstate.mm \ - qiosviewcontroller.mm \ - qioscontext.mm \ - qiosinputcontext.mm \ - qiostheme.mm \ - qiosglobal.mm \ - qiosservices.mm \ - quiview.mm \ - qiosclipboard.mm \ - quiaccessibilityelement.mm \ - qiosplatformaccessibility.mm \ - qiostextresponder.mm \ - qiosmenu.mm \ - qiosfileengineassetslibrary.mm \ - qiosfiledialog.mm - -HEADERS = \ - qiosintegration.h \ - qioseventdispatcher.h \ - qioswindow.h \ - qiosscreen.h \ - qiosbackingstore.h \ - qiosapplicationdelegate.h \ - qiosapplicationstate.h \ - qiosviewcontroller.h \ - qioscontext.h \ - qiosinputcontext.h \ - qiostheme.h \ - qiosglobal.h \ - qiosservices.h \ - quiview.h \ - qiosclipboard.h \ - quiaccessibilityelement.h \ - qiosplatformaccessibility.h \ - qiostextresponder.h \ - qiosmenu.h \ - qiosfileenginefactory.h \ - qiosfileengineassetslibrary.h \ - qiosfiledialog.h - -OTHER_FILES = \ - quiview_textinput.mm \ - quiview_accessibility.mm - -PLUGIN_TYPE = platforms -PLUGIN_CLASS_NAME = QIOSIntegrationPlugin -!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - -load(qt_plugin) +TEMPLATE = subdirs +SUBDIRS = kernel.pro optional diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro new file mode 100644 index 0000000000..84035877c5 --- /dev/null +++ b/src/plugins/platforms/ios/kernel.pro @@ -0,0 +1,58 @@ +TARGET = qios + +QT += core-private gui-private platformsupport-private +LIBS += -framework Foundation -framework UIKit -framework QuartzCore + +OBJECTIVE_SOURCES = \ + plugin.mm \ + qiosintegration.mm \ + qioseventdispatcher.mm \ + qioswindow.mm \ + qiosscreen.mm \ + qiosbackingstore.mm \ + qiosapplicationdelegate.mm \ + qiosapplicationstate.mm \ + qiosviewcontroller.mm \ + qioscontext.mm \ + qiosinputcontext.mm \ + qiostheme.mm \ + qiosglobal.mm \ + qiosservices.mm \ + quiview.mm \ + qiosclipboard.mm \ + quiaccessibilityelement.mm \ + qiosplatformaccessibility.mm \ + qiostextresponder.mm \ + qiosmenu.mm \ + qiosfiledialog.mm + +HEADERS = \ + qiosintegration.h \ + qioseventdispatcher.h \ + qioswindow.h \ + qiosscreen.h \ + qiosbackingstore.h \ + qiosapplicationdelegate.h \ + qiosapplicationstate.h \ + qiosviewcontroller.h \ + qioscontext.h \ + qiosinputcontext.h \ + qiostheme.h \ + qiosglobal.h \ + qiosservices.h \ + quiview.h \ + qiosclipboard.h \ + quiaccessibilityelement.h \ + qiosplatformaccessibility.h \ + qiostextresponder.h \ + qiosmenu.h \ + qiosfiledialog.h + +OTHER_FILES = \ + quiview_textinput.mm \ + quiview_accessibility.mm + +PLUGIN_TYPE = platforms +PLUGIN_CLASS_NAME = QIOSIntegrationPlugin +!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - +load(qt_plugin) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro new file mode 100644 index 0000000000..f4588dda03 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro @@ -0,0 +1,22 @@ +TARGET = qiosnsphotolibrarysupport + +QT += core gui gui-private +LIBS += -framework UIKit -framework AssetsLibrary + +HEADERS = \ + qiosfileengineassetslibrary.h \ + qiosfileenginefactory.h \ + qiosimagepickercontroller.h + +OBJECTIVE_SOURCES = \ + plugin.mm \ + qiosfileengineassetslibrary.mm \ + qiosimagepickercontroller.mm \ + +OTHER_FILES = \ + plugin.json + +PLUGIN_CLASS_NAME = QIosOptionalPlugin_NSPhotoLibrary +PLUGIN_EXTENDS = - +PLUGIN_TYPE = platforms/darwin +load(qt_plugin) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json new file mode 100644 index 0000000000..4491fb3d59 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "NSPhotoLibrarySupport" ] +} diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm new file mode 100644 index 0000000000..2ec0d33a41 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "../../qiosoptionalplugininterface.h" +#include "../../qiosfiledialog.h" + +#include "qiosimagepickercontroller.h" +#include "qiosfileenginefactory.h" + +QT_BEGIN_NAMESPACE + +class QIosOptionalPlugin_NSPhotoLibrary : public QObject, QIosOptionalPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QIosOptionalPluginInterface_iid FILE "plugin.json") + Q_INTERFACES(QIosOptionalPluginInterface) + +public: + explicit QIosOptionalPlugin_NSPhotoLibrary(QObject* = 0) {}; + ~QIosOptionalPlugin_NSPhotoLibrary() {} + + UIViewController* createImagePickerController(QIOSFileDialog *fileDialog) const override + { + return [[[QIOSImagePickerController alloc] initWithQIOSFileDialog:fileDialog] autorelease]; + } + +private: + QIOSFileEngineFactory m_fileEngineFactory; + +}; + +QT_END_NAMESPACE + +#include "plugin.moc" diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h new file mode 100644 index 0000000000..0e29a1003e --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIOSFILEENGINEASSETSLIBRARY_H +#define QIOSFILEENGINEASSETSLIBRARY_H + +#include + +Q_FORWARD_DECLARE_OBJC_CLASS(ALAsset); +class QIOSAssetData; + +class QIOSFileEngineAssetsLibrary : public QAbstractFileEngine +{ +public: + QIOSFileEngineAssetsLibrary(const QString &fileName); + ~QIOSFileEngineAssetsLibrary(); + + bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; + bool close() Q_DECL_OVERRIDE; + FileFlags fileFlags(FileFlags type) const Q_DECL_OVERRIDE; + qint64 size() const Q_DECL_OVERRIDE; + qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE; + qint64 pos() const Q_DECL_OVERRIDE; + bool seek(qint64 pos) Q_DECL_OVERRIDE; + QString fileName(FileName file) const Q_DECL_OVERRIDE; + void setFileName(const QString &file) Q_DECL_OVERRIDE; + QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const Q_DECL_OVERRIDE; + +#ifndef QT_NO_FILESYSTEMITERATOR + Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) Q_DECL_OVERRIDE; + Iterator *endEntryList() Q_DECL_OVERRIDE; +#endif + + void setError(QFile::FileError error, const QString &str) { QAbstractFileEngine::setError(error, str); } + +private: + QString m_fileName; + QString m_assetUrl; + qint64 m_offset; + mutable QIOSAssetData *m_data; + + ALAsset *loadAsset() const; +}; + +#endif // QIOSFILEENGINEASSETSLIBRARY_H + diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm new file mode 100644 index 0000000000..2e88c37c01 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm @@ -0,0 +1,469 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qiosfileengineassetslibrary.h" + +#import +#import + +#include +#include +#include +#include +#include + +static QThreadStorage g_iteratorCurrentUrl; +static QThreadStorage > g_assetDataCache; + +static const int kBufferSize = 10; +static ALAsset *kNoAsset = 0; + +static bool ensureAuthorizationDialogNotBlocked() +{ + if ([ALAssetsLibrary authorizationStatus] != ALAuthorizationStatusNotDetermined) + return true; + + if (static_cast(QObjectPrivate::get(qApp))->in_exec) + return true; + + if ([NSThread isMainThread]) { + // The dialog is about to show, but since main has not finished, the dialog will be held + // back until the launch completes. This is problematic since we cannot successfully return + // back to the caller before the asset is ready, which also includes showing the dialog. To + // work around this, we create an event loop to that will complete the launch (return from the + // applicationDidFinishLaunching callback). But this will only work if we're on the main thread. + QEventLoop loop; + QTimer::singleShot(1, &loop, &QEventLoop::quit); + loop.exec(); + } else { + NSLog(@"QIOSFileEngine: unable to show assets authorization dialog from non-gui thread before QApplication is executing."); + return false; + } + + return true; +} + +// ------------------------------------------------------------------------- + +class QIOSAssetEnumerator +{ +public: + QIOSAssetEnumerator(ALAssetsLibrary *assetsLibrary, ALAssetsGroupType type) + : m_semWriteAsset(dispatch_semaphore_create(kBufferSize)) + , m_semReadAsset(dispatch_semaphore_create(0)) + , m_stop(false) + , m_assetsLibrary([assetsLibrary retain]) + , m_type(type) + , m_buffer(QVector(kBufferSize)) + , m_readIndex(0) + , m_writeIndex(0) + , m_nextAssetReady(false) + { + if (!ensureAuthorizationDialogNotBlocked()) + writeAsset(kNoAsset); + else + startEnumerate(); + } + + ~QIOSAssetEnumerator() + { + m_stop = true; + + // Flush and autorelease remaining assets in the buffer + while (hasNext()) + next(); + + // Documentation states that we need to balance out calls to 'wait' + // and 'signal'. Since the enumeration function always will be one 'wait' + // ahead, we need to signal m_semProceedToNextAsset one last time. + dispatch_semaphore_signal(m_semWriteAsset); + dispatch_release(m_semReadAsset); + dispatch_release(m_semWriteAsset); + + [m_assetsLibrary autorelease]; + } + + bool hasNext() + { + if (!m_nextAssetReady) { + dispatch_semaphore_wait(m_semReadAsset, DISPATCH_TIME_FOREVER); + m_nextAssetReady = true; + } + return m_buffer[m_readIndex] != kNoAsset; + } + + ALAsset *next() + { + Q_ASSERT(m_nextAssetReady); + Q_ASSERT(m_buffer[m_readIndex]); + + ALAsset *asset = [m_buffer[m_readIndex] autorelease]; + dispatch_semaphore_signal(m_semWriteAsset); + + m_readIndex = (m_readIndex + 1) % kBufferSize; + m_nextAssetReady = false; + return asset; + } + +private: + dispatch_semaphore_t m_semWriteAsset; + dispatch_semaphore_t m_semReadAsset; + std::atomic_bool m_stop; + + ALAssetsLibrary *m_assetsLibrary; + ALAssetsGroupType m_type; + QVector m_buffer; + int m_readIndex; + int m_writeIndex; + bool m_nextAssetReady; + + void writeAsset(ALAsset *asset) + { + dispatch_semaphore_wait(m_semWriteAsset, DISPATCH_TIME_FOREVER); + m_buffer[m_writeIndex] = [asset retain]; + dispatch_semaphore_signal(m_semReadAsset); + m_writeIndex = (m_writeIndex + 1) % kBufferSize; + } + + void startEnumerate() + { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [m_assetsLibrary enumerateGroupsWithTypes:m_type usingBlock:^(ALAssetsGroup *group, BOOL *stopEnumerate) { + + if (!group) { + writeAsset(kNoAsset); + return; + } + + if (m_stop) { + *stopEnumerate = true; + return; + } + + [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stopEnumerate) { + Q_UNUSED(index); + if (!asset || ![[asset valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypePhoto]) + return; + + writeAsset(asset); + *stopEnumerate = m_stop; + }]; + } failureBlock:^(NSError *error) { + NSLog(@"QIOSFileEngine: %@", error); + writeAsset(kNoAsset); + }]; + }); + } + +}; + +// ------------------------------------------------------------------------- + +class QIOSAssetData : public QObject +{ +public: + QIOSAssetData(const QString &assetUrl, QIOSFileEngineAssetsLibrary *engine) + : m_asset(0) + , m_assetUrl(assetUrl) + , m_assetLibrary(0) + { + if (!ensureAuthorizationDialogNotBlocked()) + return; + + if (QIOSAssetData *assetData = g_assetDataCache.localData()) { + // It's a common pattern that QFiles pointing to the same path are created and destroyed + // several times during a single event loop cycle. To avoid loading the same asset + // over and over, we check if the last loaded asset has not been destroyed yet, and try to + // reuse its data. + if (assetData->m_assetUrl == assetUrl) { + m_assetLibrary = [assetData->m_assetLibrary retain]; + m_asset = [assetData->m_asset retain]; + return; + } + } + + // We can only load images from the asset library async. And this might take time, since it + // involves showing the authorization dialog. But the QFile API is synchronuous, so we need to + // wait until we have access to the data. [ALAssetLibrary assetForUrl:] will shedule a block on + // the current thread. But instead of spinning the event loop to force the block to execute, we + // wrap the call inside a synchronuous dispatch queue so that it executes on another thread. + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSURL *url = [NSURL URLWithString:assetUrl.toNSString()]; + m_assetLibrary = [[ALAssetsLibrary alloc] init]; + [m_assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) { + + if (!asset) { + // When an asset couldn't be loaded, chances are that it belongs to ALAssetsGroupPhotoStream. + // Such assets can be stored in the cloud and might need to be downloaded first. Unfortunately, + // forcing that to happen is hidden behind private APIs ([ALAsset requestDefaultRepresentation]). + // As a work-around, we search for it instead, since that will give us a pointer to the asset. + QIOSAssetEnumerator e(m_assetLibrary, ALAssetsGroupPhotoStream); + while (e.hasNext()) { + ALAsset *a = e.next(); + QString url = QUrl::fromNSURL([a valueForProperty:ALAssetPropertyAssetURL]).toString(); + if (url == assetUrl) { + asset = a; + break; + } + } + } + + if (!asset) + engine->setError(QFile::OpenError, QLatin1String("could not open image")); + + m_asset = [asset retain]; + dispatch_semaphore_signal(semaphore); + } failureBlock:^(NSError *error) { + engine->setError(QFile::OpenError, QString::fromNSString(error.localizedDescription)); + dispatch_semaphore_signal(semaphore); + }]; + }); + + dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); + dispatch_release(semaphore); + + g_assetDataCache.setLocalData(this); + } + + ~QIOSAssetData() + { + [m_assetLibrary release]; + [m_asset release]; + if (g_assetDataCache.localData() == this) + g_assetDataCache.setLocalData(0); + } + + ALAsset *m_asset; + +private: + QString m_assetUrl; + ALAssetsLibrary *m_assetLibrary; +}; + +// ------------------------------------------------------------------------- + +#ifndef QT_NO_FILESYSTEMITERATOR + +class QIOSFileEngineIteratorAssetsLibrary : public QAbstractFileEngineIterator +{ +public: + QIOSAssetEnumerator *m_enumerator; + + QIOSFileEngineIteratorAssetsLibrary( + QDir::Filters filters, const QStringList &nameFilters) + : QAbstractFileEngineIterator(filters, nameFilters) + , m_enumerator(new QIOSAssetEnumerator([[[ALAssetsLibrary alloc] init] autorelease], ALAssetsGroupAll)) + { + } + + ~QIOSFileEngineIteratorAssetsLibrary() + { + delete m_enumerator; + g_iteratorCurrentUrl.setLocalData(QString()); + } + + QString next() Q_DECL_OVERRIDE + { + // Cache the URL that we are about to return, since QDir will immediately create a + // new file engine on the file and ask if it exists. Unless we do this, we end up + // creating a new ALAsset just to verify its existence, which will be especially + // costly for assets belonging to ALAssetsGroupPhotoStream. + ALAsset *asset = m_enumerator->next(); + QString url = QUrl::fromNSURL([asset valueForProperty:ALAssetPropertyAssetURL]).toString(); + g_iteratorCurrentUrl.setLocalData(url); + return url; + } + + bool hasNext() const Q_DECL_OVERRIDE + { + return m_enumerator->hasNext(); + } + + QString currentFileName() const Q_DECL_OVERRIDE + { + return g_iteratorCurrentUrl.localData(); + } + + QFileInfo currentFileInfo() const Q_DECL_OVERRIDE + { + return QFileInfo(currentFileName()); + } +}; + +#endif + +// ------------------------------------------------------------------------- + +QIOSFileEngineAssetsLibrary::QIOSFileEngineAssetsLibrary(const QString &fileName) + : m_offset(0) + , m_data(0) +{ + setFileName(fileName); +} + +QIOSFileEngineAssetsLibrary::~QIOSFileEngineAssetsLibrary() +{ + close(); +} + +ALAsset *QIOSFileEngineAssetsLibrary::loadAsset() const +{ + if (!m_data) + m_data = new QIOSAssetData(m_assetUrl, const_cast(this)); + return m_data->m_asset; +} + +bool QIOSFileEngineAssetsLibrary::open(QIODevice::OpenMode openMode) +{ + if (openMode & (QIODevice::WriteOnly | QIODevice::Text)) + return false; + return loadAsset(); +} + +bool QIOSFileEngineAssetsLibrary::close() +{ + if (m_data) { + // Delete later, so that we can reuse the asset if a QFile is + // opened with the same path during the same event loop cycle. + m_data->deleteLater(); + m_data = 0; + } + return true; +} + +QAbstractFileEngine::FileFlags QIOSFileEngineAssetsLibrary::fileFlags(QAbstractFileEngine::FileFlags type) const +{ + QAbstractFileEngine::FileFlags flags = 0; + const bool isDir = (m_assetUrl == QLatin1String("assets-library://")); + const bool exists = isDir || m_assetUrl == g_iteratorCurrentUrl.localData() || loadAsset(); + + if (!exists) + return flags; + + if (type & FlagsMask) + flags |= ExistsFlag; + if (type & PermsMask) { + ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus]; + if (status != ALAuthorizationStatusRestricted && status != ALAuthorizationStatusDenied) + flags |= ReadOwnerPerm | ReadUserPerm | ReadGroupPerm | ReadOtherPerm; + } + if (type & TypesMask) + flags |= isDir ? DirectoryType : FileType; + + return flags; +} + +qint64 QIOSFileEngineAssetsLibrary::size() const +{ + if (ALAsset *asset = loadAsset()) + return [[asset defaultRepresentation] size]; + return 0; +} + +qint64 QIOSFileEngineAssetsLibrary::read(char *data, qint64 maxlen) +{ + ALAsset *asset = loadAsset(); + if (!asset) + return -1; + + qint64 bytesRead = qMin(maxlen, size() - m_offset); + if (!bytesRead) + return 0; + + NSError *error = 0; + [[asset defaultRepresentation] getBytes:(uint8_t *)data fromOffset:m_offset length:bytesRead error:&error]; + + if (error) { + setError(QFile::ReadError, QString::fromNSString(error.localizedDescription)); + return -1; + } + + m_offset += bytesRead; + return bytesRead; +} + +qint64 QIOSFileEngineAssetsLibrary::pos() const +{ + return m_offset; +} + +bool QIOSFileEngineAssetsLibrary::seek(qint64 pos) +{ + if (pos >= size()) + return false; + m_offset = pos; + return true; +} + +QString QIOSFileEngineAssetsLibrary::fileName(FileName file) const +{ + Q_UNUSED(file); + return m_fileName; +} + +void QIOSFileEngineAssetsLibrary::setFileName(const QString &file) +{ + if (m_data) + close(); + m_fileName = file; + // QUrl::fromLocalFile() will remove double slashes. Since the asset url is + // passed around as a file name in the app (and converted to/from a file url, e.g + // in QFileDialog), we need to ensure that m_assetUrl ends up being valid. + int index = file.indexOf(QLatin1String("/asset")); + if (index == -1) + m_assetUrl = QLatin1String("assets-library://"); + else + m_assetUrl = QLatin1String("assets-library:/") + file.mid(index); +} + +QStringList QIOSFileEngineAssetsLibrary::entryList(QDir::Filters filters, const QStringList &filterNames) const +{ + return QAbstractFileEngine::entryList(filters, filterNames); +} + +#ifndef QT_NO_FILESYSTEMITERATOR + +QAbstractFileEngine::Iterator *QIOSFileEngineAssetsLibrary::beginEntryList( + QDir::Filters filters, const QStringList &filterNames) +{ + return new QIOSFileEngineIteratorAssetsLibrary(filters, filterNames); +} + +QAbstractFileEngine::Iterator *QIOSFileEngineAssetsLibrary::endEntryList() +{ + return 0; +} + +#endif diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h new file mode 100644 index 0000000000..29f543caae --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIOSFILEENGINEFACTORY_H +#define QIOSFILEENGINEFACTORY_H + +#include +#include +#include "qiosfileengineassetslibrary.h" + +class QIOSFileEngineFactory : public QAbstractFileEngineHandler +{ +public: + QAbstractFileEngine* create(const QString &fileName) const + { + static QLatin1String assetsScheme("assets-library:"); + + if (fileName.toLower().startsWith(assetsScheme)) + return new QIOSFileEngineAssetsLibrary(fileName); + + return 0; + } +}; + +#endif // QIOSFILEENGINEFACTORY_H diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h new file mode 100644 index 0000000000..df3f6b9fa3 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import + +#include "../../qiosfiledialog.h" + +@interface QIOSImagePickerController : UIImagePickerController { + QIOSFileDialog *m_fileDialog; +} +- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog; +@end diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm new file mode 100644 index 0000000000..f9662b964a --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import + +#include "qiosimagepickercontroller.h" + +@implementation QIOSImagePickerController + +- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog +{ + self = [super init]; + if (self) { + m_fileDialog = fileDialog; + [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; + [self setDelegate:self]; + } + return self; +} + +- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info +{ + Q_UNUSED(picker); + NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL]; + QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description])); + m_fileDialog->selectedFilesChanged(QList() << fileUrl); + emit m_fileDialog->accept(); +} + +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker +{ + Q_UNUSED(picker) + emit m_fileDialog->reject(); +} + +@end diff --git a/src/plugins/platforms/ios/optional/optional.pro b/src/plugins/platforms/ios/optional/optional.pro new file mode 100644 index 0000000000..5e3421a025 --- /dev/null +++ b/src/plugins/platforms/ios/optional/optional.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = nsphotolibrarysupport diff --git a/src/plugins/platforms/ios/qiosfiledialog.h b/src/plugins/platforms/ios/qiosfiledialog.h index b4bf85edd9..668cf18caf 100644 --- a/src/plugins/platforms/ios/qiosfiledialog.h +++ b/src/plugins/platforms/ios/qiosfiledialog.h @@ -66,6 +66,8 @@ private: QList m_selection; QEventLoop m_eventLoop; UIViewController *m_viewController; + + bool showImagePickerDialog(QWindow *parent); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosfiledialog.mm b/src/plugins/platforms/ios/qiosfiledialog.mm index 7c32784e9d..a70eb11ef8 100644 --- a/src/plugins/platforms/ios/qiosfiledialog.mm +++ b/src/plugins/platforms/ios/qiosfiledialog.mm @@ -31,52 +31,18 @@ ** ****************************************************************************/ -#include "qiosfiledialog.h" - #import #include #include +#include -@interface QIOSImagePickerController : UIImagePickerController { - QIOSFileDialog *m_fileDialog; -} -@end - -@implementation QIOSImagePickerController - -- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog -{ - self = [super init]; - if (self) { - m_fileDialog = fileDialog; - [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; - [self setDelegate:self]; - } - return self; -} - -- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info -{ - Q_UNUSED(picker); - NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL]; - QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description])); - m_fileDialog->selectedFilesChanged(QList() << fileUrl); - emit m_fileDialog->accept(); -} - -- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker -{ - Q_UNUSED(picker) - emit m_fileDialog->reject(); -} - -@end - -// -------------------------------------------------------------------------- +#include "qiosfiledialog.h" +#include "qiosintegration.h" +#include "qiosoptionalplugininterface.h" QIOSFileDialog::QIOSFileDialog() - : m_viewController(0) + : m_viewController(Q_NULLPTR) { } @@ -98,17 +64,36 @@ bool QIOSFileDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality window bool acceptOpen = options()->acceptMode() == QFileDialogOptions::AcceptOpen; QString directory = options()->initialDirectory().toLocalFile(); - if (acceptOpen && directory.startsWith(QLatin1String("assets-library:"))) { - m_viewController = [[QIOSImagePickerController alloc] initWithQIOSFileDialog:this]; - UIWindow *window = parent ? reinterpret_cast(parent->winId()).window - : [UIApplication sharedApplication].keyWindow; - [window.rootViewController presentViewController:m_viewController animated:YES completion:nil]; - return true; - } + if (acceptOpen && directory.startsWith(QLatin1String("assets-library:"))) + return showImagePickerDialog(parent); return false; } +bool QIOSFileDialog::showImagePickerDialog(QWindow *parent) +{ + if (!m_viewController) { + QFactoryLoader *plugins = QIOSIntegration::instance()->optionalPlugins(); + for (int i = 0; i < plugins->metaData().size(); ++i) { + QIosOptionalPluginInterface *plugin = qobject_cast(plugins->instance(i)); + m_viewController = [plugin->createImagePickerController(this) retain]; + if (m_viewController) + break; + } + } + + if (!m_viewController) { + qWarning() << "QIOSFileDialog: Could not resolve Qt plugin that gives access to photos on iOS"; + return false; + } + + UIWindow *window = parent ? reinterpret_cast(parent->winId()).window + : [UIApplication sharedApplication].keyWindow; + [window.rootViewController presentViewController:m_viewController animated:YES completion:nil]; + + return true; +} + void QIOSFileDialog::hide() { // QFileDialog will remember the last directory set, and open subsequent dialogs in the same @@ -120,6 +105,8 @@ void QIOSFileDialog::hide() emit directoryEntered(QUrl::fromLocalFile(QDir::currentPath())); [m_viewController dismissViewControllerAnimated:YES completion:nil]; + [m_viewController release]; + m_viewController = Q_NULLPTR; m_eventLoop.exit(); } diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/qiosfileengineassetslibrary.h deleted file mode 100644 index 37bbc7bf23..0000000000 --- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QIOSFILEENGINEASSETSLIBRARY_H -#define QIOSFILEENGINEASSETSLIBRARY_H - -#include - -Q_FORWARD_DECLARE_OBJC_CLASS(ALAsset); -class QIOSAssetData; - -class QIOSFileEngineAssetsLibrary : public QAbstractFileEngine -{ -public: - QIOSFileEngineAssetsLibrary(const QString &fileName); - ~QIOSFileEngineAssetsLibrary(); - - bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; - bool close() Q_DECL_OVERRIDE; - FileFlags fileFlags(FileFlags type) const Q_DECL_OVERRIDE; - qint64 size() const Q_DECL_OVERRIDE; - qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE; - qint64 pos() const Q_DECL_OVERRIDE; - bool seek(qint64 pos) Q_DECL_OVERRIDE; - QString fileName(FileName file) const Q_DECL_OVERRIDE; - void setFileName(const QString &file) Q_DECL_OVERRIDE; - QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const Q_DECL_OVERRIDE; - -#ifndef QT_NO_FILESYSTEMITERATOR - Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) Q_DECL_OVERRIDE; - Iterator *endEntryList() Q_DECL_OVERRIDE; -#endif - - void setError(QFile::FileError error, const QString &str) { QAbstractFileEngine::setError(error, str); } - -private: - QString m_fileName; - QString m_assetUrl; - qint64 m_offset; - mutable QIOSAssetData *m_data; - - ALAsset *loadAsset() const; -}; - -#endif // QIOSFILEENGINEASSETSLIBRARY_H - diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm deleted file mode 100644 index bb12c164d6..0000000000 --- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm +++ /dev/null @@ -1,469 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qiosfileengineassetslibrary.h" - -#import -#import - -#include -#include -#include -#include -#include - -static QThreadStorage g_iteratorCurrentUrl; -static QThreadStorage > g_assetDataCache; - -static const int kBufferSize = 10; -static ALAsset *kNoAsset = 0; - -static bool ensureAuthorizationDialogNotBlocked() -{ - if ([ALAssetsLibrary authorizationStatus] != ALAuthorizationStatusNotDetermined) - return true; - - if (static_cast(QObjectPrivate::get(qApp))->in_exec) - return true; - - if ([NSThread isMainThread]) { - // The dialog is about to show, but since main has not finished, the dialog will be held - // back until the launch completes. This is problematic since we cannot successfully return - // back to the caller before the asset is ready, which also includes showing the dialog. To - // work around this, we create an event loop to that will complete the launch (return from the - // applicationDidFinishLaunching callback). But this will only work if we're on the main thread. - QEventLoop loop; - QTimer::singleShot(1, &loop, &QEventLoop::quit); - loop.exec(); - } else { - NSLog(@"QIOSFileEngine: unable to show assets authorization dialog from non-gui thread before QApplication is executing."); - return false; - } - - return true; -} - -// ------------------------------------------------------------------------- - -class QIOSAssetEnumerator -{ -public: - QIOSAssetEnumerator(ALAssetsLibrary *assetsLibrary, ALAssetsGroupType type) - : m_semWriteAsset(dispatch_semaphore_create(kBufferSize)) - , m_semReadAsset(dispatch_semaphore_create(0)) - , m_stop(false) - , m_assetsLibrary([assetsLibrary retain]) - , m_type(type) - , m_buffer(QVector(kBufferSize)) - , m_readIndex(0) - , m_writeIndex(0) - , m_nextAssetReady(false) - { - if (!ensureAuthorizationDialogNotBlocked()) - writeAsset(kNoAsset); - else - startEnumerate(); - } - - ~QIOSAssetEnumerator() - { - m_stop = true; - - // Flush and autorelease remaining assets in the buffer - while (hasNext()) - next(); - - // Documentation states that we need to balance out calls to 'wait' - // and 'signal'. Since the enumeration function always will be one 'wait' - // ahead, we need to signal m_semProceedToNextAsset one last time. - dispatch_semaphore_signal(m_semWriteAsset); - dispatch_release(m_semReadAsset); - dispatch_release(m_semWriteAsset); - - [m_assetsLibrary autorelease]; - } - - bool hasNext() - { - if (!m_nextAssetReady) { - dispatch_semaphore_wait(m_semReadAsset, DISPATCH_TIME_FOREVER); - m_nextAssetReady = true; - } - return m_buffer[m_readIndex] != kNoAsset; - } - - ALAsset *next() - { - Q_ASSERT(m_nextAssetReady); - Q_ASSERT(m_buffer[m_readIndex]); - - ALAsset *asset = [m_buffer[m_readIndex] autorelease]; - dispatch_semaphore_signal(m_semWriteAsset); - - m_readIndex = (m_readIndex + 1) % kBufferSize; - m_nextAssetReady = false; - return asset; - } - -private: - dispatch_semaphore_t m_semWriteAsset; - dispatch_semaphore_t m_semReadAsset; - std::atomic_bool m_stop; - - ALAssetsLibrary *m_assetsLibrary; - ALAssetsGroupType m_type; - QVector m_buffer; - int m_readIndex; - int m_writeIndex; - bool m_nextAssetReady; - - void writeAsset(ALAsset *asset) - { - dispatch_semaphore_wait(m_semWriteAsset, DISPATCH_TIME_FOREVER); - m_buffer[m_writeIndex] = [asset retain]; - dispatch_semaphore_signal(m_semReadAsset); - m_writeIndex = (m_writeIndex + 1) % kBufferSize; - } - - void startEnumerate() - { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [m_assetsLibrary enumerateGroupsWithTypes:m_type usingBlock:^(ALAssetsGroup *group, BOOL *stopEnumerate) { - - if (!group) { - writeAsset(kNoAsset); - return; - } - - if (m_stop) { - *stopEnumerate = true; - return; - } - - [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stopEnumerate) { - Q_UNUSED(index); - if (!asset || ![[asset valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypePhoto]) - return; - - writeAsset(asset); - *stopEnumerate = m_stop; - }]; - } failureBlock:^(NSError *error) { - NSLog(@"QIOSFileEngine: %@", error); - writeAsset(kNoAsset); - }]; - }); - } - -}; - -// ------------------------------------------------------------------------- - -class QIOSAssetData : public QObject -{ -public: - QIOSAssetData(const QString &assetUrl, QIOSFileEngineAssetsLibrary *engine) - : m_asset(0) - , m_assetUrl(assetUrl) - , m_assetLibrary(0) - { - if (!ensureAuthorizationDialogNotBlocked()) - return; - - if (QIOSAssetData *assetData = g_assetDataCache.localData()) { - // It's a common pattern that QFiles pointing to the same path are created and destroyed - // several times during a single event loop cycle. To avoid loading the same asset - // over and over, we check if the last loaded asset has not been destroyed yet, and try to - // reuse its data. - if (assetData->m_assetUrl == assetUrl) { - m_assetLibrary = [assetData->m_assetLibrary retain]; - m_asset = [assetData->m_asset retain]; - return; - } - } - - // We can only load images from the asset library async. And this might take time, since it - // involves showing the authorization dialog. But the QFile API is synchronuous, so we need to - // wait until we have access to the data. [ALAssetLibrary assetForUrl:] will shedule a block on - // the current thread. But instead of spinning the event loop to force the block to execute, we - // wrap the call inside a synchronuous dispatch queue so that it executes on another thread. - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSURL *url = [NSURL URLWithString:assetUrl.toNSString()]; - m_assetLibrary = [[ALAssetsLibrary alloc] init]; - [m_assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) { - - if (!asset) { - // When an asset couldn't be loaded, chances are that it belongs to ALAssetsGroupPhotoStream. - // Such assets can be stored in the cloud and might need to be downloaded first. Unfortunately, - // forcing that to happen is hidden behind private APIs ([ALAsset requestDefaultRepresentation]). - // As a work-around, we search for it instead, since that will give us a pointer to the asset. - QIOSAssetEnumerator e(m_assetLibrary, ALAssetsGroupPhotoStream); - while (e.hasNext()) { - ALAsset *a = e.next(); - QString url = QUrl::fromNSURL([a valueForProperty:ALAssetPropertyAssetURL]).toString(); - if (url == assetUrl) { - asset = a; - break; - } - } - } - - if (!asset) - engine->setError(QFile::OpenError, QLatin1String("could not open image")); - - m_asset = [asset retain]; - dispatch_semaphore_signal(semaphore); - } failureBlock:^(NSError *error) { - engine->setError(QFile::OpenError, QString::fromNSString(error.localizedDescription)); - dispatch_semaphore_signal(semaphore); - }]; - }); - - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - dispatch_release(semaphore); - - g_assetDataCache.setLocalData(this); - } - - ~QIOSAssetData() - { - [m_assetLibrary release]; - [m_asset release]; - if (g_assetDataCache.localData() == this) - g_assetDataCache.setLocalData(0); - } - - ALAsset *m_asset; - -private: - QString m_assetUrl; - ALAssetsLibrary *m_assetLibrary; -}; - -// ------------------------------------------------------------------------- - -#ifndef QT_NO_FILESYSTEMITERATOR - -class QIOSFileEngineIteratorAssetsLibrary : public QAbstractFileEngineIterator -{ -public: - QIOSAssetEnumerator *m_enumerator; - - QIOSFileEngineIteratorAssetsLibrary( - QDir::Filters filters, const QStringList &nameFilters) - : QAbstractFileEngineIterator(filters, nameFilters) - , m_enumerator(new QIOSAssetEnumerator([[[ALAssetsLibrary alloc] init] autorelease], ALAssetsGroupAll)) - { - } - - ~QIOSFileEngineIteratorAssetsLibrary() - { - delete m_enumerator; - g_iteratorCurrentUrl.setLocalData(QString()); - } - - QString next() Q_DECL_OVERRIDE - { - // Cache the URL that we are about to return, since QDir will immediately create a - // new file engine on the file and ask if it exists. Unless we do this, we end up - // creating a new ALAsset just to verify its existence, which will be especially - // costly for assets belonging to ALAssetsGroupPhotoStream. - ALAsset *asset = m_enumerator->next(); - QString url = QUrl::fromNSURL([asset valueForProperty:ALAssetPropertyAssetURL]).toString(); - g_iteratorCurrentUrl.setLocalData(url); - return url; - } - - bool hasNext() const Q_DECL_OVERRIDE - { - return m_enumerator->hasNext(); - } - - QString currentFileName() const Q_DECL_OVERRIDE - { - return g_iteratorCurrentUrl.localData(); - } - - QFileInfo currentFileInfo() const Q_DECL_OVERRIDE - { - return QFileInfo(currentFileName()); - } -}; - -#endif - -// ------------------------------------------------------------------------- - -QIOSFileEngineAssetsLibrary::QIOSFileEngineAssetsLibrary(const QString &fileName) - : m_offset(0) - , m_data(0) -{ - setFileName(fileName); -} - -QIOSFileEngineAssetsLibrary::~QIOSFileEngineAssetsLibrary() -{ - close(); -} - -ALAsset *QIOSFileEngineAssetsLibrary::loadAsset() const -{ - if (!m_data) - m_data = new QIOSAssetData(m_assetUrl, const_cast(this)); - return m_data->m_asset; -} - -bool QIOSFileEngineAssetsLibrary::open(QIODevice::OpenMode openMode) -{ - if (openMode & (QIODevice::WriteOnly | QIODevice::Text)) - return false; - return loadAsset(); -} - -bool QIOSFileEngineAssetsLibrary::close() -{ - if (m_data) { - // Delete later, so that we can reuse the asset if a QFile is - // opened with the same path during the same event loop cycle. - m_data->deleteLater(); - m_data = 0; - } - return true; -} - -QAbstractFileEngine::FileFlags QIOSFileEngineAssetsLibrary::fileFlags(QAbstractFileEngine::FileFlags type) const -{ - QAbstractFileEngine::FileFlags flags = 0; - const bool isDir = (m_assetUrl == QLatin1String("assets-library://")); - const bool exists = isDir || m_assetUrl == g_iteratorCurrentUrl.localData() || loadAsset(); - - if (!exists) - return flags; - - if (type & FlagsMask) - flags |= ExistsFlag; - if (type & PermsMask) { - ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus]; - if (status != ALAuthorizationStatusRestricted && status != ALAuthorizationStatusDenied) - flags |= ReadOwnerPerm | ReadUserPerm | ReadGroupPerm | ReadOtherPerm; - } - if (type & TypesMask) - flags |= isDir ? DirectoryType : FileType; - - return flags; -} - -qint64 QIOSFileEngineAssetsLibrary::size() const -{ - if (ALAsset *asset = loadAsset()) - return [[asset defaultRepresentation] size]; - return 0; -} - -qint64 QIOSFileEngineAssetsLibrary::read(char *data, qint64 maxlen) -{ - ALAsset *asset = loadAsset(); - if (!asset) - return -1; - - qint64 bytesRead = qMin(maxlen, size() - m_offset); - if (!bytesRead) - return 0; - - NSError *error = 0; - [[asset defaultRepresentation] getBytes:(uint8_t *)data fromOffset:m_offset length:bytesRead error:&error]; - - if (error) { - setError(QFile::ReadError, QString::fromNSString(error.localizedDescription)); - return -1; - } - - m_offset += bytesRead; - return bytesRead; -} - -qint64 QIOSFileEngineAssetsLibrary::pos() const -{ - return m_offset; -} - -bool QIOSFileEngineAssetsLibrary::seek(qint64 pos) -{ - if (pos >= size()) - return false; - m_offset = pos; - return true; -} - -QString QIOSFileEngineAssetsLibrary::fileName(FileName file) const -{ - Q_UNUSED(file); - return m_fileName; -} - -void QIOSFileEngineAssetsLibrary::setFileName(const QString &file) -{ - if (m_data) - close(); - m_fileName = file; - // QUrl::fromLocalFile() will remove double slashes. Since the asset url is - // passed around as a file name in the app (and converted to/from a file url, e.g - // in QFileDialog), we need to ensure that m_assetUrl ends up being valid. - int index = file.indexOf(QLatin1String("/asset")); - if (index == -1) - m_assetUrl = QLatin1String("assets-library://"); - else - m_assetUrl = QLatin1String("assets-library:/") + file.mid(index); -} - -QStringList QIOSFileEngineAssetsLibrary::entryList(QDir::Filters filters, const QStringList &filterNames) const -{ - return QAbstractFileEngine::entryList(filters, filterNames); -} - -#ifndef QT_NO_FILESYSTEMITERATOR - -QAbstractFileEngine::Iterator *QIOSFileEngineAssetsLibrary::beginEntryList( - QDir::Filters filters, const QStringList &filterNames) -{ - return new QIOSFileEngineIteratorAssetsLibrary(filters, filterNames); -} - -QAbstractFileEngine::Iterator *QIOSFileEngineAssetsLibrary::endEntryList() -{ - return 0; -} - -#endif diff --git a/src/plugins/platforms/ios/qiosfileenginefactory.h b/src/plugins/platforms/ios/qiosfileenginefactory.h deleted file mode 100644 index a8604c77d1..0000000000 --- a/src/plugins/platforms/ios/qiosfileenginefactory.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QIOSFILEENGINEFACTORY_H -#define QIOSFILEENGINEFACTORY_H - -#include -#include -#include "qiosfileengineassetslibrary.h" - -class QIOSFileEngineFactory : public QAbstractFileEngineHandler -{ -public: - QAbstractFileEngine* create(const QString &fileName) const - { - static QLatin1String assetsScheme("assets-library:"); - - if (fileName.toLower().startsWith(assetsScheme)) - return new QIOSFileEngineAssetsLibrary(fileName); - - return 0; - } -}; - -#endif // QIOSFILEENGINEFACTORY_H diff --git a/src/plugins/platforms/ios/qiosintegration.h b/src/plugins/platforms/ios/qiosintegration.h index 7d23fe1d62..25eb8990cb 100644 --- a/src/plugins/platforms/ios/qiosintegration.h +++ b/src/plugins/platforms/ios/qiosintegration.h @@ -38,8 +38,9 @@ #include #include +#include + #include "qiosapplicationstate.h" -#include "qiosfileenginefactory.h" QT_BEGIN_NAMESPACE @@ -91,6 +92,8 @@ public: void setDebugWindowManagement(bool); bool debugWindowManagement() const; + QFactoryLoader *optionalPlugins() { return m_optionalPlugins; } + private: QPlatformFontDatabase *m_fontDatabase; QPlatformClipboard *m_clipboard; @@ -99,7 +102,7 @@ private: QIOSApplicationState m_applicationState; QIOSServices *m_platformServices; mutable QPlatformAccessibility *m_accessibility; - QIOSFileEngineFactory m_fileEngineFactory; + QFactoryLoader *m_optionalPlugins; bool m_debugWindowManagement; }; diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 85b5c477cc..d33c8cf47c 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -43,6 +43,7 @@ #include "qiosinputcontext.h" #include "qiostheme.h" #include "qiosservices.h" +#include "qiosoptionalplugininterface.h" #include @@ -68,6 +69,7 @@ QIOSIntegration::QIOSIntegration() , m_inputContext(0) , m_platformServices(new QIOSServices) , m_accessibility(0) + , m_optionalPlugins(new QFactoryLoader(QIosOptionalPluginInterface_iid, QLatin1String("/platforms/darwin"))) , m_debugWindowManagement(false) { if (![UIApplication sharedApplication]) { @@ -112,6 +114,9 @@ QIOSIntegration::QIOSIntegration() m_touchDevice->setCapabilities(touchCapabilities); QWindowSystemInterface::registerTouchDevice(m_touchDevice); QMacInternalPasteboardMime::initializeMimeTypes(); + + for (int i = 0; i < m_optionalPlugins->metaData().size(); ++i) + qobject_cast(m_optionalPlugins->instance(i))->initPlugin(); } QIOSIntegration::~QIOSIntegration() @@ -134,6 +139,9 @@ QIOSIntegration::~QIOSIntegration() delete m_accessibility; m_accessibility = 0; + + delete m_optionalPlugins; + m_optionalPlugins = 0; } bool QIOSIntegration::hasCapability(Capability cap) const diff --git a/src/plugins/platforms/ios/qiosoptionalplugininterface.h b/src/plugins/platforms/ios/qiosoptionalplugininterface.h new file mode 100644 index 0000000000..bcb8978e02 --- /dev/null +++ b/src/plugins/platforms/ios/qiosoptionalplugininterface.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIOPLUGININTERFACE_H +#define QIOPLUGININTERFACE_H + +#include + +#include "qiosfiledialog.h" + +QT_BEGIN_NAMESPACE + +Q_FORWARD_DECLARE_OBJC_CLASS(UIViewController); + +#define QIosOptionalPluginInterface_iid "org.qt-project.Qt.QPA.ios.optional" + +class QIosOptionalPluginInterface +{ +public: + virtual ~QIosOptionalPluginInterface() {} + virtual void initPlugin() const {}; + virtual UIViewController* createImagePickerController(QIOSFileDialog *) const { return Q_NULLPTR; }; +}; + +Q_DECLARE_INTERFACE(QIosOptionalPluginInterface, QIosOptionalPluginInterface_iid) + +QT_END_NAMESPACE + +#endif // QIOPLUGININTERFACE_H -- cgit v1.2.3 From b9af823ef7a4131bc61b07620e7825d757df69db Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 18 Oct 2016 13:09:37 +0200 Subject: qiosfileengineassetslibrary: replace Q_DECL_OVERRIDE with override Change-Id: Iba67e1a1fa86dff3c82543597351b597be69ed1f Reviewed-by: Jake Petroules --- .../qiosfileengineassetslibrary.h | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h index 0e29a1003e..89696751c6 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h @@ -45,20 +45,20 @@ public: QIOSFileEngineAssetsLibrary(const QString &fileName); ~QIOSFileEngineAssetsLibrary(); - bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; - bool close() Q_DECL_OVERRIDE; - FileFlags fileFlags(FileFlags type) const Q_DECL_OVERRIDE; - qint64 size() const Q_DECL_OVERRIDE; - qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE; - qint64 pos() const Q_DECL_OVERRIDE; - bool seek(qint64 pos) Q_DECL_OVERRIDE; - QString fileName(FileName file) const Q_DECL_OVERRIDE; - void setFileName(const QString &file) Q_DECL_OVERRIDE; - QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const Q_DECL_OVERRIDE; + bool open(QIODevice::OpenMode openMode) override; + bool close() override; + FileFlags fileFlags(FileFlags type) const override; + qint64 size() const override; + qint64 read(char *data, qint64 maxlen) override; + qint64 pos() const override; + bool seek(qint64 pos) override; + QString fileName(FileName file) const override; + void setFileName(const QString &file) override; + QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override; #ifndef QT_NO_FILESYSTEMITERATOR - Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) Q_DECL_OVERRIDE; - Iterator *endEntryList() Q_DECL_OVERRIDE; + Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; + Iterator *endEntryList() override; #endif void setError(QFile::FileError error, const QString &str) { QAbstractFileEngine::setError(error, str); } -- cgit v1.2.3 From 04f0a69e96fca03c18e0c7eaaab7babc49e35198 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 25 Oct 2016 15:22:01 +0200 Subject: Replace PKGCONFIG+=foo usages with QMAKE_USE replace explicit pkg-config uses with the results of configure tests, for consistency. Change-Id: I3587db6085798ea7a49f8871fc6838eb687a6391 Reviewed-by: Oswald Buddenhagen --- .../platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro | 3 +-- src/plugins/platforms/mirclient/mirclient.pro | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro index f934fd85ed..065a103376 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro @@ -14,8 +14,7 @@ HEADERS += $$PWD/qeglfsvivwlintegration.h OTHER_FILES += $$PWD/eglfs_viv_wl.json -CONFIG += link_pkgconfig -PKGCONFIG_PRIVATE += wayland-server +QMAKE_USE_PRIVATE += wayland_server PLUGIN_TYPE = egldeviceintegrations PLUGIN_CLASS_NAME = QEglFSVivWaylandIntegrationPlugin diff --git a/src/plugins/platforms/mirclient/mirclient.pro b/src/plugins/platforms/mirclient/mirclient.pro index 623f7bf97b..0ba63601a9 100644 --- a/src/plugins/platforms/mirclient/mirclient.pro +++ b/src/plugins/platforms/mirclient/mirclient.pro @@ -10,8 +10,7 @@ DEFINES += MESA_EGL_NO_X11_HEADERS QMAKE_CXXFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11 -Werror -Wall QMAKE_LFLAGS += -std=c++11 -Wl,-no-undefined -CONFIG += link_pkgconfig -PKGCONFIG += egl mirclient ubuntu-platform-api +QMAKE_USE_PRIVATE += mirclient SOURCES = \ qmirclientbackingstore.cpp \ -- cgit v1.2.3 From d19f01acbf9547762150a479793b84898f1a115e Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 18 Oct 2016 13:02:34 +0200 Subject: nsphotolibrarysupport: add missing namespace macros Change-Id: Ib2014dc64dfcc1ea8de63a1668907ace6d26c530 Reviewed-by: Jake Petroules --- .../ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h | 5 +++++ .../optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm | 4 ++++ .../ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h | 4 ++++ 3 files changed, 13 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h index 89696751c6..d4dc77b1a3 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h @@ -37,6 +37,9 @@ #include Q_FORWARD_DECLARE_OBJC_CLASS(ALAsset); + +QT_BEGIN_NAMESPACE + class QIOSAssetData; class QIOSFileEngineAssetsLibrary : public QAbstractFileEngine @@ -72,5 +75,7 @@ private: ALAsset *loadAsset() const; }; +QT_END_NAMESPACE + #endif // QIOSFILEENGINEASSETSLIBRARY_H diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm index 2e88c37c01..110348d32b 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm @@ -42,6 +42,8 @@ #include #include +QT_BEGIN_NAMESPACE + static QThreadStorage g_iteratorCurrentUrl; static QThreadStorage > g_assetDataCache; @@ -466,4 +468,6 @@ QAbstractFileEngine::Iterator *QIOSFileEngineAssetsLibrary::endEntryList() return 0; } +QT_END_NAMESPACE + #endif diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h index 29f543caae..f41de5f8ec 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h @@ -38,6 +38,8 @@ #include #include "qiosfileengineassetslibrary.h" +QT_BEGIN_NAMESPACE + class QIOSFileEngineFactory : public QAbstractFileEngineHandler { public: @@ -52,4 +54,6 @@ public: } }; +QT_END_NAMESPACE + #endif // QIOSFILEENGINEFACTORY_H -- cgit v1.2.3 From 3daa76d49499a1b03ff8296d3aab8f6fa4c23267 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 27 Oct 2016 14:06:49 +0200 Subject: iOS: ensure we return a non-null clipboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QPlatformIntegration::clipboard() is not allowed to return null. This will lead to a crash as soon as someone tries to access QClipboard. Change-Id: I3c1e7cdc5103fe4424f9739a09f599d6c0af40b2 Reviewed-by: Tor Arne Vestbø Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/qiosintegration.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 82b5f3b755..44e636bae6 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -227,7 +227,7 @@ QPlatformClipboard *QIOSIntegration::clipboard() const #ifndef Q_OS_TVOS return m_clipboard; #else - return 0; + return QPlatformIntegration::clipboard(); #endif } #endif -- cgit v1.2.3 From 5700644a4268fdf8717b83a63e4843dcb86814b6 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 27 Oct 2016 13:50:21 +0200 Subject: iOS: guard iOS only code to not break tvOS build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit inputAssistantItem is not available on tvOS. Change-Id: Icff684d6299688fbeaf40ffcb32ff9c46371b305 Reviewed-by: Tor Arne Vestbø Reviewed-by: Jake Petroules --- src/plugins/platforms/ios/qiostextresponder.mm | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index d7b0a323ad..e8d216fbc2 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -236,6 +236,8 @@ self.inputView = [[[WrapperView alloc] initWithView:inputView] autorelease]; if (UIView *accessoryView = static_cast(platformData.value(kImePlatformDataInputAccessoryView).value())) self.inputAccessoryView = [[[WrapperView alloc] initWithView:accessoryView] autorelease]; + +#ifndef Q_OS_TVOS if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_9_0) { if (platformData.value(kImePlatformDataHideShortcutsBar).toBool()) { // According to the docs, leadingBarButtonGroups/trailingBarButtonGroups should be set to nil to hide the shortcuts bar. @@ -247,6 +249,7 @@ self.inputAssistantItem.trailingBarButtonGroups = @[trailing]; } } +#endif self.undoManager.groupsByEvent = NO; [self rebuildUndoStack]; -- cgit v1.2.3 From f9a80e06ac928bf796d013dd7fba10ba30827202 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 3 Jun 2016 16:22:21 -0700 Subject: Move Windows font DB and engines to QtFontDatabaseSupport This allows creating or extending QPA plugins to provide access to QFont and related types. It concerns both GDI and DirectWrite engines, as well as the regular and the freetype based font databases. The qt.qpa.fonts logging category has been moved together into the QWindowsFontDatabase related files to avoid depending on the qwindowscontext.h header file. Finally, QwindowsNativeImage is following pending a future refactor with similar code in qpixmap_win.cpp and the Windows XP style. Change-Id: Iddff2f3d715e3ab7695e6c2052b7596a01fd6fa8 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/direct2d/direct2d.pro | 3 +- .../direct2d/qwindowsdirect2dpaintengine.cpp | 4 +- .../platforms/windows/qwindowsbackingstore.cpp | 2 +- src/plugins/platforms/windows/qwindowscontext.cpp | 1 - src/plugins/platforms/windows/qwindowscontext.h | 1 - .../platforms/windows/qwindowsfontdatabase.cpp | 1960 -------------------- .../platforms/windows/qwindowsfontdatabase.h | 133 -- .../platforms/windows/qwindowsfontdatabase_ft.cpp | 438 ----- .../platforms/windows/qwindowsfontdatabase_ft.h | 68 - .../platforms/windows/qwindowsfontengine.cpp | 1328 ------------- src/plugins/platforms/windows/qwindowsfontengine.h | 187 -- .../windows/qwindowsfontenginedirectwrite.cpp | 1000 ---------- .../windows/qwindowsfontenginedirectwrite.h | 143 -- .../platforms/windows/qwindowsintegration.cpp | 4 +- .../platforms/windows/qwindowsintegration.h | 6 +- .../platforms/windows/qwindowsnativeimage.cpp | 150 -- .../platforms/windows/qwindowsnativeimage.h | 78 - .../platforms/windows/qwindowsnativeinterface.cpp | 2 +- src/plugins/platforms/windows/qwindowstheme.cpp | 2 +- src/plugins/platforms/windows/qwindowswindow.cpp | 1 - src/plugins/platforms/windows/windows.pri | 21 - 21 files changed, 13 insertions(+), 5519 deletions(-) delete mode 100644 src/plugins/platforms/windows/qwindowsfontdatabase.cpp delete mode 100644 src/plugins/platforms/windows/qwindowsfontdatabase.h delete mode 100644 src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp delete mode 100644 src/plugins/platforms/windows/qwindowsfontdatabase_ft.h delete mode 100644 src/plugins/platforms/windows/qwindowsfontengine.cpp delete mode 100644 src/plugins/platforms/windows/qwindowsfontengine.h delete mode 100644 src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp delete mode 100644 src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h delete mode 100644 src/plugins/platforms/windows/qwindowsnativeimage.cpp delete mode 100644 src/plugins/platforms/windows/qwindowsnativeimage.h (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/direct2d/direct2d.pro b/src/plugins/platforms/direct2d/direct2d.pro index 83c4a730f4..c30703720c 100644 --- a/src/plugins/platforms/direct2d/direct2d.pro +++ b/src/plugins/platforms/direct2d/direct2d.pro @@ -2,7 +2,8 @@ TARGET = qdirect2d QT += \ core-private gui-private \ - eventdispatcher_support-private + eventdispatcher_support-private \ + fontdatabase_support-private theme_support-private LIBS += -ldwmapi -ld2d1 -ld3d11 -ldwrite -lVersion -lgdi32 diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp index 0ea2fcfa74..69d2e12778 100644 --- a/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp +++ b/src/plugins/platforms/direct2d/qwindowsdirect2dpaintengine.cpp @@ -45,8 +45,8 @@ #include "qwindowsdirect2dbitmap.h" #include "qwindowsdirect2ddevicecontext.h" -#include "qwindowsfontengine.h" -#include "qwindowsfontdatabase.h" +#include +#include #include "qwindowsintegration.h" #include diff --git a/src/plugins/platforms/windows/qwindowsbackingstore.cpp b/src/plugins/platforms/windows/qwindowsbackingstore.cpp index 3b7374dc92..49c7144221 100644 --- a/src/plugins/platforms/windows/qwindowsbackingstore.cpp +++ b/src/plugins/platforms/windows/qwindowsbackingstore.cpp @@ -39,11 +39,11 @@ #include "qwindowsbackingstore.h" #include "qwindowswindow.h" -#include "qwindowsnativeimage.h" #include "qwindowscontext.h" #include #include +#include #include #include diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index bc317c7f5d..1a03df6ac2 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -84,7 +84,6 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaWindows, "qt.qpa.windows") Q_LOGGING_CATEGORY(lcQpaBackingStore, "qt.qpa.backingstore") Q_LOGGING_CATEGORY(lcQpaEvents, "qt.qpa.events") -Q_LOGGING_CATEGORY(lcQpaFonts, "qt.qpa.fonts") Q_LOGGING_CATEGORY(lcQpaGl, "qt.qpa.gl") Q_LOGGING_CATEGORY(lcQpaMime, "qt.qpa.mime") Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods") diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h index 843f7e2ad6..9dfde67797 100644 --- a/src/plugins/platforms/windows/qwindowscontext.h +++ b/src/plugins/platforms/windows/qwindowscontext.h @@ -59,7 +59,6 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQpaWindows) Q_DECLARE_LOGGING_CATEGORY(lcQpaBackingStore) Q_DECLARE_LOGGING_CATEGORY(lcQpaEvents) -Q_DECLARE_LOGGING_CATEGORY(lcQpaFonts) Q_DECLARE_LOGGING_CATEGORY(lcQpaGl) Q_DECLARE_LOGGING_CATEGORY(lcQpaMime) Q_DECLARE_LOGGING_CATEGORY(lcQpaInputMethods) diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase.cpp deleted file mode 100644 index 1630b80306..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.cpp +++ /dev/null @@ -1,1960 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwindowsfontdatabase.h" -#include "qwindowsfontdatabase_ft.h" // for default font -#include "qwindowscontext.h" -#include "qwindowsintegration.h" -#include "qwindowsfontengine.h" -#include "qwindowsfontenginedirectwrite.h" -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#if !defined(QT_NO_DIRECTWRITE) -# if defined(QT_USE_DIRECTWRITE2) -# include -# else -# include -# endif -# include -#endif - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_DIRECTWRITE -// ### fixme: Consider direct linking of dwrite.dll once Windows Vista pre SP2 is dropped (QTBUG-49711) - -typedef HRESULT (WINAPI *DWriteCreateFactoryType)(DWRITE_FACTORY_TYPE, const IID &, IUnknown **); - -static inline DWriteCreateFactoryType resolveDWriteCreateFactory() -{ - if (QSysInfo::windowsVersion() < QSysInfo::WV_VISTA) - return Q_NULLPTR; - QSystemLibrary library(QStringLiteral("dwrite")); - QFunctionPointer result = library.resolve("DWriteCreateFactory"); - if (Q_UNLIKELY(!result)) { - qWarning("Unable to load dwrite.dll"); - return Q_NULLPTR; - } - return reinterpret_cast(result); -} - -static void createDirectWriteFactory(IDWriteFactory **factory) -{ - *factory = Q_NULLPTR; - - static const DWriteCreateFactoryType dWriteCreateFactory = resolveDWriteCreateFactory(); - if (!dWriteCreateFactory) - return; - - IUnknown *result = NULL; -#if defined(QT_USE_DIRECTWRITE2) - dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory2), &result); -#endif - - if (result == NULL) { - if (FAILED(dWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), &result))) { - qErrnoWarning("DWriteCreateFactory failed"); - return; - } - } - - *factory = static_cast(result); -} - -static inline bool useDirectWrite(QFont::HintingPreference hintingPreference, - const QString &familyName = QString(), - bool isColorFont = false) -{ - const unsigned options = QWindowsIntegration::instance()->options(); - if (Q_UNLIKELY(options & QWindowsIntegration::DontUseDirectWriteFonts)) - return false; - if (isColorFont) - return (options & QWindowsIntegration::DontUseColorFonts) == 0; - - // At some scales, GDI will misrender the MingLiU font, so we force use of - // DirectWrite to work around the issue. - if (Q_UNLIKELY(familyName.startsWith(QLatin1String("MingLiU")))) - return true; - - return hintingPreference == QFont::PreferNoHinting - || hintingPreference == QFont::PreferVerticalHinting - || (QHighDpiScaling::isActive() && hintingPreference == QFont::PreferDefaultHinting); -} -#endif // !QT_NO_DIRECTWRITE - -// Helper classes for creating font engines directly from font data -namespace { - -# pragma pack(1) - - // Common structure for all formats of the "name" table - struct NameTable - { - quint16 format; - quint16 count; - quint16 stringOffset; - }; - - struct NameRecord - { - quint16 platformID; - quint16 encodingID; - quint16 languageID; - quint16 nameID; - quint16 length; - quint16 offset; - }; - - struct OffsetSubTable - { - quint32 scalerType; - quint16 numTables; - quint16 searchRange; - quint16 entrySelector; - quint16 rangeShift; - }; - - struct TableDirectory - { - quint32 identifier; - quint32 checkSum; - quint32 offset; - quint32 length; - }; - - struct OS2Table - { - quint16 version; - qint16 avgCharWidth; - quint16 weightClass; - quint16 widthClass; - quint16 type; - qint16 subscriptXSize; - qint16 subscriptYSize; - qint16 subscriptXOffset; - qint16 subscriptYOffset; - qint16 superscriptXSize; - qint16 superscriptYSize; - qint16 superscriptXOffset; - qint16 superscriptYOffset; - qint16 strikeOutSize; - qint16 strikeOutPosition; - qint16 familyClass; - quint8 panose[10]; - quint32 unicodeRanges[4]; - quint8 vendorID[4]; - quint16 selection; - quint16 firstCharIndex; - quint16 lastCharIndex; - qint16 typoAscender; - qint16 typoDescender; - qint16 typoLineGap; - quint16 winAscent; - quint16 winDescent; - quint32 codepageRanges[2]; - qint16 height; - qint16 capHeight; - quint16 defaultChar; - quint16 breakChar; - quint16 maxContext; - }; - -# pragma pack() - - class EmbeddedFont - { - public: - EmbeddedFont(const QByteArray &fontData) : m_fontData(fontData) {} - - QString changeFamilyName(const QString &newFamilyName); - QByteArray data() const { return m_fontData; } - TableDirectory *tableDirectoryEntry(const QByteArray &tagName); - QString familyName(TableDirectory *nameTableDirectory = 0); - - private: - QByteArray m_fontData; - }; - - TableDirectory *EmbeddedFont::tableDirectoryEntry(const QByteArray &tagName) - { - Q_ASSERT(tagName.size() == 4); - quint32 tagId = *(reinterpret_cast(tagName.constData())); - const size_t fontDataSize = m_fontData.size(); - if (Q_UNLIKELY(fontDataSize < sizeof(OffsetSubTable))) - return 0; - - OffsetSubTable *offsetSubTable = reinterpret_cast(m_fontData.data()); - TableDirectory *tableDirectory = reinterpret_cast(offsetSubTable + 1); - - const size_t tableCount = qFromBigEndian(offsetSubTable->numTables); - if (Q_UNLIKELY(fontDataSize < sizeof(OffsetSubTable) + sizeof(TableDirectory) * tableCount)) - return 0; - - TableDirectory *tableDirectoryEnd = tableDirectory + tableCount; - for (TableDirectory *entry = tableDirectory; entry < tableDirectoryEnd; ++entry) { - if (entry->identifier == tagId) - return entry; - } - - return 0; - } - - QString EmbeddedFont::familyName(TableDirectory *nameTableDirectoryEntry) - { - QString name; - - if (nameTableDirectoryEntry == 0) - nameTableDirectoryEntry = tableDirectoryEntry("name"); - - if (nameTableDirectoryEntry != 0) { - quint32 offset = qFromBigEndian(nameTableDirectoryEntry->offset); - if (Q_UNLIKELY(quint32(m_fontData.size()) < offset + sizeof(NameTable))) - return QString(); - - NameTable *nameTable = reinterpret_cast(m_fontData.data() + offset); - NameRecord *nameRecord = reinterpret_cast(nameTable + 1); - - quint16 nameTableCount = qFromBigEndian(nameTable->count); - if (Q_UNLIKELY(quint32(m_fontData.size()) < offset + sizeof(NameRecord) * nameTableCount)) - return QString(); - - for (int i = 0; i < nameTableCount; ++i, ++nameRecord) { - if (qFromBigEndian(nameRecord->nameID) == 1 - && qFromBigEndian(nameRecord->platformID) == 3 // Windows - && qFromBigEndian(nameRecord->languageID) == 0x0409) { // US English - quint16 stringOffset = qFromBigEndian(nameTable->stringOffset); - quint16 nameOffset = qFromBigEndian(nameRecord->offset); - quint16 nameLength = qFromBigEndian(nameRecord->length); - - if (Q_UNLIKELY(quint32(m_fontData.size()) < offset + stringOffset + nameOffset + nameLength)) - return QString(); - - const void *ptr = reinterpret_cast(nameTable) - + stringOffset - + nameOffset; - - const quint16 *s = reinterpret_cast(ptr); - const quint16 *e = s + nameLength / sizeof(quint16); - while (s != e) - name += QChar( qFromBigEndian(*s++)); - break; - } - } - } - - return name; - } - - QString EmbeddedFont::changeFamilyName(const QString &newFamilyName) - { - TableDirectory *nameTableDirectoryEntry = tableDirectoryEntry("name"); - if (nameTableDirectoryEntry == 0) - return QString(); - - QString oldFamilyName = familyName(nameTableDirectoryEntry); - - // Reserve size for name table header, five required name records and string - const int requiredRecordCount = 5; - quint16 nameIds[requiredRecordCount] = { 1, 2, 3, 4, 6 }; - - int sizeOfHeader = sizeof(NameTable) + sizeof(NameRecord) * requiredRecordCount; - int newFamilyNameSize = newFamilyName.size() * int(sizeof(quint16)); - - const QString regularString = QString::fromLatin1("Regular"); - int regularStringSize = regularString.size() * int(sizeof(quint16)); - - // Align table size of table to 32 bits (pad with 0) - int fullSize = ((sizeOfHeader + newFamilyNameSize + regularStringSize) & ~3) + 4; - - QByteArray newNameTable(fullSize, char(0)); - - { - NameTable *nameTable = reinterpret_cast(newNameTable.data()); - nameTable->count = qbswap(requiredRecordCount); - nameTable->stringOffset = qbswap(sizeOfHeader); - - NameRecord *nameRecord = reinterpret_cast(nameTable + 1); - for (int i = 0; i < requiredRecordCount; ++i, nameRecord++) { - nameRecord->nameID = qbswap(nameIds[i]); - nameRecord->encodingID = qbswap(1); - nameRecord->languageID = qbswap(0x0409); - nameRecord->platformID = qbswap(3); - nameRecord->length = qbswap(newFamilyNameSize); - - // Special case for sub-family - if (nameIds[i] == 4) { - nameRecord->offset = qbswap(newFamilyNameSize); - nameRecord->length = qbswap(regularStringSize); - } - } - - // nameRecord now points to string data - quint16 *stringStorage = reinterpret_cast(nameRecord); - const quint16 *sourceString = newFamilyName.utf16(); - for (int i = 0; i < newFamilyName.size(); ++i) - stringStorage[i] = qbswap(sourceString[i]); - stringStorage += newFamilyName.size(); - - sourceString = regularString.utf16(); - for (int i = 0; i < regularString.size(); ++i) - stringStorage[i] = qbswap(sourceString[i]); - } - - quint32 *p = reinterpret_cast(newNameTable.data()); - quint32 *tableEnd = reinterpret_cast(newNameTable.data() + fullSize); - - quint32 checkSum = 0; - while (p < tableEnd) - checkSum += qFromBigEndian(*(p++)); - - nameTableDirectoryEntry->checkSum = qbswap(checkSum); - nameTableDirectoryEntry->offset = qbswap(m_fontData.size()); - nameTableDirectoryEntry->length = qbswap(fullSize); - - m_fontData.append(newNameTable); - - return oldFamilyName; - } - -#if !defined(QT_NO_DIRECTWRITE) - - class DirectWriteFontFileStream: public IDWriteFontFileStream - { - public: - DirectWriteFontFileStream(const QByteArray &fontData) - : m_fontData(fontData) - , m_referenceCount(0) - { - } - virtual ~DirectWriteFontFileStream() - { - } - - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **object); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - HRESULT STDMETHODCALLTYPE ReadFileFragment(const void **fragmentStart, UINT64 fileOffset, - UINT64 fragmentSize, OUT void **fragmentContext); - void STDMETHODCALLTYPE ReleaseFileFragment(void *fragmentContext); - HRESULT STDMETHODCALLTYPE GetFileSize(OUT UINT64 *fileSize); - HRESULT STDMETHODCALLTYPE GetLastWriteTime(OUT UINT64 *lastWriteTime); - - private: - QByteArray m_fontData; - ULONG m_referenceCount; - }; - - HRESULT STDMETHODCALLTYPE DirectWriteFontFileStream::QueryInterface(REFIID iid, void **object) - { - if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileStream)) { - *object = this; - AddRef(); - return S_OK; - } else { - *object = NULL; - return E_NOINTERFACE; - } - } - - ULONG STDMETHODCALLTYPE DirectWriteFontFileStream::AddRef() - { - return InterlockedIncrement(&m_referenceCount); - } - - ULONG STDMETHODCALLTYPE DirectWriteFontFileStream::Release() - { - ULONG newCount = InterlockedDecrement(&m_referenceCount); - if (newCount == 0) - delete this; - return newCount; - } - - HRESULT STDMETHODCALLTYPE DirectWriteFontFileStream::ReadFileFragment( - const void **fragmentStart, - UINT64 fileOffset, - UINT64 fragmentSize, - OUT void **fragmentContext) - { - *fragmentContext = NULL; - if (fileOffset + fragmentSize <= quint64(m_fontData.size())) { - *fragmentStart = m_fontData.data() + fileOffset; - return S_OK; - } else { - *fragmentStart = NULL; - return E_FAIL; - } - } - - void STDMETHODCALLTYPE DirectWriteFontFileStream::ReleaseFileFragment(void *) - { - } - - HRESULT STDMETHODCALLTYPE DirectWriteFontFileStream::GetFileSize(UINT64 *fileSize) - { - *fileSize = m_fontData.size(); - return S_OK; - } - - HRESULT STDMETHODCALLTYPE DirectWriteFontFileStream::GetLastWriteTime(UINT64 *lastWriteTime) - { - *lastWriteTime = 0; - return E_NOTIMPL; - } - - class DirectWriteFontFileLoader: public IDWriteFontFileLoader - { - public: - DirectWriteFontFileLoader() : m_referenceCount(0) {} - virtual ~DirectWriteFontFileLoader() - { - } - - inline void addKey(const void *key, const QByteArray &fontData) - { - Q_ASSERT(!m_fontDatas.contains(key)); - m_fontDatas.insert(key, fontData); - } - - inline void removeKey(const void *key) - { - m_fontDatas.remove(key); - } - - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **object); - ULONG STDMETHODCALLTYPE AddRef(); - ULONG STDMETHODCALLTYPE Release(); - - HRESULT STDMETHODCALLTYPE CreateStreamFromKey(void const *fontFileReferenceKey, - UINT32 fontFileReferenceKeySize, - OUT IDWriteFontFileStream **fontFileStream); - - private: - ULONG m_referenceCount; - QHash m_fontDatas; - }; - - HRESULT STDMETHODCALLTYPE DirectWriteFontFileLoader::QueryInterface(const IID &iid, - void **object) - { - if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { - *object = this; - AddRef(); - return S_OK; - } else { - *object = NULL; - return E_NOINTERFACE; - } - } - - ULONG STDMETHODCALLTYPE DirectWriteFontFileLoader::AddRef() - { - return InterlockedIncrement(&m_referenceCount); - } - - ULONG STDMETHODCALLTYPE DirectWriteFontFileLoader::Release() - { - ULONG newCount = InterlockedDecrement(&m_referenceCount); - if (newCount == 0) - delete this; - return newCount; - } - - HRESULT STDMETHODCALLTYPE DirectWriteFontFileLoader::CreateStreamFromKey( - void const *fontFileReferenceKey, - UINT32 fontFileReferenceKeySize, - IDWriteFontFileStream **fontFileStream) - { - Q_UNUSED(fontFileReferenceKeySize); - - if (fontFileReferenceKeySize != sizeof(const void *)) { - qWarning("%s: Wrong key size", __FUNCTION__); - return E_FAIL; - } - - const void *key = *reinterpret_cast(fontFileReferenceKey); - *fontFileStream = NULL; - if (!m_fontDatas.contains(key)) - return E_FAIL; - - QByteArray fontData = m_fontDatas.value(key); - DirectWriteFontFileStream *stream = new DirectWriteFontFileStream(fontData); - stream->AddRef(); - *fontFileStream = stream; - - return S_OK; - } - - class CustomFontFileLoader - { - public: - CustomFontFileLoader() : m_directWriteFontFileLoader(Q_NULLPTR) - { - createDirectWriteFactory(&m_directWriteFactory); - - if (m_directWriteFactory) { - m_directWriteFontFileLoader = new DirectWriteFontFileLoader(); - m_directWriteFactory->RegisterFontFileLoader(m_directWriteFontFileLoader); - } - } - - ~CustomFontFileLoader() - { - if (m_directWriteFactory != 0 && m_directWriteFontFileLoader != 0) - m_directWriteFactory->UnregisterFontFileLoader(m_directWriteFontFileLoader); - - if (m_directWriteFactory != 0) - m_directWriteFactory->Release(); - } - - void addKey(const void *key, const QByteArray &fontData) - { - if (m_directWriteFontFileLoader != 0) - m_directWriteFontFileLoader->addKey(key, fontData); - } - - void removeKey(const void *key) - { - if (m_directWriteFontFileLoader != 0) - m_directWriteFontFileLoader->removeKey(key); - } - - IDWriteFontFileLoader *loader() const - { - return m_directWriteFontFileLoader; - } - - private: - IDWriteFactory *m_directWriteFactory; - DirectWriteFontFileLoader *m_directWriteFontFileLoader; - }; - -#endif - -} // Anonymous namespace - -/*! - \struct QWindowsFontEngineData - \brief Static constant data shared by the font engines. - \ingroup qt-lighthouse-win -*/ - -QWindowsFontEngineData::QWindowsFontEngineData() - : clearTypeEnabled(false) - , fontSmoothingGamma(QWindowsFontDatabase::fontSmoothingGamma()) -#if !defined(QT_NO_DIRECTWRITE) - , directWriteFactory(0) - , directWriteGdiInterop(0) -#endif -{ - // from qapplication_win.cpp - UINT result = 0; - if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0)) - clearTypeEnabled = (result == FE_FONTSMOOTHINGCLEARTYPE); - - const qreal gray_gamma = 2.31; - for (int i=0; i<256; ++i) - pow_gamma[i] = uint(qRound(qPow(i / qreal(255.), gray_gamma) * 2047)); - - HDC displayDC = GetDC(0); - hdc = CreateCompatibleDC(displayDC); - ReleaseDC(0, displayDC); -} - -QWindowsFontEngineData::~QWindowsFontEngineData() -{ - if (hdc) - DeleteDC(hdc); -#if !defined(QT_NO_DIRECTWRITE) - if (directWriteGdiInterop) - directWriteGdiInterop->Release(); - if (directWriteFactory) - directWriteFactory->Release(); -#endif -} - -qreal QWindowsFontDatabase::fontSmoothingGamma() -{ - int winSmooth; - qreal result = 1; - if (SystemParametersInfo(0x200C /* SPI_GETFONTSMOOTHINGCONTRAST */, 0, &winSmooth, 0)) - result = qreal(winSmooth) / qreal(1000.0); - - // Safeguard ourselves against corrupt registry values... - if (result > 5 || result < 1) - result = qreal(1.4); - return result; -} - -#if !defined(QT_NO_DIRECTWRITE) -static inline bool initDirectWrite(QWindowsFontEngineData *d) -{ - if (!d->directWriteFactory) { - createDirectWriteFactory(&d->directWriteFactory); - if (!d->directWriteFactory) - return false; - } - if (!d->directWriteGdiInterop) { - const HRESULT hr = d->directWriteFactory->GetGdiInterop(&d->directWriteGdiInterop); - if (FAILED(hr)) { - qErrnoWarning("%s: GetGdiInterop failed", __FUNCTION__); - return false; - } - } - return true; -} - -#endif // !defined(QT_NO_DIRECTWRITE) - -/*! - \class QWindowsFontDatabase - \brief Font database for Windows - - \note The Qt 4.8 WIndows font database employed a mechanism of - delayed population of the database again passing a font name - to EnumFontFamiliesEx(), working around the fact that - EnumFontFamiliesEx() does not list all fonts by default. - This should be introduced to Lighthouse as well? - - \internal - \ingroup qt-lighthouse-win -*/ - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug d, const QFontDef &def) -{ - QDebugStateSaver saver(d); - d.nospace(); - d.noquote(); - d << "QFontDef(Family=\"" << def.family << '"'; - if (!def.styleName.isEmpty()) - d << ", stylename=" << def.styleName; - d << ", pointsize=" << def.pointSize << ", pixelsize=" << def.pixelSize - << ", styleHint=" << def.styleHint << ", weight=" << def.weight - << ", stretch=" << def.stretch << ", hintingPreference=" - << def.hintingPreference << ')'; - return d; -} - -QDebug operator<<(QDebug d, const LOGFONT &lf) -{ - QDebugStateSaver saver(d); - d.nospace(); - d.noquote(); - d << "LOGFONT(\"" << QString::fromWCharArray(lf.lfFaceName) - << "\", lfWidth=" << lf.lfWidth << ", lfHeight=" << lf.lfHeight << ')'; - return d; -} -#endif // !QT_NO_DEBUG_STREAM - -static inline QFontDatabase::WritingSystem writingSystemFromCharSet(uchar charSet) -{ - switch (charSet) { - case ANSI_CHARSET: - case EASTEUROPE_CHARSET: - case BALTIC_CHARSET: - case TURKISH_CHARSET: - return QFontDatabase::Latin; - case GREEK_CHARSET: - return QFontDatabase::Greek; - case RUSSIAN_CHARSET: - return QFontDatabase::Cyrillic; - case HEBREW_CHARSET: - return QFontDatabase::Hebrew; - case ARABIC_CHARSET: - return QFontDatabase::Arabic; - case THAI_CHARSET: - return QFontDatabase::Thai; - case GB2312_CHARSET: - return QFontDatabase::SimplifiedChinese; - case CHINESEBIG5_CHARSET: - return QFontDatabase::TraditionalChinese; - case SHIFTJIS_CHARSET: - return QFontDatabase::Japanese; - case HANGUL_CHARSET: - case JOHAB_CHARSET: - return QFontDatabase::Korean; - case VIETNAMESE_CHARSET: - return QFontDatabase::Vietnamese; - case SYMBOL_CHARSET: - return QFontDatabase::Symbol; - default: - break; - } - return QFontDatabase::Any; -} - -#ifdef MAKE_TAG -#undef MAKE_TAG -#endif -// GetFontData expects the tags in little endian ;( -#define MAKE_TAG(ch1, ch2, ch3, ch4) (\ - (((quint32)(ch4)) << 24) | \ - (((quint32)(ch3)) << 16) | \ - (((quint32)(ch2)) << 8) | \ - ((quint32)(ch1)) \ - ) - -bool localizedName(const QString &name) -{ - const QChar *c = name.unicode(); - for (int i = 0; i < name.length(); ++i) { - if (c[i].unicode() >= 0x100) - return true; - } - return false; -} - -static inline quint16 getUShort(const unsigned char *p) -{ - quint16 val; - val = *p++ << 8; - val |= *p; - - return val; -} - -namespace { - -struct FontNames { - QString name; // e.g. "DejaVu Sans Condensed" - QString style; // e.g. "Italic" - QString preferredName; // e.g. "DejaVu Sans" - QString preferredStyle; // e.g. "Condensed Italic" -}; - -static QString readName(bool unicode, const uchar *string, int length) -{ - QString out; - if (unicode) { - // utf16 - - length /= 2; - out.resize(length); - QChar *uc = out.data(); - for (int i = 0; i < length; ++i) - uc[i] = getUShort(string + 2*i); - } else { - // Apple Roman - - out.resize(length); - QChar *uc = out.data(); - for (int i = 0; i < length; ++i) - uc[i] = QLatin1Char(char(string[i])); - } - return out; -} - -enum FieldTypeValue { - FamilyId = 1, - StyleId = 2, - PreferredFamilyId = 16, - PreferredStyleId = 17, -}; - -enum PlatformFieldValue { - PlatformId_Unicode = 0, - PlatformId_Apple = 1, - PlatformId_Microsoft = 3 -}; - -static FontNames getCanonicalFontNames(const uchar *table, quint32 bytes) -{ - FontNames out; - const int NameRecordSize = 12; - const int MS_LangIdEnglish = 0x009; - - // get the name table - quint16 count; - quint16 string_offset; - const unsigned char *names; - - if (bytes < 8) - return out; - - if (getUShort(table) != 0) - return out; - - count = getUShort(table+2); - string_offset = getUShort(table+4); - names = table + 6; - - if (string_offset >= bytes || 6 + count*NameRecordSize > string_offset) - return out; - - enum PlatformIdType { - NotFound = 0, - Unicode = 1, - Apple = 2, - Microsoft = 3 - }; - - PlatformIdType idStatus[4] = { NotFound, NotFound, NotFound, NotFound }; - int ids[4] = { -1, -1, -1, -1 }; - - for (int i = 0; i < count; ++i) { - // search for the correct name entries - - quint16 platform_id = getUShort(names + i*NameRecordSize); - quint16 encoding_id = getUShort(names + 2 + i*NameRecordSize); - quint16 language_id = getUShort(names + 4 + i*NameRecordSize); - quint16 name_id = getUShort(names + 6 + i*NameRecordSize); - - PlatformIdType *idType = nullptr; - int *id = nullptr; - - switch (name_id) { - case FamilyId: - idType = &idStatus[0]; - id = &ids[0]; - break; - case StyleId: - idType = &idStatus[1]; - id = &ids[1]; - break; - case PreferredFamilyId: - idType = &idStatus[2]; - id = &ids[2]; - break; - case PreferredStyleId: - idType = &idStatus[3]; - id = &ids[3]; - break; - default: - continue; - } - - quint16 length = getUShort(names + 8 + i*NameRecordSize); - quint16 offset = getUShort(names + 10 + i*NameRecordSize); - if (DWORD(string_offset + offset + length) > bytes) - continue; - - if ((platform_id == PlatformId_Microsoft - && (encoding_id == 0 || encoding_id == 1)) - && (language_id & 0x3ff) == MS_LangIdEnglish - && *idType < Microsoft) { - *id = i; - *idType = Microsoft; - } - // not sure if encoding id 4 for Unicode is utf16 or ucs4... - else if (platform_id == PlatformId_Unicode && encoding_id < 4 && *idType < Unicode) { - *id = i; - *idType = Unicode; - } - else if (platform_id == PlatformId_Apple && encoding_id == 0 && language_id == 0 && *idType < Apple) { - *id = i; - *idType = Apple; - } - } - - QString strings[4]; - for (int i = 0; i < 4; ++i) { - if (idStatus[i] == NotFound) - continue; - int id = ids[i]; - quint16 length = getUShort(names + 8 + id * NameRecordSize); - quint16 offset = getUShort(names + 10 + id * NameRecordSize); - const unsigned char *string = table + string_offset + offset; - strings[i] = readName(idStatus[i] != Apple, string, length); - } - - out.name = strings[0]; - out.style = strings[1]; - out.preferredName = strings[2]; - out.preferredStyle = strings[3]; - return out; -} - -} // namespace - -QString getEnglishName(const QString &familyName, bool includeStyle = false) -{ - QString i18n_name; - QString faceName = familyName; - faceName.truncate(LF_FACESIZE - 1); - - HDC hdc = GetDC( 0 ); - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - faceName.toWCharArray(lf.lfFaceName); - lf.lfFaceName[faceName.size()] = 0; - lf.lfCharSet = DEFAULT_CHARSET; - HFONT hfont = CreateFontIndirect(&lf); - - if (!hfont) { - ReleaseDC(0, hdc); - return QString(); - } - - HGDIOBJ oldobj = SelectObject( hdc, hfont ); - - const DWORD name_tag = MAKE_TAG( 'n', 'a', 'm', 'e' ); - - // get the name table - unsigned char *table = 0; - - DWORD bytes = GetFontData( hdc, name_tag, 0, 0, 0 ); - if ( bytes == GDI_ERROR ) { - // ### Unused variable - // int err = GetLastError(); - goto error; - } - - table = new unsigned char[bytes]; - GetFontData(hdc, name_tag, 0, table, bytes); - if ( bytes == GDI_ERROR ) - goto error; - - { - const FontNames names = getCanonicalFontNames(table, bytes); - i18n_name = names.name; - if (includeStyle) - i18n_name += QLatin1Char(' ') + names.style; - } -error: - delete [] table; - SelectObject( hdc, oldobj ); - DeleteObject( hfont ); - ReleaseDC( 0, hdc ); - - //qDebug("got i18n name of '%s' for font '%s'", i18n_name.latin1(), familyName.toLocal8Bit().data()); - return i18n_name; -} - -static bool addFontToDatabase(const QString &familyName, const QString &styleName, uchar charSet, - const TEXTMETRIC *textmetric, - const FONTSIGNATURE *signature, - int type, - bool registerAlias) -{ - // the "@family" fonts are just the same as "family". Ignore them. - if (familyName.isEmpty() || familyName.at(0) == QLatin1Char('@') || familyName.startsWith(QLatin1String("WST_"))) - return false; - - static const int SMOOTH_SCALABLE = 0xffff; - const QString foundryName; // No such concept. - const bool fixed = !(textmetric->tmPitchAndFamily & TMPF_FIXED_PITCH); - const bool ttf = (textmetric->tmPitchAndFamily & TMPF_TRUETYPE); - const bool scalable = textmetric->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); - const int size = scalable ? SMOOTH_SCALABLE : textmetric->tmHeight; - const QFont::Style style = textmetric->tmItalic ? QFont::StyleItalic : QFont::StyleNormal; - const bool antialias = false; - const QFont::Weight weight = QPlatformFontDatabase::weightFromInteger(textmetric->tmWeight); - const QFont::Stretch stretch = QFont::Unstretched; - -#ifndef QT_NO_DEBUG_OUTPUT - if (QWindowsContext::verbose > 2) { - QString message; - QTextStream str(&message); - str << __FUNCTION__ << ' ' << familyName << ' ' << charSet << " TTF=" << ttf; - if (type & DEVICE_FONTTYPE) - str << " DEVICE"; - if (type & RASTER_FONTTYPE) - str << " RASTER"; - if (type & TRUETYPE_FONTTYPE) - str << " TRUETYPE"; - str << " scalable=" << scalable << " Size=" << size - << " Style=" << style << " Weight=" << weight - << " stretch=" << stretch; - qCDebug(lcQpaFonts) << message; - } -#endif - - QString englishName; - if (registerAlias && ttf && localizedName(familyName)) - englishName = getEnglishName(familyName); - - QSupportedWritingSystems writingSystems; - if (type & TRUETYPE_FONTTYPE) { - Q_ASSERT(signature); - quint32 unicodeRange[4] = { - signature->fsUsb[0], signature->fsUsb[1], - signature->fsUsb[2], signature->fsUsb[3] - }; - quint32 codePageRange[2] = { - signature->fsCsb[0], signature->fsCsb[1] - }; - writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); - // ### Hack to work around problem with Thai text on Windows 7. Segoe UI contains - // the symbol for Baht, and Windows thus reports that it supports the Thai script. - // Since it's the default UI font on this platform, most widgets will be unable to - // display Thai text by default. As a temporary work around, we special case Segoe UI - // and remove the Thai script from its list of supported writing systems. - if (writingSystems.supported(QFontDatabase::Thai) && - familyName == QLatin1String("Segoe UI")) - writingSystems.setSupported(QFontDatabase::Thai, false); - } else { - const QFontDatabase::WritingSystem ws = writingSystemFromCharSet(charSet); - if (ws != QFontDatabase::Any) - writingSystems.setSupported(ws); - } - - QPlatformFontDatabase::registerFont(familyName, styleName, foundryName, weight, - style, stretch, antialias, scalable, size, fixed, writingSystems, 0); - // add fonts windows can generate for us: - if (weight <= QFont::DemiBold && styleName.isEmpty()) - QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, - style, stretch, antialias, scalable, size, fixed, writingSystems, 0); - if (style != QFont::StyleItalic && styleName.isEmpty()) - QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight, - QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); - if (weight <= QFont::DemiBold && style != QFont::StyleItalic && styleName.isEmpty()) - QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, - QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); - - if (!englishName.isEmpty()) - QPlatformFontDatabase::registerAliasToFontFamily(familyName, englishName); - - return true; -} - -static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *textmetric, - DWORD type, LPARAM lParam) -{ - const ENUMLOGFONTEX *f = reinterpret_cast(logFont); - const QString familyName = QString::fromWCharArray(f->elfLogFont.lfFaceName); - const QString styleName = QString::fromWCharArray(f->elfStyle); - const uchar charSet = f->elfLogFont.lfCharSet; - const bool registerAlias = bool(lParam); - - // NEWTEXTMETRICEX (passed for TT fonts) is a NEWTEXTMETRIC, which according - // to the documentation is identical to a TEXTMETRIC except for the last four - // members, which we don't use anyway - const FONTSIGNATURE *signature = Q_NULLPTR; - if (type & TRUETYPE_FONTTYPE) - signature = &reinterpret_cast(textmetric)->ntmFontSig; - addFontToDatabase(familyName, styleName, charSet, textmetric, signature, type, registerAlias); - - // keep on enumerating - return 1; -} - -void QWindowsFontDatabase::populateFamily(const QString &familyName, bool registerAlias) -{ - qCDebug(lcQpaFonts) << familyName; - if (familyName.size() >= LF_FACESIZE) { - qCWarning(lcQpaFonts) << "Unable to enumerate family '" << familyName << '\''; - return; - } - HDC dummy = GetDC(0); - LOGFONT lf; - lf.lfCharSet = DEFAULT_CHARSET; - familyName.toWCharArray(lf.lfFaceName); - lf.lfFaceName[familyName.size()] = 0; - lf.lfPitchAndFamily = 0; - EnumFontFamiliesEx(dummy, &lf, storeFont, LPARAM(registerAlias), 0); - ReleaseDC(0, dummy); -} - -void QWindowsFontDatabase::populateFamily(const QString &familyName) -{ - populateFamily(familyName, false); -} - -namespace { -// Context for enumerating system fonts, records whether the default font has been encountered, -// which is normally not enumerated by EnumFontFamiliesEx(). -struct PopulateFamiliesContext -{ - PopulateFamiliesContext(const QString &f) : systemDefaultFont(f), seenSystemDefaultFont(false) {} - - QString systemDefaultFont; - bool seenSystemDefaultFont; -}; -} // namespace - -static int QT_WIN_CALLBACK populateFontFamilies(const LOGFONT *logFont, const TEXTMETRIC *textmetric, - DWORD, LPARAM lparam) -{ - // the "@family" fonts are just the same as "family". Ignore them. - const ENUMLOGFONTEX *f = reinterpret_cast(logFont); - const wchar_t *faceNameW = f->elfLogFont.lfFaceName; - if (faceNameW[0] && faceNameW[0] != L'@' && wcsncmp(faceNameW, L"WST_", 4)) { - const QString faceName = QString::fromWCharArray(faceNameW); - QPlatformFontDatabase::registerFontFamily(faceName); - PopulateFamiliesContext *context = reinterpret_cast(lparam); - if (!context->seenSystemDefaultFont && faceName == context->systemDefaultFont) - context->seenSystemDefaultFont = true; - - // Register current font's english name as alias - const bool ttf = textmetric->tmPitchAndFamily & TMPF_TRUETYPE; - if (ttf && localizedName(faceName)) { - const QString englishName = getEnglishName(faceName); - if (!englishName.isEmpty()) { - QPlatformFontDatabase::registerAliasToFontFamily(faceName, englishName); - // Check whether the system default font name is an alias of the current font family name, - // as on Chinese Windows, where the system font "SimSun" is an alias to a font registered under a local name - if (!context->seenSystemDefaultFont && englishName == context->systemDefaultFont) - context->seenSystemDefaultFont = true; - } - } - } - return 1; // continue -} - -void QWindowsFontDatabase::populateFontDatabase() -{ - removeApplicationFonts(); - HDC dummy = GetDC(0); - LOGFONT lf; - lf.lfCharSet = DEFAULT_CHARSET; - lf.lfFaceName[0] = 0; - lf.lfPitchAndFamily = 0; - PopulateFamiliesContext context(QWindowsFontDatabase::systemDefaultFont().family()); - EnumFontFamiliesEx(dummy, &lf, populateFontFamilies, reinterpret_cast(&context), 0); - ReleaseDC(0, dummy); - // Work around EnumFontFamiliesEx() not listing the system font. - if (!context.seenSystemDefaultFont) - QPlatformFontDatabase::registerFontFamily(context.systemDefaultFont); -} - -typedef QSharedPointer QWindowsFontEngineDataPtr; - -#ifndef QT_NO_THREAD -typedef QThreadStorage FontEngineThreadLocalData; - -Q_GLOBAL_STATIC(FontEngineThreadLocalData, fontEngineThreadLocalData) - -QSharedPointer sharedFontData() -{ - FontEngineThreadLocalData *data = fontEngineThreadLocalData(); - if (!data->hasLocalData()) - data->setLocalData(QSharedPointer::create()); - return data->localData(); -} -#else // !QT_NO_THREAD -Q_GLOBAL_STATIC(QWindowsFontEngineDataPtr, fontEngineData) - -QWindowsFontEngineDataPtr sharedFontData() -{ - QWindowsFontEngineDataPtr *data = fontEngineData(); - if (data->isNull()) - *data = QWindowsFontEngineDataPtr::create(); - return *data; -} -#endif // QT_NO_THREAD - -extern Q_GUI_EXPORT bool qt_needs_a8_gamma_correction; - -QWindowsFontDatabase::QWindowsFontDatabase() -{ - // Properties accessed by QWin32PrintEngine (Qt Print Support) - static const int hfontMetaTypeId = qRegisterMetaType(); - static const int logFontMetaTypeId = qRegisterMetaType(); - Q_UNUSED(hfontMetaTypeId) - Q_UNUSED(logFontMetaTypeId) - - if (lcQpaFonts().isDebugEnabled()) { - const QWindowsFontEngineDataPtr data = sharedFontData(); - qCDebug(lcQpaFonts) << __FUNCTION__ << "Clear type: " - << data->clearTypeEnabled << "gamma: " << data->fontSmoothingGamma; - } - qt_needs_a8_gamma_correction = true; -} - -QWindowsFontDatabase::~QWindowsFontDatabase() -{ - removeApplicationFonts(); -} - -QFontEngineMulti *QWindowsFontDatabase::fontEngineMulti(QFontEngine *fontEngine, QChar::Script script) -{ - return new QWindowsMultiFontEngine(fontEngine, script); -} - -QFontEngine * QWindowsFontDatabase::fontEngine(const QFontDef &fontDef, void *handle) -{ - QFontEngine *fe = QWindowsFontDatabase::createEngine(fontDef, - QWindowsContext::instance()->defaultDPI(), - sharedFontData()); - qCDebug(lcQpaFonts) << __FUNCTION__ << "FONTDEF" << fontDef << fe << handle; - return fe; -} - -QFontEngine *QWindowsFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) -{ - EmbeddedFont font(fontData); - QFontEngine *fontEngine = 0; - -#if !defined(QT_NO_DIRECTWRITE) - if (!useDirectWrite(hintingPreference)) -#endif - { - GUID guid; - CoCreateGuid(&guid); - -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wstrict-aliasing") - QString uniqueFamilyName = QLatin1Char('f') - + QString::number(guid.Data1, 36) + QLatin1Char('-') - + QString::number(guid.Data2, 36) + QLatin1Char('-') - + QString::number(guid.Data3, 36) + QLatin1Char('-') - + QString::number(*reinterpret_cast(guid.Data4), 36); -QT_WARNING_POP - - QString actualFontName = font.changeFamilyName(uniqueFamilyName); - if (actualFontName.isEmpty()) { - qWarning("%s: Can't change family name of font", __FUNCTION__); - return 0; - } - - DWORD count = 0; - QByteArray newFontData = font.data(); - HANDLE fontHandle = - AddFontMemResourceEx(const_cast(newFontData.constData()), - DWORD(newFontData.size()), 0, &count); - if (count == 0 && fontHandle != 0) { - RemoveFontMemResourceEx(fontHandle); - fontHandle = 0; - } - - if (fontHandle == 0) { - qWarning("%s: AddFontMemResourceEx failed", __FUNCTION__); - } else { - QFontDef request; - request.family = uniqueFamilyName; - request.pixelSize = pixelSize; - request.styleStrategy = QFont::PreferMatch; - request.hintingPreference = hintingPreference; - request.stretch = QFont::Unstretched; - - fontEngine = QWindowsFontDatabase::createEngine(request, - QWindowsContext::instance()->defaultDPI(), - sharedFontData()); - - if (fontEngine) { - if (request.family != fontEngine->fontDef.family) { - qWarning("%s: Failed to load font. Got fallback instead: %s", - __FUNCTION__, qPrintable(fontEngine->fontDef.family)); - if (fontEngine->ref.load() == 0) - delete fontEngine; - fontEngine = 0; - } else { - Q_ASSERT(fontEngine->ref.load() == 0); - - // Override the generated font name - switch (fontEngine->type()) { - case QFontEngine::Win: - static_cast(fontEngine)->setUniqueFamilyName(uniqueFamilyName); - fontEngine->fontDef.family = actualFontName; - break; - -#if !defined(QT_NO_DIRECTWRITE) - case QFontEngine::DirectWrite: - static_cast(fontEngine)->setUniqueFamilyName(uniqueFamilyName); - fontEngine->fontDef.family = actualFontName; - break; -#endif // !QT_NO_DIRECTWRITE - - default: - Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled font engine."); - } - - UniqueFontData uniqueData; - uniqueData.handle = fontHandle; - uniqueData.refCount.ref(); - m_uniqueFontData[uniqueFamilyName] = uniqueData; - } - } else { - RemoveFontMemResourceEx(fontHandle); - } - } - } -#if !defined(QT_NO_DIRECTWRITE) - else { - CustomFontFileLoader fontFileLoader; - fontFileLoader.addKey(this, fontData); - - QSharedPointer fontEngineData = sharedFontData(); - if (!initDirectWrite(fontEngineData.data())) - return 0; - - IDWriteFontFile *fontFile = 0; - void *key = this; - - HRESULT hres = fontEngineData->directWriteFactory->CreateCustomFontFileReference(&key, - sizeof(void *), - fontFileLoader.loader(), - &fontFile); - if (FAILED(hres)) { - qErrnoWarning(hres, "%s: CreateCustomFontFileReference failed", __FUNCTION__); - return 0; - } - - BOOL isSupportedFontType; - DWRITE_FONT_FILE_TYPE fontFileType; - DWRITE_FONT_FACE_TYPE fontFaceType; - UINT32 numberOfFaces; - fontFile->Analyze(&isSupportedFontType, &fontFileType, &fontFaceType, &numberOfFaces); - if (!isSupportedFontType) { - fontFile->Release(); - return 0; - } - - IDWriteFontFace *directWriteFontFace = 0; - hres = fontEngineData->directWriteFactory->CreateFontFace(fontFaceType, - 1, - &fontFile, - 0, - DWRITE_FONT_SIMULATIONS_NONE, - &directWriteFontFace); - if (FAILED(hres)) { - qErrnoWarning(hres, "%s: CreateFontFace failed", __FUNCTION__); - fontFile->Release(); - return 0; - } - - fontFile->Release(); - - fontEngine = new QWindowsFontEngineDirectWrite(directWriteFontFace, - pixelSize, - fontEngineData); - - // Get font family from font data - fontEngine->fontDef.family = font.familyName(); - fontEngine->fontDef.hintingPreference = hintingPreference; - - directWriteFontFace->Release(); - } -#endif - - // Get style and weight info - if (fontEngine != 0) { - TableDirectory *os2TableEntry = font.tableDirectoryEntry("OS/2"); - if (os2TableEntry != 0) { - const OS2Table *os2Table = - reinterpret_cast(fontData.constData() - + qFromBigEndian(os2TableEntry->offset)); - - bool italic = qFromBigEndian(os2Table->selection) & 1; - bool oblique = qFromBigEndian(os2Table->selection) & 128; - - if (italic) - fontEngine->fontDef.style = QFont::StyleItalic; - else if (oblique) - fontEngine->fontDef.style = QFont::StyleOblique; - else - fontEngine->fontDef.style = QFont::StyleNormal; - - fontEngine->fontDef.weight = QPlatformFontDatabase::weightFromInteger(qFromBigEndian(os2Table->weightClass)); - } - } - - qCDebug(lcQpaFonts) << __FUNCTION__ << "FONTDATA" << fontData << pixelSize << hintingPreference << fontEngine; - return fontEngine; -} - -static QList getTrueTypeFontOffsets(const uchar *fontData) -{ - QList offsets; - const quint32 headerTag = *reinterpret_cast(fontData); - if (headerTag != MAKE_TAG('t', 't', 'c', 'f')) { - if (headerTag != MAKE_TAG(0, 1, 0, 0) - && headerTag != MAKE_TAG('O', 'T', 'T', 'O') - && headerTag != MAKE_TAG('t', 'r', 'u', 'e') - && headerTag != MAKE_TAG('t', 'y', 'p', '1')) - return offsets; - offsets << 0; - return offsets; - } - const quint32 numFonts = qFromBigEndian(fontData + 8); - for (uint i = 0; i < numFonts; ++i) { - offsets << qFromBigEndian(fontData + 12 + i * 4); - } - return offsets; -} - -static void getFontTable(const uchar *fileBegin, const uchar *data, quint32 tag, const uchar **table, quint32 *length) -{ - const quint16 numTables = qFromBigEndian(data + 4); - for (uint i = 0; i < numTables; ++i) { - const quint32 offset = 12 + 16 * i; - if (*reinterpret_cast(data + offset) == tag) { - *table = fileBegin + qFromBigEndian(data + offset + 8); - *length = qFromBigEndian(data + offset + 12); - return; - } - } - *table = 0; - *length = 0; - return; -} - -static void getFamiliesAndSignatures(const QByteArray &fontData, - QList *families, - QVector *signatures) -{ - const uchar *data = reinterpret_cast(fontData.constData()); - - QList offsets = getTrueTypeFontOffsets(data); - if (offsets.isEmpty()) - return; - - for (int i = 0; i < offsets.count(); ++i) { - const uchar *font = data + offsets.at(i); - const uchar *table; - quint32 length; - getFontTable(data, font, MAKE_TAG('n', 'a', 'm', 'e'), &table, &length); - if (!table) - continue; - FontNames names = getCanonicalFontNames(table, length); - if (names.name.isEmpty()) - continue; - - families->append(qMove(names)); - - if (signatures) { - FONTSIGNATURE signature; - getFontTable(data, font, MAKE_TAG('O', 'S', '/', '2'), &table, &length); - if (table && length >= 86) { - // Offsets taken from OS/2 table in the TrueType spec - signature.fsUsb[0] = qFromBigEndian(table + 42); - signature.fsUsb[1] = qFromBigEndian(table + 46); - signature.fsUsb[2] = qFromBigEndian(table + 50); - signature.fsUsb[3] = qFromBigEndian(table + 54); - - signature.fsCsb[0] = qFromBigEndian(table + 78); - signature.fsCsb[1] = qFromBigEndian(table + 82); - } else { - memset(&signature, 0, sizeof(signature)); - } - signatures->append(signature); - } - } -} - -QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) -{ - WinApplicationFont font; - font.fileName = fileName; - QVector signatures; - QList families; - QStringList familyNames; - - if (!fontData.isEmpty()) { - getFamiliesAndSignatures(fontData, &families, &signatures); - if (families.isEmpty()) - return familyNames; - - DWORD dummy = 0; - font.handle = - AddFontMemResourceEx(const_cast(fontData.constData()), - DWORD(fontData.size()), 0, &dummy); - if (font.handle == 0) - return QStringList(); - - // Memory fonts won't show up in enumeration, so do add them the hard way. - for (int j = 0; j < families.count(); ++j) { - const QString familyName = families.at(j).name; - const QString styleName = families.at(j).style; - familyNames << familyName; - HDC hdc = GetDC(0); - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - memcpy(lf.lfFaceName, familyName.utf16(), sizeof(wchar_t) * qMin(LF_FACESIZE - 1, familyName.size())); - lf.lfCharSet = DEFAULT_CHARSET; - HFONT hfont = CreateFontIndirect(&lf); - HGDIOBJ oldobj = SelectObject(hdc, hfont); - - TEXTMETRIC textMetrics; - GetTextMetrics(hdc, &textMetrics); - - addFontToDatabase(familyName, styleName, lf.lfCharSet, &textMetrics, &signatures.at(j), - TRUETYPE_FONTTYPE, true); - - SelectObject(hdc, oldobj); - DeleteObject(hfont); - ReleaseDC(0, hdc); - } - } else { - QFile f(fileName); - if (!f.open(QIODevice::ReadOnly)) - return QStringList(); - QByteArray data = f.readAll(); - f.close(); - - getFamiliesAndSignatures(data, &families, 0); - if (families.isEmpty()) - return QStringList(); - - if (AddFontResourceExW((wchar_t*)fileName.utf16(), FR_PRIVATE, 0) == 0) - return QStringList(); - - font.handle = 0; - - // Fonts based on files are added via populate, as they will show up in font enumeration. - for (int j = 0; j < families.count(); ++j) { - const QString familyName = families.at(j).name; - familyNames << familyName; - populateFamily(familyName, true); - } - } - - m_applicationFonts << font; - - return familyNames; -} - -void QWindowsFontDatabase::removeApplicationFonts() -{ - foreach (const WinApplicationFont &font, m_applicationFonts) { - if (font.handle) { - RemoveFontMemResourceEx(font.handle); - } else { - RemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0); - } - } - m_applicationFonts.clear(); -} - -void QWindowsFontDatabase::releaseHandle(void * /* handle */) -{ -} - -QString QWindowsFontDatabase::fontDir() const -{ - const QString result = QPlatformFontDatabase::fontDir(); - qCDebug(lcQpaFonts) << __FUNCTION__ << result; - return result; -} - -bool QWindowsFontDatabase::fontsAlwaysScalable() const -{ - return true; -} - -void QWindowsFontDatabase::derefUniqueFont(const QString &uniqueFont) -{ - if (m_uniqueFontData.contains(uniqueFont)) { - if (!m_uniqueFontData[uniqueFont].refCount.deref()) { - RemoveFontMemResourceEx(m_uniqueFontData[uniqueFont].handle); - m_uniqueFontData.remove(uniqueFont); - } - } -} - -void QWindowsFontDatabase::refUniqueFont(const QString &uniqueFont) -{ - if (m_uniqueFontData.contains(uniqueFont)) - m_uniqueFontData[uniqueFont].refCount.ref(); -} - -HFONT QWindowsFontDatabase::systemFont() -{ - static const HFONT stock_sysfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); - return stock_sysfont; -} - -// Creation functions - -static const char *other_tryFonts[] = { - "Arial", - "MS UI Gothic", - "Gulim", - "SimSun", - "PMingLiU", - "Arial Unicode MS", - 0 -}; - -static const char *jp_tryFonts [] = { - "MS UI Gothic", - "Arial", - "Gulim", - "SimSun", - "PMingLiU", - "Arial Unicode MS", - 0 -}; - -static const char *ch_CN_tryFonts [] = { - "SimSun", - "Arial", - "PMingLiU", - "Gulim", - "MS UI Gothic", - "Arial Unicode MS", - 0 -}; - -static const char *ch_TW_tryFonts [] = { - "PMingLiU", - "Arial", - "SimSun", - "Gulim", - "MS UI Gothic", - "Arial Unicode MS", - 0 -}; - -static const char *kr_tryFonts[] = { - "Gulim", - "Arial", - "PMingLiU", - "SimSun", - "MS UI Gothic", - "Arial Unicode MS", - 0 -}; - -static const char **tryFonts = 0; - -LOGFONT QWindowsFontDatabase::fontDefToLOGFONT(const QFontDef &request) -{ - LOGFONT lf; - memset(&lf, 0, sizeof(LOGFONT)); - - lf.lfHeight = -qRound(request.pixelSize); - lf.lfWidth = 0; - lf.lfEscapement = 0; - lf.lfOrientation = 0; - if (request.weight == 50) - lf.lfWeight = FW_DONTCARE; - else - lf.lfWeight = (request.weight*900)/99; - lf.lfItalic = request.style != QFont::StyleNormal; - lf.lfCharSet = DEFAULT_CHARSET; - - int strat = OUT_DEFAULT_PRECIS; - if (request.styleStrategy & QFont::PreferBitmap) { - strat = OUT_RASTER_PRECIS; - } else if (request.styleStrategy & QFont::PreferDevice) { - strat = OUT_DEVICE_PRECIS; - } else if (request.styleStrategy & QFont::PreferOutline) { - strat = OUT_OUTLINE_PRECIS; - } else if (request.styleStrategy & QFont::ForceOutline) { - strat = OUT_TT_ONLY_PRECIS; - } - - lf.lfOutPrecision = strat; - - int qual = DEFAULT_QUALITY; - - if (request.styleStrategy & QFont::PreferMatch) - qual = DRAFT_QUALITY; - else if (request.styleStrategy & QFont::PreferQuality) - qual = PROOF_QUALITY; - - if (request.styleStrategy & QFont::PreferAntialias) { - if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && !(request.styleStrategy & QFont::NoSubpixelAntialias)) { - qual = CLEARTYPE_QUALITY; - } else { - qual = ANTIALIASED_QUALITY; - } - } else if (request.styleStrategy & QFont::NoAntialias) { - qual = NONANTIALIASED_QUALITY; - } else if ((request.styleStrategy & QFont::NoSubpixelAntialias) && sharedFontData()->clearTypeEnabled) { - qual = ANTIALIASED_QUALITY; - } - - lf.lfQuality = qual; - - lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; - - int hint = FF_DONTCARE; - switch (request.styleHint) { - case QFont::Helvetica: - hint = FF_SWISS; - break; - case QFont::Times: - hint = FF_ROMAN; - break; - case QFont::Courier: - hint = FF_MODERN; - break; - case QFont::OldEnglish: - hint = FF_DECORATIVE; - break; - case QFont::System: - hint = FF_MODERN; - break; - default: - break; - } - - lf.lfPitchAndFamily = DEFAULT_PITCH | hint; - - QString fam = request.family; - if (Q_UNLIKELY(fam.size() >= LF_FACESIZE)) { - qCritical("%s: Family name '%s' is too long.", __FUNCTION__, qPrintable(fam)); - fam.truncate(LF_FACESIZE - 1); - } - - if (fam.isEmpty()) - fam = QStringLiteral("MS Sans Serif"); - - if (fam == QLatin1String("MS Sans Serif") - && (request.style == QFont::StyleItalic || (-lf.lfHeight > 18 && -lf.lfHeight != 24))) { - fam = QStringLiteral("Arial"); // MS Sans Serif has bearing problems in italic, and does not scale - } - if (fam == QLatin1String("Courier") && !(request.styleStrategy & QFont::PreferBitmap)) - fam = QStringLiteral("Courier New"); - - memcpy(lf.lfFaceName, fam.utf16(), fam.size() * sizeof(wchar_t)); - - return lf; -} - -QStringList QWindowsFontDatabase::extraTryFontsForFamily(const QString &family) -{ - QStringList result; - QFontDatabase db; - if (!db.writingSystems(family).contains(QFontDatabase::Symbol)) { - if (!tryFonts) { - LANGID lid = GetUserDefaultLangID(); - switch (lid&0xff) { - case LANG_CHINESE: // Chinese - if ( lid == 0x0804 || lid == 0x1004) // China mainland and Singapore - tryFonts = ch_CN_tryFonts; - else - tryFonts = ch_TW_tryFonts; // Taiwan, Hong Kong and Macau - break; - case LANG_JAPANESE: - tryFonts = jp_tryFonts; - break; - case LANG_KOREAN: - tryFonts = kr_tryFonts; - break; - default: - tryFonts = other_tryFonts; - break; - } - } - QFontDatabase db; - const QStringList families = db.families(); - const char **tf = tryFonts; - while (tf && *tf) { - // QTBUG-31689, family might be an English alias for a localized font name. - const QString family = QString::fromLatin1(*tf); - if (families.contains(family) || db.hasFamily(family)) - result << family; - ++tf; - } - } - result.append(QStringLiteral("Segoe UI Emoji")); - result.append(QStringLiteral("Segoe UI Symbol")); - return result; -} - -QString QWindowsFontDatabase::familyForStyleHint(QFont::StyleHint styleHint) -{ - switch (styleHint) { - case QFont::Times: - return QStringLiteral("Times New Roman"); - case QFont::Courier: - return QStringLiteral("Courier New"); - case QFont::Monospace: - return QStringLiteral("Courier New"); - case QFont::Cursive: - return QStringLiteral("Comic Sans MS"); - case QFont::Fantasy: - return QStringLiteral("Impact"); - case QFont::Decorative: - return QStringLiteral("Old English"); - case QFont::Helvetica: - return QStringLiteral("Arial"); - case QFont::System: - default: - break; - } - return QStringLiteral("MS Shell Dlg 2"); -} - -QStringList QWindowsFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const -{ - QStringList result; - result.append(QWindowsFontDatabase::familyForStyleHint(styleHint)); - result.append(QWindowsFontDatabase::extraTryFontsForFamily(family)); - result.append(QPlatformFontDatabase::fallbacksForFamily(family, style, styleHint, script)); - - qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint - << script << result; - return result; -} - - -QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, - int dpi, - const QSharedPointer &data) -{ - QFontEngine *fe = 0; - - LOGFONT lf = fontDefToLOGFONT(request); - const bool preferClearTypeAA = lf.lfQuality == CLEARTYPE_QUALITY; - - if (request.stretch != 100) { - HFONT hfont = CreateFontIndirect(&lf); - if (!hfont) { - qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); - hfont = QWindowsFontDatabase::systemFont(); - } - - HGDIOBJ oldObj = SelectObject(data->hdc, hfont); - TEXTMETRIC tm; - if (!GetTextMetrics(data->hdc, &tm)) - qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); - else - lf.lfWidth = tm.tmAveCharWidth * request.stretch / 100; - SelectObject(data->hdc, oldObj); - - DeleteObject(hfont); - } - -#if !defined(QT_NO_DIRECTWRITE) - if (initDirectWrite(data.data())) { - const QString fam = QString::fromWCharArray(lf.lfFaceName); - const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam); - if (nameSubstitute != fam) { - const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1); - memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t)); - lf.lfFaceName[nameSubstituteLength] = 0; - } - - HFONT hfont = CreateFontIndirect(&lf); - if (!hfont) { - qErrnoWarning("%s: CreateFontIndirect failed", __FUNCTION__); - } else { - HGDIOBJ oldFont = SelectObject(data->hdc, hfont); - - IDWriteFontFace *directWriteFontFace = NULL; - HRESULT hr = data->directWriteGdiInterop->CreateFontFaceFromHdc(data->hdc, &directWriteFontFace); - if (FAILED(hr)) { - const QString errorString = qt_error_string(int(hr)); - qWarning().noquote().nospace() << "DirectWrite: CreateFontFaceFromHDC() failed (" - << errorString << ") for " << request << ' ' << lf << " dpi=" << dpi; - } else { - bool isColorFont = false; -#if defined(QT_USE_DIRECTWRITE2) - IDWriteFontFace2 *directWriteFontFace2 = Q_NULLPTR; - if (SUCCEEDED(directWriteFontFace->QueryInterface(__uuidof(IDWriteFontFace2), - reinterpret_cast(&directWriteFontFace2)))) { - if (directWriteFontFace2->IsColorFont()) - isColorFont = directWriteFontFace2->GetPaletteEntryCount() > 0; - } -#endif - const QFont::HintingPreference hintingPreference = - static_cast(request.hintingPreference); - const bool useDw = useDirectWrite(hintingPreference, fam, isColorFont); - qCDebug(lcQpaFonts) << __FUNCTION__ << request.family << request.pointSize - << "pt" << "hintingPreference=" << hintingPreference << "color=" << isColorFont - << dpi << "dpi" << "useDirectWrite=" << useDw; - if (useDw) { - QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace, - request.pixelSize, - data); - - wchar_t n[64]; - GetTextFace(data->hdc, 64, n); - - QFontDef fontDef = request; - fontDef.family = QString::fromWCharArray(n); - - if (isColorFont) - fedw->glyphFormat = QFontEngine::Format_ARGB; - fedw->initFontInfo(fontDef, dpi); - fe = fedw; - } else { - directWriteFontFace->Release(); - } - } - - SelectObject(data->hdc, oldFont); - DeleteObject(hfont); - } - } -#endif // QT_NO_DIRECTWRITE - - if (!fe) { - QWindowsFontEngine *few = new QWindowsFontEngine(request.family, lf, data); - if (preferClearTypeAA) - few->glyphFormat = QFontEngine::Format_A32; - few->initFontInfo(request, dpi); - fe = few; - } - - return fe; -} - -static inline int verticalDPI() -{ - return GetDeviceCaps(QWindowsContext::instance()->displayContext(), LOGPIXELSY); -} - -QFont QWindowsFontDatabase::systemDefaultFont() -{ - LOGFONT lf; - GetObject(QWindowsFontDatabase::systemFont(), sizeof(lf), &lf); - QFont systemFont = QWindowsFontDatabase::LOGFONT_to_QFont(lf); - // "MS Shell Dlg 2" is the correct system font >= Win2k - if (systemFont.family() == QLatin1String("MS Shell Dlg")) - systemFont.setFamily(QStringLiteral("MS Shell Dlg 2")); - qCDebug(lcQpaFonts) << __FUNCTION__ << systemFont; - return systemFont; -} - -QFont QWindowsFontDatabase::LOGFONT_to_QFont(const LOGFONT& logFont, int verticalDPI_In) -{ - if (verticalDPI_In <= 0) - verticalDPI_In = verticalDPI(); - QFont qFont(QString::fromWCharArray(logFont.lfFaceName)); - qFont.setItalic(logFont.lfItalic); - if (logFont.lfWeight != FW_DONTCARE) - qFont.setWeight(QPlatformFontDatabase::weightFromInteger(logFont.lfWeight)); - const qreal logFontHeight = qAbs(logFont.lfHeight); - qFont.setPointSizeF(logFontHeight * 72.0 / qreal(verticalDPI_In)); - qFont.setUnderline(logFont.lfUnderline); - qFont.setOverline(false); - qFont.setStrikeOut(logFont.lfStrikeOut); - return qFont; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase.h b/src/plugins/platforms/windows/qwindowsfontdatabase.h deleted file mode 100644 index 8b8c9c15f4..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontdatabase.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSFONTDATABASE_H -#define QWINDOWSFONTDATABASE_H - -#include -#include -#include - -#if !defined(QT_NO_DIRECTWRITE) - struct IDWriteFactory; - struct IDWriteGdiInterop; -#endif - -QT_BEGIN_NAMESPACE - -class QWindowsFontEngineData -{ - Q_DISABLE_COPY(QWindowsFontEngineData) -public: - QWindowsFontEngineData(); - ~QWindowsFontEngineData(); - - uint pow_gamma[256]; - - bool clearTypeEnabled; - qreal fontSmoothingGamma; - HDC hdc; -#if !defined(QT_NO_DIRECTWRITE) - IDWriteFactory *directWriteFactory; - IDWriteGdiInterop *directWriteGdiInterop; -#endif -}; - -class QWindowsFontDatabase : public QPlatformFontDatabase -{ -public: - QWindowsFontDatabase(); - ~QWindowsFontDatabase(); - - void populateFontDatabase() Q_DECL_OVERRIDE; - void populateFamily(const QString &familyName) Q_DECL_OVERRIDE; - QFontEngineMulti *fontEngineMulti(QFontEngine *fontEngine, QChar::Script script) Q_DECL_OVERRIDE; - QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) Q_DECL_OVERRIDE; - QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) Q_DECL_OVERRIDE; - QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const Q_DECL_OVERRIDE; - QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName) Q_DECL_OVERRIDE; - void releaseHandle(void *handle) Q_DECL_OVERRIDE; - QString fontDir() const Q_DECL_OVERRIDE; - - QFont defaultFont() const Q_DECL_OVERRIDE { return systemDefaultFont(); } - bool fontsAlwaysScalable() const Q_DECL_OVERRIDE; - void derefUniqueFont(const QString &uniqueFont); - void refUniqueFont(const QString &uniqueFont); - - static QFont systemDefaultFont(); - - static QFontEngine *createEngine(const QFontDef &request, - int dpi, - const QSharedPointer &data); - - static HFONT systemFont(); - static QFont LOGFONT_to_QFont(const LOGFONT& lf, int verticalDPI = 0); - - static qreal fontSmoothingGamma(); - static LOGFONT fontDefToLOGFONT(const QFontDef &fontDef); - - static QStringList extraTryFontsForFamily(const QString &family); - static QString familyForStyleHint(QFont::StyleHint styleHint); - -private: - void populateFamily(const QString &familyName, bool registerAlias); - void removeApplicationFonts(); - - struct WinApplicationFont { - HANDLE handle; - QString fileName; - }; - - QList m_applicationFonts; - - struct UniqueFontData { - HANDLE handle; - QAtomicInt refCount; - }; - - QMap m_uniqueFontData; -}; - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug, const QFontDef &def); -#endif - -QT_END_NAMESPACE - -#endif // QWINDOWSFONTDATABASE_H diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp deleted file mode 100644 index bc0e5cc523..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwindowsfontdatabase_ft.h" -#include "qwindowsfontdatabase.h" -#include "qwindowscontext.h" - -#include -#include FT_TRUETYPE_TABLES_H - -#include -#include -#include -#include -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -static inline QFontDatabase::WritingSystem writingSystemFromCharSet(uchar charSet) -{ - switch (charSet) { - case ANSI_CHARSET: - case EASTEUROPE_CHARSET: - case BALTIC_CHARSET: - case TURKISH_CHARSET: - return QFontDatabase::Latin; - case GREEK_CHARSET: - return QFontDatabase::Greek; - case RUSSIAN_CHARSET: - return QFontDatabase::Cyrillic; - case HEBREW_CHARSET: - return QFontDatabase::Hebrew; - case ARABIC_CHARSET: - return QFontDatabase::Arabic; - case THAI_CHARSET: - return QFontDatabase::Thai; - case GB2312_CHARSET: - return QFontDatabase::SimplifiedChinese; - case CHINESEBIG5_CHARSET: - return QFontDatabase::TraditionalChinese; - case SHIFTJIS_CHARSET: - return QFontDatabase::Japanese; - case HANGUL_CHARSET: - case JOHAB_CHARSET: - return QFontDatabase::Korean; - case VIETNAMESE_CHARSET: - return QFontDatabase::Vietnamese; - case SYMBOL_CHARSET: - return QFontDatabase::Symbol; - default: - break; - } - return QFontDatabase::Any; -} - -static FontFile * createFontFile(const QString &fileName, int index) -{ - FontFile *fontFile = new FontFile; - fontFile->fileName = fileName; - fontFile->indexValue = index; - return fontFile; -} - -extern bool localizedName(const QString &name); -extern QString getEnglishName(const QString &familyName, bool includeStyle = false); - -namespace { -struct FontKey -{ - QString fileName; - QStringList fontNames; -}; -} // namespace - -typedef QVector FontKeys; - -static FontKeys &fontKeys() -{ - static FontKeys result; - if (result.isEmpty()) { - const QSettings fontRegistry(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"), - QSettings::NativeFormat); - const QStringList allKeys = fontRegistry.allKeys(); - const QString trueType = QStringLiteral("(TrueType)"); -#ifndef QT_NO_REGULAREXPRESSION - const QRegularExpression sizeListMatch(QStringLiteral("\\s(\\d+,)+\\d+")); -#else - const QRegExp sizeListMatch(QLatin1String("\\s(\\d+,)+\\d+")); -#endif - Q_ASSERT(sizeListMatch.isValid()); - const int size = allKeys.size(); - result.reserve(size); - for (int i = 0; i < size; ++i) { - FontKey fontKey; - const QString ®istryFontKey = allKeys.at(i); - fontKey.fileName = fontRegistry.value(registryFontKey).toString(); - QString realKey = registryFontKey; - realKey.remove(trueType); - realKey.remove(sizeListMatch); - const auto fontNames = QStringRef(&realKey).trimmed().split(QLatin1Char('&')); - fontKey.fontNames.reserve(fontNames.size()); - for (const QStringRef &fontName : fontNames) - fontKey.fontNames.append(fontName.trimmed().toString()); - result.append(fontKey); - } - } - return result; -} - -static const FontKey *findFontKey(const QString &name, int *indexIn = Q_NULLPTR) -{ - const FontKeys &keys = fontKeys(); - for (auto it = keys.constBegin(), cend = keys.constEnd(); it != cend; ++it) { - const int index = it->fontNames.indexOf(name); - if (index >= 0) { - if (indexIn) - *indexIn = index; - return &(*it); - } - } - if (indexIn) - *indexIn = -1; - return Q_NULLPTR; -} - -static bool addFontToDatabase(const QString &faceName, - const QString &styleName, - const QString &fullName, - uchar charSet, - const TEXTMETRIC *textmetric, - const FONTSIGNATURE *signature, - int type, - bool registerAlias) -{ - // the "@family" fonts are just the same as "family". Ignore them. - if (faceName.isEmpty() || faceName.at(0) == QLatin1Char('@') || faceName.startsWith(QLatin1String("WST_"))) - return false; - - static const int SMOOTH_SCALABLE = 0xffff; - const QString foundryName; // No such concept. - const bool fixed = !(textmetric->tmPitchAndFamily & TMPF_FIXED_PITCH); - const bool ttf = (textmetric->tmPitchAndFamily & TMPF_TRUETYPE); - const bool scalable = textmetric->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); - const int size = scalable ? SMOOTH_SCALABLE : textmetric->tmHeight; - const QFont::Style style = textmetric->tmItalic ? QFont::StyleItalic : QFont::StyleNormal; - const bool antialias = false; - const QFont::Weight weight = QPlatformFontDatabase::weightFromInteger(textmetric->tmWeight); - const QFont::Stretch stretch = QFont::Unstretched; - -#ifndef QT_NO_DEBUG_STREAM - if (QWindowsContext::verbose > 2) { - QString message; - QTextStream str(&message); - str << __FUNCTION__ << ' ' << faceName << "::" << fullName << ' ' << charSet << " TTF=" << ttf; - if (type & DEVICE_FONTTYPE) - str << " DEVICE"; - if (type & RASTER_FONTTYPE) - str << " RASTER"; - if (type & TRUETYPE_FONTTYPE) - str << " TRUETYPE"; - str << " scalable=" << scalable << " Size=" << size - << " Style=" << style << " Weight=" << weight - << " stretch=" << stretch; - qCDebug(lcQpaFonts) << message; - } -#endif - - QString englishName; - if (registerAlias & ttf && localizedName(faceName)) - englishName = getEnglishName(faceName); - - QSupportedWritingSystems writingSystems; - if (type & TRUETYPE_FONTTYPE) { - Q_ASSERT(signature); - quint32 unicodeRange[4] = { - signature->fsUsb[0], signature->fsUsb[1], - signature->fsUsb[2], signature->fsUsb[3] - }; - quint32 codePageRange[2] = { - signature->fsCsb[0], signature->fsCsb[1] - }; - writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); - // ### Hack to work around problem with Thai text on Windows 7. Segoe UI contains - // the symbol for Baht, and Windows thus reports that it supports the Thai script. - // Since it's the default UI font on this platform, most widgets will be unable to - // display Thai text by default. As a temporary work around, we special case Segoe UI - // and remove the Thai script from its list of supported writing systems. - if (writingSystems.supported(QFontDatabase::Thai) && - faceName == QLatin1String("Segoe UI")) - writingSystems.setSupported(QFontDatabase::Thai, false); - } else { - const QFontDatabase::WritingSystem ws = writingSystemFromCharSet(charSet); - if (ws != QFontDatabase::Any) - writingSystems.setSupported(ws); - } - - int index = 0; - const FontKey *key = findFontKey(fullName, &index); - if (!key) { - // On non-English locales, the styles of the font may be localized in enumeration, but - // not in the registry. - QLocale systemLocale = QLocale::system(); - if (systemLocale.language() != QLocale::C - && systemLocale.language() != QLocale::English - && styleName != QLatin1String("Italic") - && styleName != QLatin1String("Bold")) { - key = findFontKey(getEnglishName(fullName, true), &index); - } - if (!key) - key = findFontKey(faceName, &index); - if (!key && !registerAlias && englishName.isEmpty() && localizedName(faceName)) - englishName = getEnglishName(faceName); - if (!key && !englishName.isEmpty()) - key = findFontKey(englishName, &index); - if (!key) - return false; - } - QString value = key->fileName; - if (value.isEmpty()) - return false; - - if (!QDir::isAbsolutePath(value)) - value.prepend(QFile::decodeName(qgetenv("windir") + "\\Fonts\\")); - - QPlatformFontDatabase::registerFont(faceName, styleName, foundryName, weight, style, stretch, - antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - - // add fonts windows can generate for us: - if (weight <= QFont::DemiBold && styleName.isEmpty()) - QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, style, stretch, - antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - - if (style != QFont::StyleItalic && styleName.isEmpty()) - QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, QFont::StyleItalic, stretch, - antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - - if (weight <= QFont::DemiBold && style != QFont::StyleItalic && styleName.isEmpty()) - QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch, - antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); - - if (!englishName.isEmpty()) - QPlatformFontDatabase::registerAliasToFontFamily(faceName, englishName); - - return true; -} - -static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *textmetric, - DWORD type, LPARAM) -{ - const ENUMLOGFONTEX *f = reinterpret_cast(logFont); - const QString faceName = QString::fromWCharArray(f->elfLogFont.lfFaceName); - const QString styleName = QString::fromWCharArray(f->elfStyle); - const QString fullName = QString::fromWCharArray(f->elfFullName); - const uchar charSet = f->elfLogFont.lfCharSet; - - // NEWTEXTMETRICEX (passed for TT fonts) is a NEWTEXTMETRIC, which according - // to the documentation is identical to a TEXTMETRIC except for the last four - // members, which we don't use anyway - const FONTSIGNATURE *signature = Q_NULLPTR; - if (type & TRUETYPE_FONTTYPE) - signature = &reinterpret_cast(textmetric)->ntmFontSig; - addFontToDatabase(faceName, styleName, fullName, charSet, textmetric, signature, type, false); - - // keep on enumerating - return 1; -} - -/*! - \brief Populate font database using EnumFontFamiliesEx(). - - Normally, leaving the name empty should enumerate - all fonts, however, system fonts like "MS Shell Dlg 2" - are only found when specifying the name explicitly. -*/ - -void QWindowsFontDatabaseFT::populateFamily(const QString &familyName) -{ - qCDebug(lcQpaFonts) << familyName; - if (familyName.size() >= LF_FACESIZE) { - qCWarning(lcQpaFonts) << "Unable to enumerate family '" << familyName << '\''; - return; - } - HDC dummy = GetDC(0); - LOGFONT lf; - lf.lfCharSet = DEFAULT_CHARSET; - familyName.toWCharArray(lf.lfFaceName); - lf.lfFaceName[familyName.size()] = 0; - lf.lfPitchAndFamily = 0; - EnumFontFamiliesEx(dummy, &lf, storeFont, 0, 0); - ReleaseDC(0, dummy); -} - -namespace { -// Context for enumerating system fonts, records whether the default font has been -// encountered, which is normally not enumerated. -struct PopulateFamiliesContext -{ - PopulateFamiliesContext(const QString &f) : systemDefaultFont(f), seenSystemDefaultFont(false) {} - - QString systemDefaultFont; - bool seenSystemDefaultFont; -}; -} // namespace - -// Delayed population of font families - -static int QT_WIN_CALLBACK populateFontFamilies(const LOGFONT *logFont, const TEXTMETRIC *textmetric, - DWORD, LPARAM lparam) -{ - const ENUMLOGFONTEX *f = reinterpret_cast(logFont); - // the "@family" fonts are just the same as "family". Ignore them. - const wchar_t *faceNameW = f->elfLogFont.lfFaceName; - if (faceNameW[0] && faceNameW[0] != L'@' && wcsncmp(faceNameW, L"WST_", 4)) { - // Register only font families for which a font file exists for delayed population - const bool ttf = textmetric->tmPitchAndFamily & TMPF_TRUETYPE; - const QString faceName = QString::fromWCharArray(faceNameW); - const FontKey *key = findFontKey(faceName); - if (!key) { - key = findFontKey(QString::fromWCharArray(f->elfFullName)); - if (!key && ttf && localizedName(faceName)) - key = findFontKey(getEnglishName(faceName)); - } - if (key) { - QPlatformFontDatabase::registerFontFamily(faceName); - PopulateFamiliesContext *context = reinterpret_cast(lparam); - if (!context->seenSystemDefaultFont && faceName == context->systemDefaultFont) - context->seenSystemDefaultFont = true; - - // Register current font's english name as alias - if (ttf && localizedName(faceName)) { - const QString englishName = getEnglishName(faceName); - if (!englishName.isEmpty()) { - QPlatformFontDatabase::registerAliasToFontFamily(faceName, englishName); - // Check whether the system default font name is an alias of the current font family name, - // as on Chinese Windows, where the system font "SimSun" is an alias to a font registered under a local name - if (!context->seenSystemDefaultFont && englishName == context->systemDefaultFont) - context->seenSystemDefaultFont = true; - } - } - } - } - return 1; // continue -} - -void QWindowsFontDatabaseFT::populateFontDatabase() -{ - HDC dummy = GetDC(0); - LOGFONT lf; - lf.lfCharSet = DEFAULT_CHARSET; - lf.lfFaceName[0] = 0; - lf.lfPitchAndFamily = 0; - PopulateFamiliesContext context(QWindowsFontDatabase::systemDefaultFont().family()); - EnumFontFamiliesEx(dummy, &lf, populateFontFamilies, reinterpret_cast(&context), 0); - ReleaseDC(0, dummy); - // Work around EnumFontFamiliesEx() not listing the system font - if (!context.seenSystemDefaultFont) - QPlatformFontDatabase::registerFontFamily(context.systemDefaultFont); -} - -QFontEngine * QWindowsFontDatabaseFT::fontEngine(const QFontDef &fontDef, void *handle) -{ - QFontEngine *fe = QBasicFontDatabase::fontEngine(fontDef, handle); - qCDebug(lcQpaFonts) << __FUNCTION__ << "FONTDEF" << fontDef.family << fe << handle; - return fe; -} - -QFontEngine *QWindowsFontDatabaseFT::fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) -{ - QFontEngine *fe = QBasicFontDatabase::fontEngine(fontData, pixelSize, hintingPreference); - qCDebug(lcQpaFonts) << __FUNCTION__ << "FONTDATA" << fontData << pixelSize << hintingPreference << fe; - return fe; -} - -QStringList QWindowsFontDatabaseFT::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const -{ - QStringList result; - result.append(QWindowsFontDatabase::familyForStyleHint(styleHint)); - result.append(QWindowsFontDatabase::extraTryFontsForFamily(family)); - result.append(QBasicFontDatabase::fallbacksForFamily(family, style, styleHint, script)); - - qCDebug(lcQpaFonts) << __FUNCTION__ << family << style << styleHint - << script << result; - - return result; -} -QString QWindowsFontDatabaseFT::fontDir() const -{ - const QString result = QLatin1String(qgetenv("windir")) + QLatin1String("/Fonts");//QPlatformFontDatabase::fontDir(); - qCDebug(lcQpaFonts) << __FUNCTION__ << result; - return result; -} - -QFont QWindowsFontDatabaseFT::defaultFont() const -{ - return QWindowsFontDatabase::systemDefaultFont(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h b/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h deleted file mode 100644 index 90008e20a4..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontdatabase_ft.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSFONTDATABASEFT_H -#define QWINDOWSFONTDATABASEFT_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QWindowsFontDatabaseFT : public QBasicFontDatabase -{ -public: - void populateFontDatabase() Q_DECL_OVERRIDE; - void populateFamily(const QString &familyName) Q_DECL_OVERRIDE; - QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) Q_DECL_OVERRIDE; - QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, - QFont::HintingPreference hintingPreference) Q_DECL_OVERRIDE; - - QStringList fallbacksForFamily(const QString &family, QFont::Style style, - QFont::StyleHint styleHint, - QChar::Script script) const Q_DECL_OVERRIDE; - - QString fontDir() const Q_DECL_OVERRIDE; - QFont defaultFont() const Q_DECL_OVERRIDE; -}; - -QT_END_NAMESPACE - -#endif // QWINDOWSFONTDATABASEFT_H diff --git a/src/plugins/platforms/windows/qwindowsfontengine.cpp b/src/plugins/platforms/windows/qwindowsfontengine.cpp deleted file mode 100644 index f5d1ed9fad..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontengine.cpp +++ /dev/null @@ -1,1328 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwindowsintegration.h" -#include "qwindowsfontengine.h" -#include "qwindowsnativeimage.h" -#include "qwindowscontext.h" -#include "qwindowsfontdatabase.h" -#include -#include "qwindowsfontenginedirectwrite.h" - -#include // glyph_metrics_t -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - -#if !defined(QT_NO_DIRECTWRITE) -# include -#endif - -QT_BEGIN_NAMESPACE - -//### mingw needed define -#ifndef TT_PRIM_CSPLINE -#define TT_PRIM_CSPLINE 3 -#endif - -// GetFontData expects the tags in little endian ;( -#define MAKE_LITTLE_ENDIAN_TAG(ch1, ch2, ch3, ch4) (\ - (((quint32)(ch4)) << 24) | \ - (((quint32)(ch3)) << 16) | \ - (((quint32)(ch2)) << 8) | \ - ((quint32)(ch1)) \ - ) - -// common DC for all fonts - -typedef BOOL (WINAPI *PtrGetCharWidthI)(HDC, UINT, UINT, LPWORD, LPINT); -static PtrGetCharWidthI ptrGetCharWidthI = 0; -static bool resolvedGetCharWidthI = false; - -static void resolveGetCharWidthI() -{ - if (resolvedGetCharWidthI) - return; - resolvedGetCharWidthI = true; - ptrGetCharWidthI = (PtrGetCharWidthI)QSystemLibrary::resolve(QStringLiteral("gdi32"), "GetCharWidthI"); -} - -static inline quint16 getUShort(unsigned char *p) -{ - quint16 val; - val = *p++ << 8; - val |= *p; - - return val; -} - -// general font engine - -QFixed QWindowsFontEngine::lineThickness() const -{ - if(lineWidth > 0) - return lineWidth; - - return QFontEngine::lineThickness(); -} - -static OUTLINETEXTMETRIC *getOutlineTextMetric(HDC hdc) -{ - int size; - size = GetOutlineTextMetrics(hdc, 0, 0); - OUTLINETEXTMETRIC *otm = (OUTLINETEXTMETRIC *)malloc(size); - GetOutlineTextMetrics(hdc, size, otm); - return otm; -} - -bool QWindowsFontEngine::hasCFFTable() const -{ - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - return GetFontData(hdc, MAKE_LITTLE_ENDIAN_TAG('C', 'F', 'F', ' '), 0, 0, 0) != GDI_ERROR; -} - -bool QWindowsFontEngine::hasCMapTable() const -{ - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - return GetFontData(hdc, MAKE_LITTLE_ENDIAN_TAG('c', 'm', 'a', 'p'), 0, 0, 0) != GDI_ERROR; -} - -bool QWindowsFontEngine::hasGlyfTable() const -{ - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - return GetFontData(hdc, MAKE_LITTLE_ENDIAN_TAG('g', 'l', 'y', 'f'), 0, 0, 0) != GDI_ERROR; -} - -bool QWindowsFontEngine::hasEbdtTable() const -{ - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - return GetFontData(hdc, MAKE_LITTLE_ENDIAN_TAG('E', 'B', 'D', 'T'), 0, 0, 0) != GDI_ERROR; -} - -static inline QString stringFromOutLineTextMetric(const OUTLINETEXTMETRIC *otm, PSTR offset) -{ - const uchar *p = reinterpret_cast(otm) + quintptr(offset); - return QString::fromWCharArray(reinterpret_cast(p)); -} - -void QWindowsFontEngine::getCMap() -{ - ttf = (bool)(tm.tmPitchAndFamily & TMPF_TRUETYPE) || hasCMapTable(); - - cffTable = hasCFFTable(); - - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - bool symb = false; - if (ttf) { - cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); - cmap = QFontEngine::getCMap(reinterpret_cast(cmapTable.constData()), - cmapTable.size(), &symb, &cmapSize); - } - if (!cmap) { - ttf = false; - symb = false; - } - symbol = symb; - designToDevice = 1; - _faceId.index = 0; - if(cmap) { - OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc); - unitsPerEm = int(otm->otmEMSquare); - const QFixed unitsPerEmF(unitsPerEm); - designToDevice = unitsPerEmF / QFixed::fromReal(fontDef.pixelSize); - x_height = int(otm->otmsXHeight); - loadKerningPairs(designToDevice); - _faceId.filename = QFile::encodeName(stringFromOutLineTextMetric(otm, otm->otmpFullName)); - lineWidth = otm->otmsUnderscoreSize; - fsType = otm->otmfsType; - free(otm); - - } else { - unitsPerEm = tm.tmHeight; - } -} - -int QWindowsFontEngine::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout *glyphs) const -{ - int glyph_pos = 0; - { - if (symbol) { - QStringIterator it(str, str + numChars); - while (it.hasNext()) { - const uint uc = it.next(); - glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, cmapSize, uc); - if(!glyphs->glyphs[glyph_pos] && uc < 0x100) - glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, cmapSize, uc + 0xf000); - ++glyph_pos; - } - } else if (ttf) { - QStringIterator it(str, str + numChars); - while (it.hasNext()) { - const uint uc = it.next(); - glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, cmapSize, uc); - ++glyph_pos; - } - } else { - QStringIterator it(str, str + numChars); - while (it.hasNext()) { - const uint uc = it.next(); - if (uc >= tm.tmFirstChar && uc <= tm.tmLastChar) - glyphs->glyphs[glyph_pos] = uc; - else - glyphs->glyphs[glyph_pos] = 0; - ++glyph_pos; - } - } - } - glyphs->numGlyphs = glyph_pos; - return glyph_pos; -} - -/*! - \class QWindowsFontEngine - \brief Standard Windows font engine. - \internal - \ingroup qt-lighthouse-win - - Will probably be superseded by a common Free Type font engine in Qt 5.X. -*/ - -QWindowsFontEngine::QWindowsFontEngine(const QString &name, - LOGFONT lf, - const QSharedPointer &fontEngineData) - : QFontEngine(Win), - m_fontEngineData(fontEngineData), - _name(name), - hfont(0), - m_logfont(lf), - ttf(0), - hasOutline(0), - cmap(0), - cmapSize(0), - lbearing(SHRT_MIN), - rbearing(SHRT_MIN), - x_height(-1), - synthesized_flags(-1), - lineWidth(-1), - widthCache(0), - widthCacheSize(0), - designAdvances(0), - designAdvancesSize(0) -{ - qCDebug(lcQpaFonts) << __FUNCTION__ << name << lf.lfHeight; - hfont = CreateFontIndirect(&m_logfont); - if (!hfont) { - qErrnoWarning("%s: CreateFontIndirect failed for family '%s'", __FUNCTION__, qPrintable(name)); - hfont = QWindowsFontDatabase::systemFont(); - } - - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - const BOOL res = GetTextMetrics(hdc, &tm); - if (!res) { - qErrnoWarning("%s: GetTextMetrics failed", __FUNCTION__); - ZeroMemory(&tm, sizeof(TEXTMETRIC)); - } - - fontDef.pixelSize = -lf.lfHeight; - fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH); - - cache_cost = tm.tmHeight * tm.tmAveCharWidth * 2000; - getCMap(); - - if (!resolvedGetCharWidthI) - resolveGetCharWidthI(); - - // ### Properties accessed by QWin32PrintEngine (QtPrintSupport) - QVariantMap userData; - userData.insert(QStringLiteral("logFont"), QVariant::fromValue(m_logfont)); - userData.insert(QStringLiteral("hFont"), QVariant::fromValue(hfont)); - userData.insert(QStringLiteral("trueType"), QVariant(bool(ttf))); - setUserData(userData); - - hasUnreliableOutline = hasGlyfTable() && hasEbdtTable(); -} - -QWindowsFontEngine::~QWindowsFontEngine() -{ - if (designAdvances) - free(designAdvances); - - if (widthCache) - free(widthCache); - - // make sure we aren't by accident still selected - SelectObject(m_fontEngineData->hdc, QWindowsFontDatabase::systemFont()); - - if (!DeleteObject(hfont)) - qErrnoWarning("%s: QFontEngineWin: failed to delete font...", __FUNCTION__); - qCDebug(lcQpaFonts) << __FUNCTION__ << _name; - - if (!uniqueFamilyName.isEmpty()) { - QPlatformFontDatabase *pfdb = QWindowsIntegration::instance()->fontDatabase(); - static_cast(pfdb)->derefUniqueFont(uniqueFamilyName); - } -} - -glyph_t QWindowsFontEngine::glyphIndex(uint ucs4) const -{ - glyph_t glyph = 0; - - if (symbol) { - glyph = getTrueTypeGlyphIndex(cmap, cmapSize, ucs4); - if (glyph == 0 && ucs4 < 0x100) - glyph = getTrueTypeGlyphIndex(cmap, cmapSize, ucs4 + 0xf000); - } else if (ttf) { - glyph = getTrueTypeGlyphIndex(cmap, cmapSize, ucs4); - } else if (ucs4 >= tm.tmFirstChar && ucs4 <= tm.tmLastChar) { - glyph = ucs4; - } - - return glyph; -} - -HGDIOBJ QWindowsFontEngine::selectDesignFont() const -{ - LOGFONT f = m_logfont; - f.lfHeight = -unitsPerEm; - f.lfWidth = 0; - HFONT designFont = CreateFontIndirect(&f); - return SelectObject(m_fontEngineData->hdc, designFont); -} - -bool QWindowsFontEngine::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const -{ - Q_ASSERT(glyphs->numGlyphs >= *nglyphs); - if (*nglyphs < len) { - *nglyphs = len; - return false; - } - - glyphs->numGlyphs = *nglyphs; - *nglyphs = getGlyphIndexes(str, len, glyphs); - - if (!(flags & GlyphIndicesOnly)) - recalcAdvances(glyphs, flags); - - return true; -} - -inline void calculateTTFGlyphWidth(HDC hdc, UINT glyph, int &width) -{ - if (ptrGetCharWidthI) - ptrGetCharWidthI(hdc, glyph, 1, 0, &width); -} - -void QWindowsFontEngine::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags flags) const -{ - HGDIOBJ oldFont = 0; - HDC hdc = m_fontEngineData->hdc; - if (ttf && (flags & DesignMetrics)) { - for(int i = 0; i < glyphs->numGlyphs; i++) { - unsigned int glyph = glyphs->glyphs[i]; - if(int(glyph) >= designAdvancesSize) { - const int newSize = int(glyph + 256) >> 8 << 8; - designAdvances = reinterpret_cast(realloc(designAdvances, size_t(newSize) * sizeof(QFixed))); - Q_CHECK_PTR(designAdvances); - for(int i = designAdvancesSize; i < newSize; ++i) - designAdvances[i] = -1000000; - designAdvancesSize = newSize; - } - if (designAdvances[glyph] < -999999) { - if (!oldFont) - oldFont = selectDesignFont(); - - int width = 0; - calculateTTFGlyphWidth(hdc, glyph, width); - designAdvances[glyph] = QFixed(width) / designToDevice; - } - glyphs->advances[i] = designAdvances[glyph]; - } - if(oldFont) - DeleteObject(SelectObject(hdc, oldFont)); - } else { - for(int i = 0; i < glyphs->numGlyphs; i++) { - unsigned int glyph = glyphs->glyphs[i]; - - if (glyph >= widthCacheSize) { - const uint newSize = (glyph + 256) >> 8 << 8; - widthCache = reinterpret_cast(realloc(widthCache, newSize * sizeof(QFixed))); - Q_CHECK_PTR(widthCache); - memset(widthCache + widthCacheSize, 0, newSize - widthCacheSize); - widthCacheSize = newSize; - } - glyphs->advances[i] = widthCache[glyph]; - // font-width cache failed - if (glyphs->advances[i].value() == 0) { - int width = 0; - if (!oldFont) - oldFont = SelectObject(hdc, hfont); - - if (!ttf) { - QChar ch[2] = { ushort(glyph), 0 }; - int chrLen = 1; - if (QChar::requiresSurrogates(glyph)) { - ch[0] = QChar::highSurrogate(glyph); - ch[1] = QChar::lowSurrogate(glyph); - ++chrLen; - } - SIZE size = {0, 0}; - GetTextExtentPoint32(hdc, reinterpret_cast(ch), chrLen, &size); - width = size.cx; - } else { - calculateTTFGlyphWidth(hdc, glyph, width); - } - glyphs->advances[i] = width; - // if glyph's within cache range, store it for later - if (width > 0 && width < 0x100) - widthCache[glyph] = uchar(width); - } - } - - if (oldFont) - SelectObject(hdc, oldFont); - } -} - -glyph_metrics_t QWindowsFontEngine::boundingBox(const QGlyphLayout &glyphs) -{ - if (glyphs.numGlyphs == 0) - return glyph_metrics_t(); - - QFixed w = 0; - for (int i = 0; i < glyphs.numGlyphs; ++i) - w += glyphs.effectiveAdvance(i); - - return glyph_metrics_t(0, -tm.tmAscent, w - lastRightBearing(glyphs), tm.tmHeight, w, 0); -} - -bool QWindowsFontEngine::getOutlineMetrics(glyph_t glyph, const QTransform &t, glyph_metrics_t *metrics) const -{ - Q_ASSERT(metrics != 0); - - HDC hdc = m_fontEngineData->hdc; - - GLYPHMETRICS gm; - DWORD res = 0; - MAT2 mat; - mat.eM11.value = mat.eM22.value = 1; - mat.eM11.fract = mat.eM22.fract = 0; - mat.eM21.value = mat.eM12.value = 0; - mat.eM21.fract = mat.eM12.fract = 0; - - if (t.type() > QTransform::TxTranslate) { - // We need to set the transform using the HDC's world - // matrix rather than using the MAT2 above, because the - // results provided when transforming via MAT2 does not - // match the glyphs that are drawn using a WorldTransform - XFORM xform; - xform.eM11 = FLOAT(t.m11()); - xform.eM12 = FLOAT(t.m12()); - xform.eM21 = FLOAT(t.m21()); - xform.eM22 = FLOAT(t.m22()); - xform.eDx = 0; - xform.eDy = 0; - SetGraphicsMode(hdc, GM_ADVANCED); - SetWorldTransform(hdc, &xform); - } - - uint format = GGO_METRICS; - if (ttf) - format |= GGO_GLYPH_INDEX; - res = GetGlyphOutline(hdc, glyph, format, &gm, 0, 0, &mat); - - if (t.type() > QTransform::TxTranslate) { - XFORM xform; - xform.eM11 = xform.eM22 = 1; - xform.eM12 = xform.eM21 = xform.eDx = xform.eDy = 0; - SetWorldTransform(hdc, &xform); - SetGraphicsMode(hdc, GM_COMPATIBLE); - } - - if (res != GDI_ERROR) { - *metrics = glyph_metrics_t(gm.gmptGlyphOrigin.x, -gm.gmptGlyphOrigin.y, - int(gm.gmBlackBoxX), int(gm.gmBlackBoxY), - gm.gmCellIncX, gm.gmCellIncY); - return true; - } else { - return false; - } -} - -glyph_metrics_t QWindowsFontEngine::boundingBox(glyph_t glyph, const QTransform &t) -{ - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - - glyph_metrics_t glyphMetrics; - bool success = getOutlineMetrics(glyph, t, &glyphMetrics); - - if (!ttf && !success) { - // Bitmap fonts - wchar_t ch = wchar_t(glyph); - ABCFLOAT abc; - GetCharABCWidthsFloat(hdc, ch, ch, &abc); - int width = qRound(abc.abcfB); - - return glyph_metrics_t(QFixed::fromReal(abc.abcfA), -tm.tmAscent, width, tm.tmHeight, width, 0).transformed(t); - } - - return glyphMetrics; -} - -QFixed QWindowsFontEngine::ascent() const -{ - return tm.tmAscent; -} - -QFixed QWindowsFontEngine::descent() const -{ - return tm.tmDescent; -} - -QFixed QWindowsFontEngine::leading() const -{ - return tm.tmExternalLeading; -} - -namespace { -# pragma pack(1) - - struct OS2Table - { - quint16 version; - qint16 avgCharWidth; - quint16 weightClass; - quint16 widthClass; - quint16 type; - qint16 subscriptXSize; - qint16 subscriptYSize; - qint16 subscriptXOffset; - qint16 subscriptYOffset; - qint16 superscriptXSize; - qint16 superscriptYSize; - qint16 superscriptXOffset; - qint16 superscriptYOffset; - qint16 strikeOutSize; - qint16 strikeOutPosition; - qint16 familyClass; - quint8 panose[10]; - quint32 unicodeRanges[4]; - quint8 vendorID[4]; - quint16 selection; - quint16 firstCharIndex; - quint16 lastCharIndex; - qint16 typoAscender; - qint16 typoDescender; - qint16 typoLineGap; - quint16 winAscent; - quint16 winDescent; - quint32 codepageRanges[2]; - qint16 height; - qint16 capHeight; - quint16 defaultChar; - quint16 breakChar; - quint16 maxContext; - }; - -# pragma pack() -} - -QFixed QWindowsFontEngine::capHeight() const -{ - const QByteArray tableData = getSfntTable(MAKE_TAG('O', 'S', '/', '2')); - if (size_t(tableData.size()) >= sizeof(OS2Table)) { - const OS2Table *table = reinterpret_cast(tableData.constData()); - if (qFromBigEndian(table->version) >= 2) { - qint16 capHeight = qFromBigEndian(table->capHeight); - if (capHeight > 0) - return QFixed(capHeight) / designToDevice; - } - } - return calculatedCapHeight(); -} - -QFixed QWindowsFontEngine::xHeight() const -{ - if(x_height >= 0) - return x_height; - return QFontEngine::xHeight(); -} - -QFixed QWindowsFontEngine::averageCharWidth() const -{ - return tm.tmAveCharWidth; -} - -qreal QWindowsFontEngine::maxCharWidth() const -{ - return tm.tmMaxCharWidth; -} - -enum { max_font_count = 256 }; -static const ushort char_table[] = { - 40, - 67, - 70, - 75, - 86, - 88, - 89, - 91, - 102, - 114, - 124, - 127, - 205, - 645, - 884, - 922, - 1070, - 12386, - 0 -}; - -static const int char_table_entries = sizeof(char_table)/sizeof(ushort); - -#ifndef Q_CC_MINGW -void QWindowsFontEngine::getGlyphBearings(glyph_t glyph, qreal *leftBearing, qreal *rightBearing) -{ - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - - if (ttf) { - ABC abcWidths; - GetCharABCWidthsI(hdc, glyph, 1, 0, &abcWidths); - if (leftBearing) - *leftBearing = abcWidths.abcA; - if (rightBearing) - *rightBearing = abcWidths.abcC; - } else { - QFontEngine::getGlyphBearings(glyph, leftBearing, rightBearing); - } -} -#endif // Q_CC_MINGW - -bool QWindowsFontEngine::hasUnreliableGlyphOutline() const -{ - return hasUnreliableOutline || QFontEngine::hasUnreliableGlyphOutline(); -} - -qreal QWindowsFontEngine::minLeftBearing() const -{ - if (lbearing == SHRT_MIN) - minRightBearing(); // calculates both - - return lbearing; -} - -qreal QWindowsFontEngine::minRightBearing() const -{ - if (rbearing == SHRT_MIN) { - int ml = 0; - int mr = 0; - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - if (ttf) { - ABC *abc = 0; - int n = tm.tmLastChar - tm.tmFirstChar; - if (n <= max_font_count) { - abc = new ABC[n+1]; - GetCharABCWidths(hdc, tm.tmFirstChar, tm.tmLastChar, abc); - } else { - abc = new ABC[char_table_entries+1]; - for(int i = 0; i < char_table_entries; i++) - GetCharABCWidths(hdc, char_table[i], char_table[i], abc + i); - n = char_table_entries; - } - ml = abc[0].abcA; - mr = abc[0].abcC; - for (int i = 1; i < n; i++) { - if (abc[i].abcA + abc[i].abcB + abc[i].abcC != 0) { - ml = qMin(ml,abc[i].abcA); - mr = qMin(mr,abc[i].abcC); - } - } - delete [] abc; - } else { - ABCFLOAT *abc = 0; - int n = tm.tmLastChar - tm.tmFirstChar+1; - if (n <= max_font_count) { - abc = new ABCFLOAT[n]; - GetCharABCWidthsFloat(hdc, tm.tmFirstChar, tm.tmLastChar, abc); - } else { - abc = new ABCFLOAT[char_table_entries]; - for(int i = 0; i < char_table_entries; i++) - GetCharABCWidthsFloat(hdc, char_table[i], char_table[i], abc+i); - n = char_table_entries; - } - float fml = abc[0].abcfA; - float fmr = abc[0].abcfC; - for (int i=1; i(dataBuffer + headerOffset); - - QPointF lastPoint(qt_to_qpointf(ttph->pfxStart, scale)); - path->moveTo(lastPoint + oset); - offset += sizeof(TTPOLYGONHEADER); - while (offset < headerOffset + ttph->cb) { - const TTPOLYCURVE *curve = reinterpret_cast(dataBuffer + offset); - switch (curve->wType) { - case TT_PRIM_LINE: { - for (int i=0; icpfx; ++i) { - QPointF p = qt_to_qpointf(curve->apfx[i], scale) + oset; - path->lineTo(p); - } - break; - } - case TT_PRIM_QSPLINE: { - const QPainterPath::Element &elm = path->elementAt(path->elementCount()-1); - QPointF prev(elm.x, elm.y); - QPointF endPoint; - for (int i=0; icpfx - 1; ++i) { - QPointF p1 = qt_to_qpointf(curve->apfx[i], scale) + oset; - QPointF p2 = qt_to_qpointf(curve->apfx[i+1], scale) + oset; - if (i < curve->cpfx - 2) { - endPoint = QPointF((p1.x() + p2.x()) / 2, (p1.y() + p2.y()) / 2); - } else { - endPoint = p2; - } - - path->quadTo(p1, endPoint); - prev = endPoint; - } - - break; - } - case TT_PRIM_CSPLINE: { - for (int i=0; icpfx; ) { - QPointF p2 = qt_to_qpointf(curve->apfx[i++], scale) + oset; - QPointF p3 = qt_to_qpointf(curve->apfx[i++], scale) + oset; - QPointF p4 = qt_to_qpointf(curve->apfx[i++], scale) + oset; - path->cubicTo(p2, p3, p4); - } - break; - } - default: - qWarning("QFontEngineWin::addOutlineToPath, unhandled switch case"); - } - offset += sizeof(TTPOLYCURVE) + (curve->cpfx-1) * sizeof(POINTFX); - } - path->closeSubpath(); - headerOffset += ttph->cb; - } - delete [] dataBuffer; - - return true; -} - -void QWindowsFontEngine::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, - QPainterPath *path, QTextItem::RenderFlags) -{ - LOGFONT lf = m_logfont; - // The sign must be negative here to make sure we match against character height instead of - // hinted cell height. This ensures that we get linear matching, and we need this for - // paths since we later on apply a scaling transform to the glyph outline to get the - // font at the correct pixel size. - lf.lfHeight = -unitsPerEm; - lf.lfWidth = 0; - HFONT hf = CreateFontIndirect(&lf); - HDC hdc = m_fontEngineData->hdc; - HGDIOBJ oldfont = SelectObject(hdc, hf); - - for(int i = 0; i < nglyphs; ++i) { - if (!addGlyphToPath(glyphs[i], positions[i], hdc, path, ttf, /*metric*/0, - qreal(fontDef.pixelSize) / unitsPerEm)) { - // Some windows fonts, like "Modern", are vector stroke - // fonts, which are reported as TMPF_VECTOR but do not - // support GetGlyphOutline, and thus we set this bit so - // that addOutLineToPath can check it and return safely... - hasOutline = false; - break; - } - } - DeleteObject(SelectObject(hdc, oldfont)); -} - -void QWindowsFontEngine::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, - QPainterPath *path, QTextItem::RenderFlags flags) -{ - if(tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) { - hasOutline = true; - QFontEngine::addOutlineToPath(x, y, glyphs, path, flags); - if (hasOutline) { - // has_outline is set to false if addGlyphToPath gets - // false from GetGlyphOutline, meaning its not an outline - // font. - return; - } - } - QFontEngine::addBitmapFontToPath(x, y, glyphs, path, flags); -} - -QFontEngine::FaceId QWindowsFontEngine::faceId() const -{ - return _faceId; -} - -QT_BEGIN_INCLUDE_NAMESPACE -#include -QT_END_INCLUDE_NAMESPACE - -int QWindowsFontEngine::synthesized() const -{ - if(synthesized_flags == -1) { - synthesized_flags = 0; - if(ttf) { - const DWORD HEAD = MAKE_LITTLE_ENDIAN_TAG('h', 'e', 'a', 'd'); - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - uchar data[4]; - GetFontData(hdc, HEAD, 44, &data, 4); - USHORT macStyle = getUShort(data); - if (tm.tmItalic && !(macStyle & 2)) - synthesized_flags = SynthesizedItalic; - if (fontDef.stretch != 100 && ttf) - synthesized_flags |= SynthesizedStretch; - if (tm.tmWeight >= 500 && !(macStyle & 1)) - synthesized_flags |= SynthesizedBold; - //qDebug() << "font is" << _name << - // "it=" << (macStyle & 2) << fontDef.style << "flags=" << synthesized_flags; - } - } - return synthesized_flags; -} - -QFixed QWindowsFontEngine::emSquareSize() const -{ - return unitsPerEm; -} - -QFontEngine::Properties QWindowsFontEngine::properties() const -{ - LOGFONT lf = m_logfont; - lf.lfHeight = unitsPerEm; - HFONT hf = CreateFontIndirect(&lf); - HDC hdc = m_fontEngineData->hdc; - HGDIOBJ oldfont = SelectObject(hdc, hf); - OUTLINETEXTMETRIC *otm = getOutlineTextMetric(hdc); - Properties p; - p.emSquare = unitsPerEm; - p.italicAngle = otm->otmItalicAngle; - const QByteArray name = stringFromOutLineTextMetric(otm, otm->otmpFamilyName).toLatin1() - + stringFromOutLineTextMetric(otm, otm->otmpStyleName).toLatin1(); - p.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(name); - p.boundingBox = QRectF(otm->otmrcFontBox.left, -otm->otmrcFontBox.top, - otm->otmrcFontBox.right - otm->otmrcFontBox.left, - otm->otmrcFontBox.top - otm->otmrcFontBox.bottom); - p.ascent = otm->otmAscent; - p.descent = -otm->otmDescent; - p.leading = int(otm->otmLineGap); - p.capHeight = 0; - p.lineWidth = otm->otmsUnderscoreSize; - free(otm); - DeleteObject(SelectObject(hdc, oldfont)); - return p; -} - -void QWindowsFontEngine::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) -{ - LOGFONT lf = m_logfont; - lf.lfHeight = -unitsPerEm; - int flags = synthesized(); - if(flags & SynthesizedItalic) - lf.lfItalic = false; - lf.lfWidth = 0; - HFONT hf = CreateFontIndirect(&lf); - HDC hdc = m_fontEngineData->hdc; - HGDIOBJ oldfont = SelectObject(hdc, hf); - QFixedPoint p; - p.x = 0; - p.y = 0; - addGlyphToPath(glyph, p, hdc, path, ttf, metrics); - DeleteObject(SelectObject(hdc, oldfont)); -} - -bool QWindowsFontEngine::getSfntTableData(uint tag, uchar *buffer, uint *length) const -{ - if (!ttf && !cffTable) - return false; - HDC hdc = m_fontEngineData->hdc; - SelectObject(hdc, hfont); - DWORD t = qbswap(tag); - *length = GetFontData(hdc, t, 0, buffer, *length); - Q_ASSERT(*length == GDI_ERROR || int(*length) > 0); - return *length != GDI_ERROR; -} - -#if !defined(CLEARTYPE_QUALITY) -# define CLEARTYPE_QUALITY 5 -#endif - -QWindowsNativeImage *QWindowsFontEngine::drawGDIGlyph(HFONT font, glyph_t glyph, int margin, - const QTransform &t, - QImage::Format mask_format) -{ - Q_UNUSED(mask_format) - glyph_metrics_t gm = boundingBox(glyph); - -// printf(" -> for glyph %4x\n", glyph); - - int gx = gm.x.toInt(); - int gy = gm.y.toInt(); - int iw = gm.width.toInt(); - int ih = gm.height.toInt(); - - if (iw <= 0 || ih <= 0) - return 0; - - bool has_transformation = t.type() > QTransform::TxTranslate; - - unsigned int options = ttf ? ETO_GLYPH_INDEX : 0; - XFORM xform; - - if (has_transformation) { - xform.eM11 = FLOAT(t.m11()); - xform.eM12 = FLOAT(t.m12()); - xform.eM21 = FLOAT(t.m21()); - xform.eM22 = FLOAT(t.m22()); - xform.eDx = margin; - xform.eDy = margin; - - const HDC hdc = m_fontEngineData->hdc; - - SetGraphicsMode(hdc, GM_ADVANCED); - SetWorldTransform(hdc, &xform); - HGDIOBJ old_font = SelectObject(hdc, font); - - const UINT ggo_options = GGO_METRICS | (ttf ? GGO_GLYPH_INDEX : 0); - GLYPHMETRICS tgm; - MAT2 mat; - memset(&mat, 0, sizeof(mat)); - mat.eM11.value = mat.eM22.value = 1; - - const DWORD result = GetGlyphOutline(hdc, glyph, ggo_options, &tgm, 0, 0, &mat); - - XFORM identity = {1, 0, 0, 1, 0, 0}; - SetWorldTransform(hdc, &identity); - SetGraphicsMode(hdc, GM_COMPATIBLE); - SelectObject(hdc, old_font); - - if (result == GDI_ERROR) { - const int errorCode = int(GetLastError()); - qErrnoWarning(errorCode, "QWinFontEngine: unable to query transformed glyph metrics (GetGlyphOutline() failed, error %d)...", errorCode); - return 0; - } - - iw = int(tgm.gmBlackBoxX); - ih = int(tgm.gmBlackBoxY); - - xform.eDx -= tgm.gmptGlyphOrigin.x; - xform.eDy += tgm.gmptGlyphOrigin.y; - } - - // The padding here needs to be kept in sync with the values in alphaMapBoundingBox. - QWindowsNativeImage *ni = new QWindowsNativeImage(iw + 2 * margin, - ih + 2 * margin, - QWindowsNativeImage::systemFormat()); - - /*If cleartype is enabled we use the standard system format even on Windows CE - and not the special textbuffer format we have to use if cleartype is disabled*/ - - ni->image().fill(0xffffffff); - - HDC hdc = ni->hdc(); - - SelectObject(hdc, GetStockObject(NULL_BRUSH)); - SelectObject(hdc, GetStockObject(BLACK_PEN)); - SetTextColor(hdc, RGB(0,0,0)); - SetBkMode(hdc, TRANSPARENT); - SetTextAlign(hdc, TA_BASELINE); - - HGDIOBJ old_font = SelectObject(hdc, font); - - if (has_transformation) { - SetGraphicsMode(hdc, GM_ADVANCED); - SetWorldTransform(hdc, &xform); - ExtTextOut(hdc, 0, 0, options, 0, reinterpret_cast(&glyph), 1, 0); - } else { - ExtTextOut(hdc, -gx + margin, -gy + margin, options, 0, reinterpret_cast(&glyph), 1, 0); - } - - SelectObject(hdc, old_font); - return ni; -} - -glyph_metrics_t QWindowsFontEngine::alphaMapBoundingBox(glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat format) -{ - int margin = 0; - if (format == QFontEngine::Format_A32 || format == QFontEngine::Format_ARGB) - margin = glyphMargin(QFontEngine::Format_A32); - glyph_metrics_t gm = boundingBox(glyph, matrix); - gm.width += margin * 2; - gm.height += margin * 2; - return gm; -} - -QImage QWindowsFontEngine::alphaMapForGlyph(glyph_t glyph, const QTransform &xform) -{ - HFONT font = hfont; - - bool clearTypeTemporarilyDisabled = (m_fontEngineData->clearTypeEnabled && m_logfont.lfQuality != NONANTIALIASED_QUALITY); - if (clearTypeTemporarilyDisabled) { - LOGFONT lf = m_logfont; - lf.lfQuality = ANTIALIASED_QUALITY; - font = CreateFontIndirect(&lf); - } - QImage::Format mask_format = QWindowsNativeImage::systemFormat(); - mask_format = QImage::Format_RGB32; - - const QWindowsNativeImage *mask = drawGDIGlyph(font, glyph, 0, xform, mask_format); - if (mask == 0) { - if (m_fontEngineData->clearTypeEnabled) - DeleteObject(font); - return QImage(); - } - - QImage alphaMap(mask->width(), mask->height(), QImage::Format_Alpha8); - - - // Copy data... Cannot use QPainter here as GDI has messed up the - // Alpha channel of the ni.image pixels... - for (int y=0; yheight(); ++y) { - uchar *dest = alphaMap.scanLine(y); - if (mask->image().format() == QImage::Format_RGB16) { - const qint16 *src = reinterpret_cast(mask->image().constScanLine(y)); - for (int x=0; xwidth(); ++x) - dest[x] = 255 - qGray(src[x]); - } else { - const uint *src = reinterpret_cast(mask->image().constScanLine(y)); - for (int x=0; xwidth(); ++x) { - if (QWindowsNativeImage::systemFormat() == QImage::Format_RGB16) - dest[x] = 255 - qGray(src[x]); - else - dest[x] = 255 - (m_fontEngineData->pow_gamma[qGray(src[x])] * 255. / 2047.); - } - } - } - - // Cleanup... - delete mask; - if (clearTypeTemporarilyDisabled) { - DeleteObject(font); - } - - return alphaMap; -} - -#define SPI_GETFONTSMOOTHINGCONTRAST 0x200C -#define SPI_SETFONTSMOOTHINGCONTRAST 0x200D - -QImage QWindowsFontEngine::alphaRGBMapForGlyph(glyph_t glyph, QFixed, const QTransform &t) -{ - HFONT font = hfont; - - UINT contrast; - SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &contrast, 0); - SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, reinterpret_cast(quintptr(1000)), 0); - - int margin = glyphMargin(QFontEngine::Format_A32); - QWindowsNativeImage *mask = drawGDIGlyph(font, glyph, margin, t, QImage::Format_RGB32); - SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, reinterpret_cast(quintptr(contrast)), 0); - - if (mask == 0) - return QImage(); - - // Gracefully handle the odd case when the display is 16-bit - const QImage source = mask->image().depth() == 32 - ? mask->image() - : mask->image().convertToFormat(QImage::Format_RGB32); - - QImage rgbMask(mask->width(), mask->height(), QImage::Format_RGB32); - for (int y=0; yheight(); ++y) { - uint *dest = (uint *) rgbMask.scanLine(y); - const uint *src = reinterpret_cast(source.constScanLine(y)); - for (int x=0; xwidth(); ++x) { - dest[x] = 0xffffffff - (0x00ffffff & src[x]); - } - } - - delete mask; - - return rgbMask; -} - -QFontEngine *QWindowsFontEngine::cloneWithSize(qreal pixelSize) const -{ - QFontDef request = fontDef; - QString actualFontName = request.family; - if (!uniqueFamilyName.isEmpty()) - request.family = uniqueFamilyName; - request.pixelSize = pixelSize; - - QFontEngine *fontEngine = - QWindowsFontDatabase::createEngine(request, - QWindowsContext::instance()->defaultDPI(), - m_fontEngineData); - if (fontEngine) { - fontEngine->fontDef.family = actualFontName; - if (!uniqueFamilyName.isEmpty()) { - static_cast(fontEngine)->setUniqueFamilyName(uniqueFamilyName); - QPlatformFontDatabase *pfdb = QWindowsIntegration::instance()->fontDatabase(); - static_cast(pfdb)->refUniqueFont(uniqueFamilyName); - } - } - return fontEngine; -} - -Qt::HANDLE QWindowsFontEngine::handle() const -{ - return hfont; -} - -void QWindowsFontEngine::initFontInfo(const QFontDef &request, - int dpi) -{ - fontDef = request; // most settings are equal - HDC dc = m_fontEngineData->hdc; - SelectObject(dc, hfont); - wchar_t n[64]; - GetTextFace(dc, 64, n); - fontDef.family = QString::fromWCharArray(n); - fontDef.fixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH); - if (fontDef.pointSize < 0) { - fontDef.pointSize = fontDef.pixelSize * 72. / dpi; - } else if (fontDef.pixelSize == -1) { - fontDef.pixelSize = qRound(fontDef.pointSize * dpi / 72.); - } -} - -/*! - \class QWindowsMultiFontEngine - \brief Standard Windows Multi font engine. - \internal - \ingroup qt-lighthouse-win - - "Merges" several font engines that have gaps in the - supported writing systems. - - Will probably be superseded by a common Free Type font engine in Qt 5.X. -*/ -QWindowsMultiFontEngine::QWindowsMultiFontEngine(QFontEngine *fe, int script) - : QFontEngineMulti(fe, script) -{ -} - -QFontEngine *QWindowsMultiFontEngine::loadEngine(int at) -{ - QFontEngine *fontEngine = engine(0); - QSharedPointer data; - LOGFONT lf; - -#ifndef QT_NO_DIRECTWRITE - if (fontEngine->type() == QFontEngine::DirectWrite) { - QWindowsFontEngineDirectWrite *fe = static_cast(fontEngine); - lf = QWindowsFontDatabase::fontDefToLOGFONT(fe->fontDef); - - data = fe->fontEngineData(); - } else -#endif - { - QWindowsFontEngine *fe = static_cast(fontEngine); - lf = fe->m_logfont; - - data = fe->fontEngineData(); - } - - const QString fam = fallbackFamilyAt(at - 1); - const int faceNameLength = qMin(fam.length(), LF_FACESIZE - 1); - memcpy(lf.lfFaceName, fam.utf16(), faceNameLength * sizeof(wchar_t)); - lf.lfFaceName[faceNameLength] = 0; - -#ifndef QT_NO_DIRECTWRITE - if (fontEngine->type() == QFontEngine::DirectWrite) { - const QString nameSubstitute = QWindowsFontEngineDirectWrite::fontNameSubstitute(fam); - if (nameSubstitute != fam) { - const int nameSubstituteLength = qMin(nameSubstitute.length(), LF_FACESIZE - 1); - memcpy(lf.lfFaceName, nameSubstitute.utf16(), nameSubstituteLength * sizeof(wchar_t)); - lf.lfFaceName[nameSubstituteLength] = 0; - } - - IDWriteFont *directWriteFont = 0; - HRESULT hr = data->directWriteGdiInterop->CreateFontFromLOGFONT(&lf, &directWriteFont); - if (FAILED(hr)) { - qErrnoWarning("%s: CreateFontFromLOGFONT failed", __FUNCTION__); - } else { - Q_ASSERT(directWriteFont); - IDWriteFontFace *directWriteFontFace = NULL; - HRESULT hr = directWriteFont->CreateFontFace(&directWriteFontFace); - if (SUCCEEDED(hr)) { - Q_ASSERT(directWriteFontFace); - QWindowsFontEngineDirectWrite *fedw = new QWindowsFontEngineDirectWrite(directWriteFontFace, - fontEngine->fontDef.pixelSize, - data); - fedw->fontDef.weight = fontEngine->fontDef.weight; - if (fontEngine->fontDef.style > QFont::StyleNormal) - fedw->fontDef.style = fontEngine->fontDef.style; - fedw->fontDef.family = fam; - fedw->fontDef.hintingPreference = fontEngine->fontDef.hintingPreference; - return fedw; - } else { - qErrnoWarning("%s: CreateFontFace failed", __FUNCTION__); - } - } - } -#endif - - // Get here if original font is not DirectWrite or DirectWrite creation failed for some - // reason - - QFontEngine *fe = new QWindowsFontEngine(fam, lf, data); - fe->fontDef.weight = fontEngine->fontDef.weight; - if (fontEngine->fontDef.style > QFont::StyleNormal) - fe->fontDef.style = fontEngine->fontDef.style; - fe->fontDef.family = fam; - fe->fontDef.hintingPreference = fontEngine->fontDef.hintingPreference; - return fe; -} - -bool QWindowsFontEngine::supportsTransformation(const QTransform &transform) const -{ - // Support all transformations for ttf files, and translations for raster fonts - return ttf || transform.type() <= QTransform::TxTranslate; -} - -QT_END_NAMESPACE - diff --git a/src/plugins/platforms/windows/qwindowsfontengine.h b/src/plugins/platforms/windows/qwindowsfontengine.h deleted file mode 100644 index b63d8fd282..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontengine.h +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSFONTENGINE_H -#define QWINDOWSFONTENGINE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -class QWindowsNativeImage; -class QWindowsFontEngineData; - -class QWindowsFontEngine : public QFontEngine -{ - friend class QWindowsMultiFontEngine; - -public: - QWindowsFontEngine(const QString &name, LOGFONT lf, - const QSharedPointer &fontEngineData); - - ~QWindowsFontEngine(); - void initFontInfo(const QFontDef &request, - int dpi); - - QFixed lineThickness() const Q_DECL_OVERRIDE; - Properties properties() const Q_DECL_OVERRIDE; - void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) Q_DECL_OVERRIDE; - FaceId faceId() const Q_DECL_OVERRIDE; - bool getSfntTableData(uint tag, uchar *buffer, uint *length) const Q_DECL_OVERRIDE; - int synthesized() const Q_DECL_OVERRIDE; - QFixed emSquareSize() const Q_DECL_OVERRIDE; - - glyph_t glyphIndex(uint ucs4) const Q_DECL_OVERRIDE; - bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const Q_DECL_OVERRIDE; - void recalcAdvances(QGlyphLayout *glyphs, ShaperFlags) const Q_DECL_OVERRIDE; - - void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) Q_DECL_OVERRIDE; - virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, - QPainterPath *path, QTextItem::RenderFlags flags) Q_DECL_OVERRIDE; - - HGDIOBJ selectDesignFont() const; - - glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) Q_DECL_OVERRIDE; - glyph_metrics_t boundingBox(glyph_t g) Q_DECL_OVERRIDE { return boundingBox(g, QTransform()); } - glyph_metrics_t boundingBox(glyph_t g, const QTransform &t) Q_DECL_OVERRIDE; - - - QFixed ascent() const Q_DECL_OVERRIDE; - QFixed descent() const Q_DECL_OVERRIDE; - QFixed leading() const Q_DECL_OVERRIDE; - QFixed xHeight() const Q_DECL_OVERRIDE; - QFixed capHeight() const Q_DECL_OVERRIDE; - QFixed averageCharWidth() const Q_DECL_OVERRIDE; - qreal maxCharWidth() const Q_DECL_OVERRIDE; - qreal minLeftBearing() const Q_DECL_OVERRIDE; - qreal minRightBearing() const Q_DECL_OVERRIDE; - - QImage alphaMapForGlyph(glyph_t t) Q_DECL_OVERRIDE { return alphaMapForGlyph(t, QTransform()); } - QImage alphaMapForGlyph(glyph_t, const QTransform &xform) Q_DECL_OVERRIDE; - QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform) Q_DECL_OVERRIDE; - glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat) Q_DECL_OVERRIDE; - - QFontEngine *cloneWithSize(qreal pixelSize) const Q_DECL_OVERRIDE; - Qt::HANDLE handle() const Q_DECL_OVERRIDE; - bool supportsTransformation(const QTransform &transform) const Q_DECL_OVERRIDE; - -#ifndef Q_CC_MINGW - void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0) Q_DECL_OVERRIDE; -#endif - - bool hasUnreliableGlyphOutline() const Q_DECL_OVERRIDE; - - int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs) const; - void getCMap(); - - bool getOutlineMetrics(glyph_t glyph, const QTransform &t, glyph_metrics_t *metrics) const; - - const QSharedPointer &fontEngineData() const { return m_fontEngineData; } - - void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; } - -private: - QWindowsNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform, - QImage::Format mask_format); - bool hasCFFTable() const; - bool hasCMapTable() const; - bool hasGlyfTable() const; - bool hasEbdtTable() const; - - const QSharedPointer m_fontEngineData; - - const QString _name; - QString uniqueFamilyName; - HFONT hfont; - const LOGFONT m_logfont; - uint ttf : 1; - uint hasOutline : 1; - uint hasUnreliableOutline : 1; - uint cffTable : 1; - TEXTMETRIC tm; - const unsigned char *cmap; - int cmapSize; - QByteArray cmapTable; - mutable qreal lbearing; - mutable qreal rbearing; - QFixed designToDevice; - int unitsPerEm; - QFixed x_height; - FaceId _faceId; - - mutable int synthesized_flags; - mutable QFixed lineWidth; - mutable unsigned char *widthCache; - mutable uint widthCacheSize; - mutable QFixed *designAdvances; - mutable int designAdvancesSize; -}; - -class QWindowsMultiFontEngine : public QFontEngineMulti -{ -public: - explicit QWindowsMultiFontEngine(QFontEngine *fe, int script); - - QFontEngine *loadEngine(int at) Q_DECL_OVERRIDE; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(HFONT) -Q_DECLARE_METATYPE(LOGFONT) - -#endif // QWINDOWSFONTENGINE_H - diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp deleted file mode 100644 index 334e9cb8b9..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.cpp +++ /dev/null @@ -1,1000 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_NO_DIRECTWRITE - -#include "qwindowsfontenginedirectwrite.h" -#include "qwindowsfontdatabase.h" -#include "qwindowscontext.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(QT_USE_DIRECTWRITE2) -# include -#else -# include -#endif - -#include - -QT_BEGIN_NAMESPACE - -// Convert from design units to logical pixels -#define DESIGN_TO_LOGICAL(DESIGN_UNIT_VALUE) \ - QFixed::fromReal((qreal(DESIGN_UNIT_VALUE) / qreal(m_unitsPerEm)) * fontDef.pixelSize) - -namespace { - - class GeometrySink: public IDWriteGeometrySink - { - public: - GeometrySink(QPainterPath *path) - : m_refCount(0), m_path(path) - { - Q_ASSERT(m_path != 0); - } - virtual ~GeometrySink() - { - } - - IFACEMETHOD_(void, AddBeziers)(const D2D1_BEZIER_SEGMENT *beziers, UINT bezierCount); - IFACEMETHOD_(void, AddLines)(const D2D1_POINT_2F *points, UINT pointCount); - IFACEMETHOD_(void, BeginFigure)(D2D1_POINT_2F startPoint, D2D1_FIGURE_BEGIN figureBegin); - IFACEMETHOD(Close)(); - IFACEMETHOD_(void, EndFigure)(D2D1_FIGURE_END figureEnd); - IFACEMETHOD_(void, SetFillMode)(D2D1_FILL_MODE fillMode); - IFACEMETHOD_(void, SetSegmentFlags)(D2D1_PATH_SEGMENT vertexFlags); - - IFACEMETHOD_(unsigned long, AddRef)(); - IFACEMETHOD_(unsigned long, Release)(); - IFACEMETHOD(QueryInterface)(IID const &riid, void **ppvObject); - - private: - inline static QPointF fromD2D1_POINT_2F(const D2D1_POINT_2F &inp) - { - return QPointF(inp.x, inp.y); - } - - unsigned long m_refCount; - QPointF m_startPoint; - QPainterPath *m_path; - }; - - void GeometrySink::AddBeziers(const D2D1_BEZIER_SEGMENT *beziers, - UINT bezierCount) - { - for (uint i=0; icubicTo(c1, c2, p2); - } - } - - void GeometrySink::AddLines(const D2D1_POINT_2F *points, UINT pointsCount) - { - for (uint i=0; ilineTo(fromD2D1_POINT_2F(points[i])); - } - - void GeometrySink::BeginFigure(D2D1_POINT_2F startPoint, - D2D1_FIGURE_BEGIN /*figureBegin*/) - { - m_startPoint = fromD2D1_POINT_2F(startPoint); - m_path->moveTo(m_startPoint); - } - - IFACEMETHODIMP GeometrySink::Close() - { - return E_NOTIMPL; - } - - void GeometrySink::EndFigure(D2D1_FIGURE_END figureEnd) - { - if (figureEnd == D2D1_FIGURE_END_CLOSED) - m_path->closeSubpath(); - } - - void GeometrySink::SetFillMode(D2D1_FILL_MODE fillMode) - { - m_path->setFillRule(fillMode == D2D1_FILL_MODE_ALTERNATE - ? Qt::OddEvenFill - : Qt::WindingFill); - } - - void GeometrySink::SetSegmentFlags(D2D1_PATH_SEGMENT /*vertexFlags*/) - { - /* Not implemented */ - } - - IFACEMETHODIMP_(unsigned long) GeometrySink::AddRef() - { - return InterlockedIncrement(&m_refCount); - } - - IFACEMETHODIMP_(unsigned long) GeometrySink::Release() - { - unsigned long newCount = InterlockedDecrement(&m_refCount); - if (newCount == 0) - { - delete this; - return 0; - } - - return newCount; - } - - IFACEMETHODIMP GeometrySink::QueryInterface(IID const &riid, void **ppvObject) - { - if (__uuidof(IDWriteGeometrySink) == riid) { - *ppvObject = this; - } else if (__uuidof(IUnknown) == riid) { - *ppvObject = this; - } else { - *ppvObject = NULL; - return E_FAIL; - } - - AddRef(); - return S_OK; - } - -} - -static DWRITE_RENDERING_MODE hintingPreferenceToRenderingMode(QFont::HintingPreference hintingPreference) -{ - switch (hintingPreference) { - case QFont::PreferNoHinting: - return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; - case QFont::PreferVerticalHinting: - return DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL; - default: - return DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC; - } -} - -/*! - \class QWindowsFontEngineDirectWrite - \brief Windows font engine using Direct Write. - \internal - \ingroup qt-lighthouse-win - - Font engine for subpixel positioned text on Windows Vista - (with platform update) and Windows 7. If selected during - configuration, the engine will be selected only when the hinting - preference of a font is set to None or Vertical hinting. The font - database uses most of the same logic but creates a direct write - font based on the LOGFONT rather than a GDI handle. - - Will probably be superseded by a common Free Type font engine in Qt 5.X. -*/ - -QWindowsFontEngineDirectWrite::QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace, - qreal pixelSize, - const QSharedPointer &d) - : QFontEngine(DirectWrite) - , m_fontEngineData(d) - , m_directWriteFontFace(directWriteFontFace) - , m_directWriteBitmapRenderTarget(0) - , m_lineThickness(-1) - , m_unitsPerEm(-1) - , m_ascent(-1) - , m_capHeight(-1) - , m_descent(-1) - , m_xHeight(-1) - , m_lineGap(-1) -{ - qCDebug(lcQpaFonts) << __FUNCTION__ << pixelSize; - - Q_ASSERT(m_directWriteFontFace); - - m_fontEngineData->directWriteFactory->AddRef(); - m_directWriteFontFace->AddRef(); - - fontDef.pixelSize = pixelSize; - collectMetrics(); - cache_cost = (m_ascent.toInt() + m_descent.toInt()) * m_xHeight.toInt() * 2000; -} - -QWindowsFontEngineDirectWrite::~QWindowsFontEngineDirectWrite() -{ - qCDebug(lcQpaFonts) << __FUNCTION__; - - m_fontEngineData->directWriteFactory->Release(); - m_directWriteFontFace->Release(); - - if (m_directWriteBitmapRenderTarget != 0) - m_directWriteBitmapRenderTarget->Release(); - - if (!m_uniqueFamilyName.isEmpty()) { - QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); - static_cast(pfdb)->derefUniqueFont(m_uniqueFamilyName); - } -} - -#ifndef Q_CC_MINGW -typedef IDWriteLocalFontFileLoader QIdWriteLocalFontFileLoader; - -static UUID uuidIdWriteLocalFontFileLoader() -{ - return __uuidof(IDWriteLocalFontFileLoader); -} -#else // !Q_CC_MINGW -DECLARE_INTERFACE_(QIdWriteLocalFontFileLoader, IDWriteFontFileLoader) -{ - STDMETHOD(GetFilePathLengthFromKey)(THIS_ void const *, UINT32, UINT32*) PURE; - STDMETHOD(GetFilePathFromKey)(THIS_ void const *, UINT32, WCHAR *, UINT32) PURE; - STDMETHOD(GetLastWriteTimeFromKey)(THIS_ void const *, UINT32, FILETIME *) PURE; -}; - -static UUID uuidIdWriteLocalFontFileLoader() -{ - static const UUID result = { 0xb2d9f3ec, 0xc9fe, 0x4a11, {0xa2, 0xec, 0xd8, 0x62, 0x8, 0xf7, 0xc0, 0xa2}}; - return result; -} -#endif // Q_CC_MINGW - -QString QWindowsFontEngineDirectWrite::filenameFromFontFile(IDWriteFontFile *fontFile) -{ - IDWriteFontFileLoader *loader = Q_NULLPTR; - - HRESULT hr = fontFile->GetLoader(&loader); - if (FAILED(hr)) { - qErrnoWarning("%s: GetLoader failed", __FUNCTION__); - return QString(); - } - - QIdWriteLocalFontFileLoader *localLoader = Q_NULLPTR; - hr = loader->QueryInterface(uuidIdWriteLocalFontFileLoader(), - reinterpret_cast(&localLoader)); - - const void *fontFileReferenceKey = Q_NULLPTR; - UINT32 fontFileReferenceKeySize = 0; - if (SUCCEEDED(hr)) { - hr = fontFile->GetReferenceKey(&fontFileReferenceKey, - &fontFileReferenceKeySize); - if (FAILED(hr)) - qErrnoWarning(hr, "%s: GetReferenceKey failed", __FUNCTION__); - } - - UINT32 filePathLength = 0; - if (SUCCEEDED(hr)) { - hr = localLoader->GetFilePathLengthFromKey(fontFileReferenceKey, - fontFileReferenceKeySize, - &filePathLength); - if (FAILED(hr)) - qErrnoWarning(hr, "GetFilePathLength failed", __FUNCTION__); - } - - QString ret; - if (SUCCEEDED(hr) && filePathLength > 0) { - QVarLengthArray filePath(filePathLength + 1); - - hr = localLoader->GetFilePathFromKey(fontFileReferenceKey, - fontFileReferenceKeySize, - filePath.data(), - filePathLength + 1); - if (FAILED(hr)) - qErrnoWarning(hr, "%s: GetFilePathFromKey failed", __FUNCTION__); - else - ret = QString::fromWCharArray(filePath.data()); - } - - if (localLoader != Q_NULLPTR) - localLoader->Release(); - - if (loader != Q_NULLPTR) - loader->Release(); - return ret; -} - -void QWindowsFontEngineDirectWrite::collectMetrics() -{ - DWRITE_FONT_METRICS metrics; - - m_directWriteFontFace->GetMetrics(&metrics); - m_unitsPerEm = metrics.designUnitsPerEm; - - m_lineThickness = DESIGN_TO_LOGICAL(metrics.underlineThickness); - m_ascent = DESIGN_TO_LOGICAL(metrics.ascent); - m_capHeight = DESIGN_TO_LOGICAL(metrics.capHeight); - m_descent = DESIGN_TO_LOGICAL(metrics.descent); - m_xHeight = DESIGN_TO_LOGICAL(metrics.xHeight); - m_lineGap = DESIGN_TO_LOGICAL(metrics.lineGap); - m_underlinePosition = DESIGN_TO_LOGICAL(metrics.underlinePosition); - - IDWriteFontFile *fontFile = Q_NULLPTR; - UINT32 numberOfFiles = 1; - if (SUCCEEDED(m_directWriteFontFace->GetFiles(&numberOfFiles, &fontFile))) { - m_faceId.filename = QFile::encodeName(filenameFromFontFile(fontFile)); - fontFile->Release(); - } -} - -QFixed QWindowsFontEngineDirectWrite::underlinePosition() const -{ - if (m_underlinePosition > 0) - return m_underlinePosition; - else - return QFontEngine::underlinePosition(); -} - -QFixed QWindowsFontEngineDirectWrite::lineThickness() const -{ - if (m_lineThickness > 0) - return m_lineThickness; - else - return QFontEngine::lineThickness(); -} - -bool QWindowsFontEngineDirectWrite::getSfntTableData(uint tag, uchar *buffer, uint *length) const -{ - bool ret = false; - - const void *tableData = 0; - UINT32 tableSize; - void *tableContext = 0; - BOOL exists; - HRESULT hr = m_directWriteFontFace->TryGetFontTable(qbswap(tag), - &tableData, &tableSize, - &tableContext, &exists); - if (SUCCEEDED(hr)) { - if (exists) { - ret = true; - if (buffer && *length >= tableSize) - memcpy(buffer, tableData, tableSize); - *length = tableSize; - Q_ASSERT(int(*length) > 0); - } - m_directWriteFontFace->ReleaseFontTable(tableContext); - } else { - qErrnoWarning("%s: TryGetFontTable failed", __FUNCTION__); - } - - return ret; -} - -QFixed QWindowsFontEngineDirectWrite::emSquareSize() const -{ - if (m_unitsPerEm > 0) - return m_unitsPerEm; - else - return QFontEngine::emSquareSize(); -} - -glyph_t QWindowsFontEngineDirectWrite::glyphIndex(uint ucs4) const -{ - UINT16 glyphIndex; - - HRESULT hr = m_directWriteFontFace->GetGlyphIndicesW(&ucs4, 1, &glyphIndex); - if (FAILED(hr)) { - qErrnoWarning("%s: glyphIndex failed", __FUNCTION__); - glyphIndex = 0; - } - - return glyphIndex; -} - -bool QWindowsFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, - int *nglyphs, QFontEngine::ShaperFlags flags) const -{ - Q_ASSERT(glyphs->numGlyphs >= *nglyphs); - if (*nglyphs < len) { - *nglyphs = len; - return false; - } - - QVarLengthArray codePoints(len); - int actualLength = 0; - QStringIterator it(str, str + len); - while (it.hasNext()) - codePoints[actualLength++] = it.next(); - - QVarLengthArray glyphIndices(actualLength); - HRESULT hr = m_directWriteFontFace->GetGlyphIndicesW(codePoints.data(), actualLength, - glyphIndices.data()); - if (FAILED(hr)) { - qErrnoWarning("%s: GetGlyphIndicesW failed", __FUNCTION__); - return false; - } - - for (int i = 0; i < actualLength; ++i) - glyphs->glyphs[i] = glyphIndices.at(i); - - *nglyphs = actualLength; - glyphs->numGlyphs = actualLength; - - if (!(flags & GlyphIndicesOnly)) - recalcAdvances(glyphs, 0); - - return true; -} - -QFontEngine::FaceId QWindowsFontEngineDirectWrite::faceId() const -{ - return m_faceId; -} - -void QWindowsFontEngineDirectWrite::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags) const -{ - QVarLengthArray glyphIndices(glyphs->numGlyphs); - - // ### Caching? - for(int i=0; inumGlyphs; i++) - glyphIndices[i] = UINT16(glyphs->glyphs[i]); - - QVarLengthArray glyphMetrics(glyphIndices.size()); - HRESULT hr = m_directWriteFontFace->GetDesignGlyphMetrics(glyphIndices.data(), - glyphIndices.size(), - glyphMetrics.data()); - if (SUCCEEDED(hr)) { - qreal stretch = fontDef.stretch != QFont::AnyStretch ? fontDef.stretch / 100.0 : 1.0; - for (int i = 0; i < glyphs->numGlyphs; ++i) - glyphs->advances[i] = DESIGN_TO_LOGICAL(glyphMetrics[i].advanceWidth * stretch); - if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { - for (int i = 0; i < glyphs->numGlyphs; ++i) - glyphs->advances[i] = glyphs->advances[i].round(); - } - } else { - qErrnoWarning("%s: GetDesignGlyphMetrics failed", __FUNCTION__); - } -} - -void QWindowsFontEngineDirectWrite::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, - QPainterPath *path, QTextItem::RenderFlags flags) -{ - QVarLengthArray glyphIndices(nglyphs); - QVarLengthArray glyphOffsets(nglyphs); - QVarLengthArray glyphAdvances(nglyphs); - - for (int i=0; iGetGlyphRunOutline( - fontDef.pixelSize, - glyphIndices.data(), - glyphAdvances.data(), - glyphOffsets.data(), - nglyphs, - false, - flags & QTextItem::RightToLeft, - &geometrySink - ); - - if (FAILED(hr)) - qErrnoWarning("%s: GetGlyphRunOutline failed", __FUNCTION__); -} - -glyph_metrics_t QWindowsFontEngineDirectWrite::boundingBox(const QGlyphLayout &glyphs) -{ - if (glyphs.numGlyphs == 0) - return glyph_metrics_t(); - - bool round = fontDef.styleStrategy & QFont::ForceIntegerMetrics; - - QFixed w = 0; - for (int i = 0; i < glyphs.numGlyphs; ++i) { - w += round ? glyphs.effectiveAdvance(i).round() : glyphs.effectiveAdvance(i); - - } - - return glyph_metrics_t(0, -m_ascent, w - lastRightBearing(glyphs), m_ascent + m_descent, w, 0); -} - -glyph_metrics_t QWindowsFontEngineDirectWrite::boundingBox(glyph_t g) -{ - UINT16 glyphIndex = g; - - DWRITE_GLYPH_METRICS glyphMetrics; - HRESULT hr = m_directWriteFontFace->GetDesignGlyphMetrics(&glyphIndex, 1, &glyphMetrics); - if (SUCCEEDED(hr)) { - QFixed advanceWidth = DESIGN_TO_LOGICAL(glyphMetrics.advanceWidth); - QFixed leftSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.leftSideBearing); - QFixed rightSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.rightSideBearing); - QFixed advanceHeight = DESIGN_TO_LOGICAL(glyphMetrics.advanceHeight); - QFixed verticalOriginY = DESIGN_TO_LOGICAL(glyphMetrics.verticalOriginY); - QFixed topSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.topSideBearing); - QFixed bottomSideBearing = DESIGN_TO_LOGICAL(glyphMetrics.bottomSideBearing); - - if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) { - advanceWidth = advanceWidth.round(); - advanceHeight = advanceHeight.round(); - } - - QFixed width = advanceWidth - leftSideBearing - rightSideBearing; - QFixed height = advanceHeight - topSideBearing - bottomSideBearing; - return glyph_metrics_t(leftSideBearing, - -verticalOriginY + topSideBearing, - width, - height, - advanceWidth, - 0); - } else { - qErrnoWarning("%s: GetDesignGlyphMetrics failed", __FUNCTION__); - } - - return glyph_metrics_t(); -} - -QFixed QWindowsFontEngineDirectWrite::ascent() const -{ - return fontDef.styleStrategy & QFont::ForceIntegerMetrics - ? m_ascent.round() - : m_ascent; -} - -QFixed QWindowsFontEngineDirectWrite::capHeight() const -{ - if (m_capHeight <= 0) - return calculatedCapHeight(); - - return fontDef.styleStrategy & QFont::ForceIntegerMetrics - ? m_capHeight.round() - : m_capHeight; -} - -QFixed QWindowsFontEngineDirectWrite::descent() const -{ - return fontDef.styleStrategy & QFont::ForceIntegerMetrics - ? m_descent.round() - : m_descent; -} - -QFixed QWindowsFontEngineDirectWrite::leading() const -{ - return fontDef.styleStrategy & QFont::ForceIntegerMetrics - ? m_lineGap.round() - : m_lineGap; -} - -QFixed QWindowsFontEngineDirectWrite::xHeight() const -{ - return fontDef.styleStrategy & QFont::ForceIntegerMetrics - ? m_xHeight.round() - : m_xHeight; -} - -qreal QWindowsFontEngineDirectWrite::maxCharWidth() const -{ - // ### - return 0; -} - -QImage QWindowsFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) -{ - QImage im = alphaRGBMapForGlyph(glyph, subPixelPosition, t); - - QImage alphaMap(im.width(), im.height(), QImage::Format_Alpha8); - - for (int y=0; y(im.constScanLine(y)); - uchar *dst = alphaMap.scanLine(y); - for (int x=0; xpow_gamma[qGray(0xffffffff - *src)] * 255. / 2047.); - ++dst; - ++src; - } - } - - return alphaMap; -} - -QImage QWindowsFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition) -{ - return alphaMapForGlyph(glyph, subPixelPosition, QTransform()); -} - -bool QWindowsFontEngineDirectWrite::supportsSubPixelPositions() const -{ - return true; -} - -QImage QWindowsFontEngineDirectWrite::imageForGlyph(glyph_t t, - QFixed subPixelPosition, - int margin, - const QTransform &originalTransform) -{ - UINT16 glyphIndex = t; - FLOAT glyphAdvance = 0; - - DWRITE_GLYPH_OFFSET glyphOffset; - glyphOffset.advanceOffset = 0; - glyphOffset.ascenderOffset = 0; - - DWRITE_GLYPH_RUN glyphRun; - glyphRun.fontFace = m_directWriteFontFace; - glyphRun.fontEmSize = fontDef.pixelSize; - glyphRun.glyphCount = 1; - glyphRun.glyphIndices = &glyphIndex; - glyphRun.glyphAdvances = &glyphAdvance; - glyphRun.isSideways = false; - glyphRun.bidiLevel = 0; - glyphRun.glyphOffsets = &glyphOffset; - - QTransform xform = originalTransform; - if (fontDef.stretch != 100) - xform.scale(fontDef.stretch / 100.0, 1.0); - - DWRITE_MATRIX transform; - transform.dx = subPixelPosition.toReal(); - transform.dy = 0; - transform.m11 = xform.m11(); - transform.m12 = xform.m12(); - transform.m21 = xform.m21(); - transform.m22 = xform.m22(); - - DWRITE_RENDERING_MODE renderMode = - hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); - - IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; - HRESULT hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( - &glyphRun, - 1.0f, - &transform, - renderMode, - DWRITE_MEASURING_MODE_NATURAL, - 0.0, 0.0, - &glyphAnalysis - ); - - if (SUCCEEDED(hr)) { - RECT rect; - glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect); - - QRect boundingRect = QRect(QPoint(rect.left - margin, - rect.top - margin), - QPoint(rect.right + margin, - rect.bottom + margin)); - - - const int width = boundingRect.width() - 1; // -1 due to Qt's off-by-one definition of a QRect - const int height = boundingRect.height() - 1; - - QImage image; -#if defined(QT_USE_DIRECTWRITE2) - HRESULT hr = DWRITE_E_NOCOLOR; - IDWriteColorGlyphRunEnumerator *enumerator = 0; - IDWriteFactory2 *factory2 = Q_NULLPTR; - if (glyphFormat == QFontEngine::Format_ARGB - && SUCCEEDED(m_fontEngineData->directWriteFactory->QueryInterface(__uuidof(IDWriteFactory2), - reinterpret_cast(&factory2)))) { - hr = factory2->TranslateColorGlyphRun(0.0f, - 0.0f, - &glyphRun, - NULL, - DWRITE_MEASURING_MODE_NATURAL, - NULL, - 0, - &enumerator); - image = QImage(width, height, QImage::Format_ARGB32_Premultiplied); - image.fill(0); - } else -#endif - { - image = QImage(width, height, QImage::Format_RGB32); - image.fill(0xffffffff); - } - -#if defined(QT_USE_DIRECTWRITE2) - BOOL ok = true; - if (SUCCEEDED(hr)) { - while (SUCCEEDED(hr) && ok) { - const DWRITE_COLOR_GLYPH_RUN *colorGlyphRun = 0; - hr = enumerator->GetCurrentRun(&colorGlyphRun); - if (FAILED(hr)) { // No colored runs, only outline - qErrnoWarning(hr, "%s: IDWriteColorGlyphRunEnumerator::GetCurrentRun failed", __FUNCTION__); - break; - } - - IDWriteGlyphRunAnalysis *colorGlyphsAnalysis = NULL; - hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( - &colorGlyphRun->glyphRun, - 1.0f, - &transform, - renderMode, - DWRITE_MEASURING_MODE_NATURAL, - 0.0, 0.0, - &colorGlyphsAnalysis - ); - if (FAILED(hr)) { - qErrnoWarning(hr, "%s: CreateGlyphRunAnalysis failed for color run", __FUNCTION__); - break; - } - - float r = qBound(0.0f, colorGlyphRun->runColor.r, 1.0f); - float g = qBound(0.0f, colorGlyphRun->runColor.g, 1.0f); - float b = qBound(0.0f, colorGlyphRun->runColor.b, 1.0f); - float a = qBound(0.0f, colorGlyphRun->runColor.a, 1.0f); - - if (!qFuzzyIsNull(a)) { - renderGlyphRun(&image, - r, - g, - b, - a, - colorGlyphsAnalysis, - boundingRect); - } - colorGlyphsAnalysis->Release(); - - hr = enumerator->MoveNext(&ok); - if (FAILED(hr)) { - qErrnoWarning(hr, "%s: IDWriteColorGlyphRunEnumerator::MoveNext failed", __FUNCTION__); - break; - } - } - } else -#endif - { - renderGlyphRun(&image, - 0.0, - 0.0, - 0.0, - 1.0, - glyphAnalysis, - boundingRect); - } - - glyphAnalysis->Release(); - return image; - } else { - qErrnoWarning(hr, "%s: CreateGlyphRunAnalysis failed", __FUNCTION__); - return QImage(); - } -} - - -void QWindowsFontEngineDirectWrite::renderGlyphRun(QImage *destination, - float r, - float g, - float b, - float a, - IDWriteGlyphRunAnalysis *glyphAnalysis, - const QRect &boundingRect) -{ - const int width = destination->width(); - const int height = destination->height(); - - r *= 255.0; - g *= 255.0; - b *= 255.0; - - const int size = width * height * 3; - if (size > 0) { - RECT rect; - rect.left = boundingRect.left(); - rect.top = boundingRect.top(); - rect.right = boundingRect.right(); - rect.bottom = boundingRect.bottom(); - - QVarLengthArray alphaValueArray(size); - BYTE *alphaValues = alphaValueArray.data(); - memset(alphaValues, 0, size); - - HRESULT hr = glyphAnalysis->CreateAlphaTexture(DWRITE_TEXTURE_CLEARTYPE_3x1, - &rect, - alphaValues, - size); - if (SUCCEEDED(hr)) { - if (destination->hasAlphaChannel()) { - for (int y = 0; y < height; ++y) { - uint *dest = reinterpret_cast(destination->scanLine(y)); - BYTE *src = alphaValues + width * 3 * y; - - for (int x = 0; x < width; ++x) { - float redAlpha = a * *src++ / 255.0; - float greenAlpha = a * *src++ / 255.0; - float blueAlpha = a * *src++ / 255.0; - float averageAlpha = (redAlpha + greenAlpha + blueAlpha) / 3.0; - - QRgb currentRgb = dest[x]; - dest[x] = qRgba(qRound(qRed(currentRgb) * (1.0 - averageAlpha) + averageAlpha * r), - qRound(qGreen(currentRgb) * (1.0 - averageAlpha) + averageAlpha * g), - qRound(qBlue(currentRgb) * (1.0 - averageAlpha) + averageAlpha * b), - qRound(qAlpha(currentRgb) * (1.0 - averageAlpha) + averageAlpha * 255)); - } - } - - } else { - for (int y = 0; y < height; ++y) { - uint *dest = reinterpret_cast(destination->scanLine(y)); - BYTE *src = alphaValues + width * 3 * y; - - for (int x = 0; x < width; ++x) { - dest[x] = *(src + 0) << 16 - | *(src + 1) << 8 - | *(src + 2); - - src += 3; - } - } - } - } else { - qErrnoWarning("%s: CreateAlphaTexture failed", __FUNCTION__); - } - } else { - glyphAnalysis->Release(); - qWarning("%s: Glyph has no bounds", __FUNCTION__); - } -} - -QImage QWindowsFontEngineDirectWrite::alphaRGBMapForGlyph(glyph_t t, - QFixed subPixelPosition, - const QTransform &xform) -{ - QImage mask = imageForGlyph(t, - subPixelPosition, - glyphMargin(QFontEngine::Format_A32), - xform); - - return mask.depth() == 32 - ? mask - : mask.convertToFormat(QImage::Format_RGB32); -} - -QFontEngine *QWindowsFontEngineDirectWrite::cloneWithSize(qreal pixelSize) const -{ - QWindowsFontEngineDirectWrite *fontEngine = new QWindowsFontEngineDirectWrite(m_directWriteFontFace, - pixelSize, - m_fontEngineData); - - fontEngine->fontDef = fontDef; - fontEngine->fontDef.pixelSize = pixelSize; - if (!m_uniqueFamilyName.isEmpty()) { - fontEngine->setUniqueFamilyName(m_uniqueFamilyName); - QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); - static_cast(pfdb)->refUniqueFont(m_uniqueFamilyName); - } - - return fontEngine; -} - -Qt::HANDLE QWindowsFontEngineDirectWrite::handle() const -{ - return m_directWriteFontFace; -} - -void QWindowsFontEngineDirectWrite::initFontInfo(const QFontDef &request, - int dpi) -{ - fontDef = request; - - if (fontDef.pointSize < 0) - fontDef.pointSize = fontDef.pixelSize * 72. / dpi; - else if (fontDef.pixelSize == -1) - fontDef.pixelSize = qRound(fontDef.pointSize * dpi / 72.); -} - -QString QWindowsFontEngineDirectWrite::fontNameSubstitute(const QString &familyName) -{ - static const char keyC[] = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\" - "FontSubstitutes"; - return QSettings(QLatin1String(keyC), QSettings::NativeFormat).value(familyName, familyName).toString(); -} - -glyph_metrics_t QWindowsFontEngineDirectWrite::alphaMapBoundingBox(glyph_t glyph, - QFixed subPixelPosition, - const QTransform &originalTransform, - GlyphFormat format) -{ - Q_UNUSED(format); - - QTransform matrix = originalTransform; - if (fontDef.stretch != 100) - matrix.scale(fontDef.stretch / 100.0, 1.0); - - glyph_metrics_t bbox = QFontEngine::boundingBox(glyph, matrix); // To get transformed advance - - UINT16 glyphIndex = glyph; - FLOAT glyphAdvance = 0; - - DWRITE_GLYPH_OFFSET glyphOffset; - glyphOffset.advanceOffset = 0; - glyphOffset.ascenderOffset = 0; - - DWRITE_GLYPH_RUN glyphRun; - glyphRun.fontFace = m_directWriteFontFace; - glyphRun.fontEmSize = fontDef.pixelSize; - glyphRun.glyphCount = 1; - glyphRun.glyphIndices = &glyphIndex; - glyphRun.glyphAdvances = &glyphAdvance; - glyphRun.isSideways = false; - glyphRun.bidiLevel = 0; - glyphRun.glyphOffsets = &glyphOffset; - - DWRITE_MATRIX transform; - transform.dx = subPixelPosition.toReal(); - transform.dy = 0; - transform.m11 = matrix.m11(); - transform.m12 = matrix.m12(); - transform.m21 = matrix.m21(); - transform.m22 = matrix.m22(); - - DWRITE_RENDERING_MODE renderMode = - hintingPreferenceToRenderingMode(QFont::HintingPreference(fontDef.hintingPreference)); - - IDWriteGlyphRunAnalysis *glyphAnalysis = NULL; - HRESULT hr = m_fontEngineData->directWriteFactory->CreateGlyphRunAnalysis( - &glyphRun, - 1.0f, - &transform, - renderMode, - DWRITE_MEASURING_MODE_NATURAL, - 0.0, 0.0, - &glyphAnalysis - ); - - if (SUCCEEDED(hr)) { - RECT rect; - glyphAnalysis->GetAlphaTextureBounds(DWRITE_TEXTURE_CLEARTYPE_3x1, &rect); - glyphAnalysis->Release(); - - int margin = glyphMargin(QFontEngine::Format_A32); - - return glyph_metrics_t(rect.left, - rect.top, - rect.right - rect.left + margin * 2, - rect.bottom - rect.top + margin * 2, - bbox.xoff, bbox.yoff); - } else { - return glyph_metrics_t(); - } -} - -QImage QWindowsFontEngineDirectWrite::bitmapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) -{ - return imageForGlyph(glyph, subPixelPosition, glyphMargin(QFontEngine::Format_A32), t); -} - -QT_END_NAMESPACE - -#endif // QT_NO_DIRECTWRITE diff --git a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h b/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h deleted file mode 100644 index e4a82c6a6e..0000000000 --- a/src/plugins/platforms/windows/qwindowsfontenginedirectwrite.h +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSFONTENGINEDIRECTWRITE_H -#define QWINDOWSFONTENGINEDIRECTWRITE_H - -#include - -#ifndef QT_NO_DIRECTWRITE - -#include -#include - -struct IDWriteFont; -struct IDWriteFontFace; -struct IDWriteFontFile; -struct IDWriteFactory; -struct IDWriteBitmapRenderTarget; -struct IDWriteGdiInterop; -struct IDWriteGlyphRunAnalysis; - -QT_BEGIN_NAMESPACE - -class QWindowsFontEngineData; - -class QWindowsFontEngineDirectWrite : public QFontEngine -{ -public: - explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace, - qreal pixelSize, - const QSharedPointer &d); - ~QWindowsFontEngineDirectWrite(); - - void initFontInfo(const QFontDef &request, int dpi); - - QFixed lineThickness() const Q_DECL_OVERRIDE; - QFixed underlinePosition() const Q_DECL_OVERRIDE; - bool getSfntTableData(uint tag, uchar *buffer, uint *length) const Q_DECL_OVERRIDE; - QFixed emSquareSize() const Q_DECL_OVERRIDE; - - glyph_t glyphIndex(uint ucs4) const Q_DECL_OVERRIDE; - bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, - ShaperFlags flags) const Q_DECL_OVERRIDE; - void recalcAdvances(QGlyphLayout *glyphs, ShaperFlags) const Q_DECL_OVERRIDE; - - void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, - QPainterPath *path, QTextItem::RenderFlags flags) Q_DECL_OVERRIDE; - - glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) Q_DECL_OVERRIDE; - glyph_metrics_t boundingBox(glyph_t g) Q_DECL_OVERRIDE; - glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed, - const QTransform &matrix, GlyphFormat) Q_DECL_OVERRIDE; - - QFixed ascent() const Q_DECL_OVERRIDE; - QFixed capHeight() const Q_DECL_OVERRIDE; - QFixed descent() const Q_DECL_OVERRIDE; - QFixed leading() const Q_DECL_OVERRIDE; - QFixed xHeight() const Q_DECL_OVERRIDE; - qreal maxCharWidth() const Q_DECL_OVERRIDE; - FaceId faceId() const Q_DECL_OVERRIDE; - - bool supportsSubPixelPositions() const Q_DECL_OVERRIDE; - - QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition) Q_DECL_OVERRIDE; - QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) Q_DECL_OVERRIDE; - QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform) Q_DECL_OVERRIDE; - QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) Q_DECL_OVERRIDE; - - QFontEngine *cloneWithSize(qreal pixelSize) const Q_DECL_OVERRIDE; - Qt::HANDLE handle() const Q_DECL_OVERRIDE; - - const QSharedPointer &fontEngineData() const { return m_fontEngineData; } - - static QString fontNameSubstitute(const QString &familyName); - - IDWriteFontFace *directWriteFontFace() const { return m_directWriteFontFace; } - - void setUniqueFamilyName(const QString &newName) { m_uniqueFamilyName = newName; } - -private: - QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform); - void collectMetrics(); - void renderGlyphRun(QImage *destination, float r, float g, float b, float a, IDWriteGlyphRunAnalysis *glyphAnalysis, const QRect &boundingRect); - static QString filenameFromFontFile(IDWriteFontFile *fontFile); - - const QSharedPointer m_fontEngineData; - - IDWriteFontFace *m_directWriteFontFace; - IDWriteBitmapRenderTarget *m_directWriteBitmapRenderTarget; - - QFixed m_lineThickness; - QFixed m_underlinePosition; - int m_unitsPerEm; - QFixed m_ascent; - QFixed m_capHeight; - QFixed m_descent; - QFixed m_xHeight; - QFixed m_lineGap; - FaceId m_faceId; - QString m_uniqueFamilyName; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_DIRECTWRITE - -#endif // QWINDOWSFONTENGINEDIRECTWRITE_H diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 16a2b56774..004b03d9a9 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -47,9 +47,8 @@ #include "qwindowstheme.h" #include "qwindowsservices.h" #ifndef QT_NO_FREETYPE -# include "qwindowsfontdatabase_ft.h" +# include #endif -#include "qwindowsfontdatabase.h" #ifndef QT_NO_CLIPBOARD # include "qwindowsclipboard.h" # ifndef QT_NO_DRAGANDDROP @@ -220,6 +219,7 @@ QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList ¶mL // are connected to Windows 8.1 QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorDpiAware; m_options = parseOptions(paramList, &tabletAbsoluteRange, &dpiAwareness); + QWindowsFontDatabase::setFontOptions(m_options); if (tabletAbsoluteRange >= 0) m_context.setTabletAbsoluteRange(tabletAbsoluteRange); if (!dpiAwarenessSet) { // Set only once in case of repeated instantiations of QGuiApplication. diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h index 4258f908e7..a668470993 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.h +++ b/src/plugins/platforms/windows/qwindowsintegration.h @@ -43,6 +43,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -61,8 +62,9 @@ public: NoNativeDialogs = 0x8, XpNativeDialogs = 0x10, DontPassOsMouseEventsSynthesizedFromTouch = 0x20, // Do not pass OS-generated mouse events from touch. - DontUseDirectWriteFonts = 0x40, - DontUseColorFonts = 0x80 + // Keep in sync with QWindowsFontDatabase::FontOptions + DontUseDirectWriteFonts = QWindowsFontDatabase::DontUseDirectWriteFonts, + DontUseColorFonts = QWindowsFontDatabase::DontUseColorFonts }; explicit QWindowsIntegration(const QStringList ¶mList); diff --git a/src/plugins/platforms/windows/qwindowsnativeimage.cpp b/src/plugins/platforms/windows/qwindowsnativeimage.cpp deleted file mode 100644 index ec9683ea8d..0000000000 --- a/src/plugins/platforms/windows/qwindowsnativeimage.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwindowsnativeimage.h" -#include "qwindowscontext.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -typedef struct { - BITMAPINFOHEADER bmiHeader; - DWORD redMask; - DWORD greenMask; - DWORD blueMask; -} BITMAPINFO_MASK; - -/*! - \class QWindowsNativeImage - \brief Windows Native image - - Note that size can be 0 (widget autotests with zero size), which - causes CreateDIBSection() to fail. - - \sa QWindowsBackingStore - \internal - \ingroup qt-lighthouse-win -*/ - -static inline HDC createDC() -{ - HDC display_dc = GetDC(0); - HDC hdc = CreateCompatibleDC(display_dc); - ReleaseDC(0, display_dc); - Q_ASSERT(hdc); - return hdc; -} - -static inline HBITMAP createDIB(HDC hdc, int width, int height, - QImage::Format format, - uchar **bitsIn) -{ - BITMAPINFO_MASK bmi; - memset(&bmi, 0, sizeof(bmi)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biWidth = width; - bmi.bmiHeader.biHeight = -height; // top-down. - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biSizeImage = 0; - - if (format == QImage::Format_RGB16) { - bmi.bmiHeader.biBitCount = 16; - bmi.bmiHeader.biCompression = BI_BITFIELDS; - bmi.redMask = 0xF800; - bmi.greenMask = 0x07E0; - bmi.blueMask = 0x001F; - } else { - bmi.bmiHeader.biBitCount = 32; - bmi.bmiHeader.biCompression = BI_RGB; - bmi.redMask = 0; - bmi.greenMask = 0; - bmi.blueMask = 0; - } - - uchar *bits = Q_NULLPTR; - HBITMAP bitmap = CreateDIBSection(hdc, reinterpret_cast(&bmi), - DIB_RGB_COLORS, reinterpret_cast(&bits), 0, 0); - if (Q_UNLIKELY(!bitmap || !bits)) - qFatal("%s: CreateDIBSection failed.", __FUNCTION__); - - *bitsIn = bits; - return bitmap; -} - -QWindowsNativeImage::QWindowsNativeImage(int width, int height, - QImage::Format format) : - m_hdc(createDC()), - m_bitmap(0), - m_null_bitmap(0) -{ - if (width != 0 && height != 0) { - uchar *bits; - m_bitmap = createDIB(m_hdc, width, height, format, &bits); - m_null_bitmap = static_cast(SelectObject(m_hdc, m_bitmap)); - m_image = QImage(bits, width, height, format); - Q_ASSERT(m_image.paintEngine()->type() == QPaintEngine::Raster); - static_cast(m_image.paintEngine())->setDC(m_hdc); - } else { - m_image = QImage(width, height, format); - } - - GdiFlush(); -} - -QWindowsNativeImage::~QWindowsNativeImage() -{ - if (m_hdc) { - if (m_bitmap) { - if (m_null_bitmap) - SelectObject(m_hdc, m_null_bitmap); - DeleteObject(m_bitmap); - } - DeleteDC(m_hdc); - } -} - -QImage::Format QWindowsNativeImage::systemFormat() -{ - static const int depth = QWindowsContext::instance()->screenDepth(); - return depth == 16 ? QImage::Format_RGB16 : QImage::Format_RGB32; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsnativeimage.h b/src/plugins/platforms/windows/qwindowsnativeimage.h deleted file mode 100644 index bfe0f07dfd..0000000000 --- a/src/plugins/platforms/windows/qwindowsnativeimage.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSNATIVEIMAGE_H -#define QWINDOWSNATIVEIMAGE_H - -#include - -#include - -QT_BEGIN_NAMESPACE - -class QWindowsNativeImage -{ - Q_DISABLE_COPY(QWindowsNativeImage) -public: - QWindowsNativeImage(int width, int height, - QImage::Format format); - - ~QWindowsNativeImage(); - - inline int width() const { return m_image.width(); } - inline int height() const { return m_image.height(); } - - QImage &image() { return m_image; } - const QImage &image() const { return m_image; } - - HDC hdc() const { return m_hdc; } - - static QImage::Format systemFormat(); - -private: - const HDC m_hdc; - QImage m_image; - - HBITMAP m_bitmap; - HBITMAP m_null_bitmap; -}; - -QT_END_NAMESPACE - -#endif // QWINDOWSNATIVEIMAGE_H diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp index e0ae111b9a..eaa6e45b9f 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp @@ -41,7 +41,6 @@ #include "qwindowswindow.h" #include "qwindowscontext.h" #include "qwindowscursor.h" -#include "qwindowsfontdatabase.h" #include "qwindowsopenglcontext.h" #include "qwindowsopengltester.h" #include "qwindowsintegration.h" @@ -51,6 +50,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index fe67c0ce37..ed12c8124e 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -48,7 +48,6 @@ #include "qwindowscontext.h" #include "qwindowsintegration.h" #include "qt_windows.h" -#include "qwindowsfontdatabase.h" #include #include #ifndef Q_CC_MINGW @@ -69,6 +68,7 @@ #include #include #include +#include #include #include diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 0ebed59a1d..a9b061ad73 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qwindowswindow.h" -#include "qwindowsnativeimage.h" #include "qwindowscontext.h" #include "qwindowsdrag.h" #include "qwindowsscreen.h" diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri index 411c9e032b..d97e49309f 100644 --- a/src/plugins/platforms/windows/windows.pri +++ b/src/plugins/platforms/windows/windows.pri @@ -9,24 +9,12 @@ LIBS += -lshlwapi -lshell32 -ladvapi32 DEFINES *= QT_NO_CAST_FROM_ASCII -qtConfig(directwrite) { - qtConfig(directwrite2): \ - DEFINES *= QT_USE_DIRECTWRITE2 - - SOURCES += $$PWD/qwindowsfontenginedirectwrite.cpp - HEADERS += $$PWD/qwindowsfontenginedirectwrite.h -} else { - DEFINES *= QT_NO_DIRECTWRITE -} - SOURCES += \ $$PWD/qwindowswindow.cpp \ $$PWD/qwindowsintegration.cpp \ $$PWD/qwindowscontext.cpp \ $$PWD/qwindowsscreen.cpp \ $$PWD/qwindowskeymapper.cpp \ - $$PWD/qwindowsfontengine.cpp \ - $$PWD/qwindowsfontdatabase.cpp \ $$PWD/qwindowsmousehandler.cpp \ $$PWD/qwindowsole.cpp \ $$PWD/qwindowsmime.cpp \ @@ -36,7 +24,6 @@ SOURCES += \ $$PWD/qwindowstheme.cpp \ $$PWD/qwindowsdialoghelpers.cpp \ $$PWD/qwindowsservices.cpp \ - $$PWD/qwindowsnativeimage.cpp \ $$PWD/qwindowsnativeinterface.cpp \ $$PWD/qwindowsopengltester.cpp @@ -46,8 +33,6 @@ HEADERS += \ $$PWD/qwindowscontext.h \ $$PWD/qwindowsscreen.h \ $$PWD/qwindowskeymapper.h \ - $$PWD/qwindowsfontengine.h \ - $$PWD/qwindowsfontdatabase.h \ $$PWD/qwindowsmousehandler.h \ $$PWD/qtwindowsglobal.h \ $$PWD/qwindowsole.h \ @@ -58,7 +43,6 @@ HEADERS += \ $$PWD/qwindowstheme.h \ $$PWD/qwindowsdialoghelpers.h \ $$PWD/qwindowsservices.h \ - $$PWD/qwindowsnativeimage.h \ $$PWD/qwindowsnativeinterface.h \ $$PWD/qwindowsopengltester.h \ $$PWD/qwindowsthreadpoolrunner.h @@ -111,11 +95,6 @@ qtConfig(dynamicgl) { RESOURCES += $$PWD/openglblacklists.qrc -qtConfig(freetype) { - HEADERS += $$PWD/qwindowsfontdatabase_ft.h - SOURCES += $$PWD/qwindowsfontdatabase_ft.cpp -} - qtConfig(accessibility): include($$PWD/accessible/accessible.pri) DEFINES *= LIBEGL_NAME=$${LIBEGL_NAME} -- cgit v1.2.3 From 8d9c42e36217e14efa69974c2cdc8d90f465a959 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 27 Oct 2016 09:49:24 +0200 Subject: xcb: Avoid crash when requesting non-supported stereo formats Introduced in the 5.7 branch by 5f39a0ef8d037ed8d1fa19d5514308ed4a2ca161. Add also a warning in the GLX backend instead of just dereferencing the null pointer. Task-number: QTBUG-55291 Change-Id: I1f2930768b39a04ee443a68d0ac7dc9ecf26cb9c Reviewed-by: Louai Al-Khanji --- src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp index 8ae83b8084..a8d51d5e8c 100644 --- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp +++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qxcbglxwindow.cpp @@ -59,6 +59,10 @@ const xcb_visualtype_t *QXcbGlxWindow::createVisual() if (!scr) return Q_NULLPTR; XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(scr), scr->screenNumber(), &m_format); + if (!visualInfo) { + qWarning() << "No XVisualInfo for format" << m_format; + return Q_NULLPTR; + } const xcb_visualtype_t *xcb_visualtype = scr->visualForId(visualInfo->visualid); XFree(visualInfo); return xcb_visualtype; -- cgit v1.2.3 From f577a01f5e8d9678d268917ca727a6e9a3e819a6 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 27 Oct 2016 12:29:26 +0200 Subject: eglfs: Cast to EGLNativeDisplayType in EGLDevice backend When compiling with EGL native types being the Xlib types (uncommon since we disable this both for Mesa and NVIDIA embedded, but can happen with other vendor's headers), the types for EGLDeviceEXT (void*) and EGLNativeDisplayType (Display, i.e. _XDisplay*) won't match, breaking compilation. At runtime we won't hit that path, so all we need to ensure is that the code compiles. Do this via a cast. When the native types are generic, both types are void* so the cast has no effect. Change-Id: Ib54f569d4494906f74107f08b47bd6b521d700db Reviewed-by: Louai Al-Khanji --- .../eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp index 743f714cf0..f6e86bf0bc 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp @@ -71,7 +71,7 @@ void QEglFSKmsEglDevice::close() EGLNativeDisplayType QEglFSKmsEglDevice::nativeDisplay() const { - return static_cast(m_integration)->eglDevice(); + return reinterpret_cast(static_cast(m_integration)->eglDevice()); } QEglFSKmsScreen *QEglFSKmsEglDevice::createScreen(QEglFSKmsIntegration *integration, QEglFSKmsDevice *device, QEglFSKmsOutput output, QPoint position) -- cgit v1.2.3 From f9280ba45ed6e492871cd25026a1bce7a17042dc Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 24 Oct 2016 13:49:41 -0700 Subject: QNSColorPanelDelegate: Don't restore stolen view on dealloc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We may not be playing nice with Cocoa's internals when we decide to reparent NSColorPanel's contents to add QColorDialog's own OK/Cancel buttons. In order to reduce issues, we should avoid poking at things during the application's shutdown sequence. Simply releasing the stolen view should be enough at that point. A similar pattern exists in QNSFontPanelDelegate. Change-Id: I678c236e0c57c4d08a1109a479d965f924288c54 Task-number: QTBUG-56448 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov Reviewed-by: Erik Verbruggen --- src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm | 2 +- src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index ed17ef8fe9..3c924bec94 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -116,7 +116,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); - (void)dealloc { - [self restoreOriginalContentView]; + [mStolenContentView release]; [mColorPanel setDelegate:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index d1802fe4f9..5b27dc1da9 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -144,7 +144,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); - (void)dealloc { - [self restoreOriginalContentView]; + [mStolenContentView release]; [mFontPanel setDelegate:nil]; [[NSFontManager sharedFontManager] setDelegate:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; -- cgit v1.2.3 From 8cd812455932f896b45aae84c4dc571f60f60b25 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 28 Oct 2016 14:11:21 +0200 Subject: Windows QPA: Do not use QSettings to access the registry When commenting out the warning in createOrOpenKey() (src\corelib\io\qsettings_win.cpp:157), applications produce warnings: QSettings: Failed to create subkey "Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes": Access is denied. indicating that an attempt to open the registry in read/write mode fails. Add a utility function to read out registry strings in read-only mode to the font database and use that instead. Change-Id: I4187344cac7ec2ba27f15b51e237575efc171853 Reviewed-by: Joerg Bornemann --- .../windows/accessible/qwindowsaccessibility.cpp | 24 +++++++++++----------- .../windows/accessible/qwindowsmsaaaccessible.cpp | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp b/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp index 7cf24421f8..aed9c94003 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp +++ b/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp @@ -47,13 +47,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include // registry helper #include "qwindowsaccessibility.h" #ifdef Q_CC_MINGW @@ -114,6 +114,14 @@ static inline QString messageBoxAlertSound(const QObject *messageBox) return QString(); } +static QString soundFileName(const QString &soundName) +{ + const QString key = QStringLiteral("AppEvents\\Schemes\\Apps\\.Default\\") + + soundName + QStringLiteral("\\.Current"); + return QWindowsFontDatabase::readRegistryString(HKEY_CURRENT_USER, + reinterpret_cast(key.utf16()), L""); +} + void QWindowsAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event) { QString soundName; @@ -134,17 +142,9 @@ void QWindowsAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event) break; } - if (!soundName.isEmpty()) { -#ifndef QT_NO_SETTINGS - QSettings settings(QLatin1String("HKEY_CURRENT_USER\\AppEvents\\Schemes\\Apps\\.Default\\") + soundName, - QSettings::NativeFormat); - QString file = settings.value(QLatin1String(".Current/.")).toString(); -#else - QString file; -#endif - if (!file.isEmpty()) { - PlaySound(reinterpret_cast(soundName.utf16()), 0, SND_ALIAS | SND_ASYNC | SND_NODEFAULT | SND_NOWAIT); - } + if (!soundName.isEmpty() && !soundFileName(soundName).isEmpty()) { + PlaySound(reinterpret_cast(soundName.utf16()), 0, + SND_ALIAS | SND_ASYNC | SND_NODEFAULT | SND_NOWAIT); } // An event has to be associated with a window, diff --git a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp index ff115a2249..9803dedb1e 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp +++ b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3 From 4039568837919fa3e172a71950b235fcf1ddedc7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 27 Oct 2016 09:17:54 +0200 Subject: Direct2d: Add missing dependency to platformsupport's accessibility Change-Id: I620370bb5f4bbac11c1e5740c706e0cb64d9d407 Reviewed-by: Joerg Bornemann --- src/plugins/platforms/direct2d/direct2d.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/direct2d/direct2d.pro b/src/plugins/platforms/direct2d/direct2d.pro index c30703720c..224f122fc4 100644 --- a/src/plugins/platforms/direct2d/direct2d.pro +++ b/src/plugins/platforms/direct2d/direct2d.pro @@ -2,7 +2,7 @@ TARGET = qdirect2d QT += \ core-private gui-private \ - eventdispatcher_support-private \ + eventdispatcher_support-private accessibility_support-private \ fontdatabase_support-private theme_support-private LIBS += -ldwmapi -ld2d1 -ld3d11 -ldwrite -lVersion -lgdi32 -- cgit v1.2.3 From f2f39946d2911fe1157d3f71094cc7acf06e2f46 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 28 Oct 2016 11:57:38 +0200 Subject: Fix a mis-merge in af0d0b9 "-framework AudioToolbox" was lost. Task-number: QTBUG-56784 Change-Id: Ibd536c53e7e1456077559c021a70407339f33971 Reviewed-by: Richard Moe Gustavsen --- src/plugins/platforms/ios/kernel.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro index d8235ee011..955f8d9642 100644 --- a/src/plugins/platforms/ios/kernel.pro +++ b/src/plugins/platforms/ios/kernel.pro @@ -1,7 +1,7 @@ TARGET = qios QT += core-private gui-private platformsupport-private -LIBS += -framework Foundation -framework UIKit -framework QuartzCore +LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AudioToolbox OBJECTIVE_SOURCES = \ plugin.mm \ -- cgit v1.2.3 From f9ec707e4960bf7d5298ee2ba8f22d7506ef54a7 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 18 Oct 2016 10:56:11 -0700 Subject: windows: Disable OpenGL proper on Intel 945 Change-Id: I77fbf5bafcd6b0fe5040513ef6b0d049600f9b33 Task-number: QTBUG-40991 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/openglblacklists/default.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/openglblacklists/default.json b/src/plugins/platforms/windows/openglblacklists/default.json index 1e00da52eb..dd99e674ec 100644 --- a/src/plugins/platforms/windows/openglblacklists/default.json +++ b/src/plugins/platforms/windows/openglblacklists/default.json @@ -102,6 +102,18 @@ "features": [ "disable_desktopgl", "disable_d3d11", "disable_d3d9" ] + }, + { + "id": 9, + "description": "Intel 945 crash (QTBUG-40991)", + "vendor_id": "0x8086", + "device_id": [ "0x27A2" ], + "os": { + "type": "win" + }, + "features": [ + "disable_desktopgl" + ] } ] } -- cgit v1.2.3 From ca5d4137aa352d61d796c82b06e2d8f19a07cf10 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 27 Oct 2016 12:37:02 +0200 Subject: minimalegl: Reorder includes to avoid EGL native type clashes Some of the qminimaleglscreen.h includes are not even necessary. With the inclusion of egl.h (or qt_egl_p.h in 5.7 and up) isolated to this header, all we need to ensure is that the sources that include it place the include at a suitable place. This is not the only possible solution, there are alternatives (each with its own caveat), but this is likely the least intrusive. Task-number: QTBUG-56559 Change-Id: I17db031c8e401d9895a417ba3568ad1e4ba30f72 Reviewed-by: Louai Al-Khanji --- src/plugins/platforms/minimalegl/qminimaleglintegration.cpp | 3 ++- src/plugins/platforms/minimalegl/qminimaleglintegration.h | 2 -- src/plugins/platforms/minimalegl/qminimaleglwindow.h | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp b/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp index 1bcb22618e..5328a8b353 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp +++ b/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp @@ -52,7 +52,8 @@ #include #include -#include +// this is where EGL headers are pulled in, make sure it is last +#include "qminimaleglscreen.h" QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/minimalegl/qminimaleglintegration.h b/src/plugins/platforms/minimalegl/qminimaleglintegration.h index 7a2c23ced4..8ceeb7b193 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglintegration.h +++ b/src/plugins/platforms/minimalegl/qminimaleglintegration.h @@ -34,8 +34,6 @@ #ifndef QMINIMALEGLINTEGRATION_H #define QMINIMALEGLINTEGRATION_H -#include "qminimaleglscreen.h" - #include #include diff --git a/src/plugins/platforms/minimalegl/qminimaleglwindow.h b/src/plugins/platforms/minimalegl/qminimaleglwindow.h index ba7f999602..4edeaf4da9 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglwindow.h +++ b/src/plugins/platforms/minimalegl/qminimaleglwindow.h @@ -35,7 +35,6 @@ #define QMINIMALEGLWINDOW_H #include "qminimaleglintegration.h" -#include "qminimaleglscreen.h" #include -- cgit v1.2.3