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>
This commit is contained in:
Friedemann Kleint 2020-04-23 06:32:56 +02:00
parent fc8c011450
commit f061c413de
3 changed files with 15 additions and 12 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;
}