summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-04-23 06:32:56 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-05-25 08:52:32 +0200
commitf061c413de2e3fdc4cc1578f420651a7c45da3e9 (patch)
tree7ec4dd6cde58865160286d96dcba841b1d3e8e55 /src
parentfc8c011450c0326d05a8c0098a294cafbbb50191 (diff)
Windows: Fix wrong DPI used in font size after changing scaling
QWindowsFontDatabase::defaultVerticalDPI(), which was used for converting the point sizes was missing an updating logic for scaling changes. When implementing it, it turned out that the value obtained from GetDC(0) does not adapt to scaling changes. Remove the function and set it from the screen manager directly to the DPI of the primary screen. Pick-to: 5.15 Task-number: QTBUG-82267 Change-Id: If05ebc893fe78a9461500aba97f2dc127cdf4406 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase.cpp19
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase_p.h2
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp6
3 files changed, 15 insertions, 12 deletions
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase.cpp
index e6dee54d84..568d1463e7 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase.cpp
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase.cpp
@@ -624,19 +624,16 @@ void QWindowsFontDatabaseBase::createDirectWriteFactory(IDWriteFactory **factory
}
#endif // !defined(QT_NO_DIRECTWRITE)
+static int s_defaultVerticalDPI = 96; // Native Pixels
+
int QWindowsFontDatabaseBase::defaultVerticalDPI()
{
- static int vDPI = -1;
- if (vDPI == -1) {
- if (HDC defaultDC = GetDC(0)) {
- vDPI = GetDeviceCaps(defaultDC, LOGPIXELSY);
- ReleaseDC(0, defaultDC);
- } else {
- // FIXME: Resolve now or return 96 and keep unresolved?
- vDPI = 96;
- }
- }
- return vDPI;
+ return s_defaultVerticalDPI;
+}
+
+void QWindowsFontDatabaseBase::setDefaultVerticalDPI(int d)
+{
+ s_defaultVerticalDPI = d;
}
LOGFONT QWindowsFontDatabaseBase::fontDefToLOGFONT(const QFontDef &request, const QString &faceName)
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase_p.h
index 5b9db5dede..55763f7c76 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase_p.h
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabasebase_p.h
@@ -93,6 +93,8 @@ public:
QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
static int defaultVerticalDPI();
+ static void setDefaultVerticalDPI(int d);
+
static QSharedPointer<QWindowsFontEngineData> data();
#if !defined(QT_NO_DIRECTWRITE)
static void createDirectWriteFactory(IDWriteFactory **factory);
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index 8850d8cdd4..689624ff2a 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -51,6 +51,7 @@
#include <QtGui/qguiapplication.h>
#include <qpa/qwindowsysteminterface.h>
#include <private/qhighdpiscaling_p.h>
+#include <private/qwindowsfontdatabasebase_p.h>
#include <QtGui/qscreen.h>
#include <QtCore/qdebug.h>
@@ -111,8 +112,11 @@ static bool monitorData(HMONITOR hMonitor, QWindowsScreenData *data)
// EnumDisplayMonitors (as opposed to EnumDisplayDevices) enumerates only
// virtual desktop screens.
data->flags |= QWindowsScreenData::VirtualDesktop;
- if (info.dwFlags & MONITORINFOF_PRIMARY)
+ if (info.dwFlags & MONITORINFOF_PRIMARY) {
data->flags |= QWindowsScreenData::PrimaryScreen;
+ if ((data->flags & QWindowsScreenData::LockScreen) == 0)
+ QWindowsFontDatabase::setDefaultVerticalDPI(data->dpi.second);
+ }
return true;
}