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:
parent
fc8c011450
commit
f061c413de
@ -624,19 +624,16 @@ void QWindowsFontDatabaseBase::createDirectWriteFactory(IDWriteFactory **factory
|
|||||||
}
|
}
|
||||||
#endif // !defined(QT_NO_DIRECTWRITE)
|
#endif // !defined(QT_NO_DIRECTWRITE)
|
||||||
|
|
||||||
|
static int s_defaultVerticalDPI = 96; // Native Pixels
|
||||||
|
|
||||||
int QWindowsFontDatabaseBase::defaultVerticalDPI()
|
int QWindowsFontDatabaseBase::defaultVerticalDPI()
|
||||||
{
|
{
|
||||||
static int vDPI = -1;
|
return s_defaultVerticalDPI;
|
||||||
if (vDPI == -1) {
|
}
|
||||||
if (HDC defaultDC = GetDC(0)) {
|
|
||||||
vDPI = GetDeviceCaps(defaultDC, LOGPIXELSY);
|
void QWindowsFontDatabaseBase::setDefaultVerticalDPI(int d)
|
||||||
ReleaseDC(0, defaultDC);
|
{
|
||||||
} else {
|
s_defaultVerticalDPI = d;
|
||||||
// FIXME: Resolve now or return 96 and keep unresolved?
|
|
||||||
vDPI = 96;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return vDPI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGFONT QWindowsFontDatabaseBase::fontDefToLOGFONT(const QFontDef &request, const QString &faceName)
|
LOGFONT QWindowsFontDatabaseBase::fontDefToLOGFONT(const QFontDef &request, const QString &faceName)
|
||||||
|
@ -93,6 +93,8 @@ public:
|
|||||||
QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
|
QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
|
||||||
|
|
||||||
static int defaultVerticalDPI();
|
static int defaultVerticalDPI();
|
||||||
|
static void setDefaultVerticalDPI(int d);
|
||||||
|
|
||||||
static QSharedPointer<QWindowsFontEngineData> data();
|
static QSharedPointer<QWindowsFontEngineData> data();
|
||||||
#if !defined(QT_NO_DIRECTWRITE)
|
#if !defined(QT_NO_DIRECTWRITE)
|
||||||
static void createDirectWriteFactory(IDWriteFactory **factory);
|
static void createDirectWriteFactory(IDWriteFactory **factory);
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include <QtGui/qguiapplication.h>
|
#include <QtGui/qguiapplication.h>
|
||||||
#include <qpa/qwindowsysteminterface.h>
|
#include <qpa/qwindowsysteminterface.h>
|
||||||
#include <private/qhighdpiscaling_p.h>
|
#include <private/qhighdpiscaling_p.h>
|
||||||
|
#include <private/qwindowsfontdatabasebase_p.h>
|
||||||
#include <QtGui/qscreen.h>
|
#include <QtGui/qscreen.h>
|
||||||
|
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
@ -111,8 +112,11 @@ static bool monitorData(HMONITOR hMonitor, QWindowsScreenData *data)
|
|||||||
// EnumDisplayMonitors (as opposed to EnumDisplayDevices) enumerates only
|
// EnumDisplayMonitors (as opposed to EnumDisplayDevices) enumerates only
|
||||||
// virtual desktop screens.
|
// virtual desktop screens.
|
||||||
data->flags |= QWindowsScreenData::VirtualDesktop;
|
data->flags |= QWindowsScreenData::VirtualDesktop;
|
||||||
if (info.dwFlags & MONITORINFOF_PRIMARY)
|
if (info.dwFlags & MONITORINFOF_PRIMARY) {
|
||||||
data->flags |= QWindowsScreenData::PrimaryScreen;
|
data->flags |= QWindowsScreenData::PrimaryScreen;
|
||||||
|
if ((data->flags & QWindowsScreenData::LockScreen) == 0)
|
||||||
|
QWindowsFontDatabase::setDefaultVerticalDPI(data->dpi.second);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user