Port default font resolve to SystemParametersInfoForDpi
We were getting font metrics for the primary screen and then adjusting for the screen DPI get a screen-independent font size. This could fail in edge cases where the screen DPI was changed after app startup, but before the first window was shown. See QTBUG-105857. Use SystemParametersInfoForDpi() to query for font info at 96 DPI instead, which removes the need for tracking primary screen DPI. LOGFONT_to_QFont() still has one usage (qwizard_win.cpp) which provides a custom DPI for scaling, so we keep that function as-is. Fixes: QTBUG-105857 Change-Id: I1adf0ab3bf2c309e8fcb58093e86214fa11a2da8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit edb00660e47a82ac24048841100d7d7e59a7805e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ef581555b3
commit
45358c29d5
@ -566,16 +566,9 @@ void QWindowsFontDatabaseBase::createDirectWriteFactory(IDWriteFactory **factory
|
|||||||
}
|
}
|
||||||
#endif // directwrite && direct2d
|
#endif // directwrite && direct2d
|
||||||
|
|
||||||
static int s_defaultVerticalDPI = 96; // Native Pixels
|
|
||||||
|
|
||||||
int QWindowsFontDatabaseBase::defaultVerticalDPI()
|
int QWindowsFontDatabaseBase::defaultVerticalDPI()
|
||||||
{
|
{
|
||||||
return s_defaultVerticalDPI;
|
return 96;
|
||||||
}
|
|
||||||
|
|
||||||
void QWindowsFontDatabaseBase::setDefaultVerticalDPI(int d)
|
|
||||||
{
|
|
||||||
s_defaultVerticalDPI = d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGFONT QWindowsFontDatabaseBase::fontDefToLOGFONT(const QFontDef &request, const QString &faceName)
|
LOGFONT QWindowsFontDatabaseBase::fontDefToLOGFONT(const QFontDef &request, const QString &faceName)
|
||||||
@ -690,9 +683,9 @@ HFONT QWindowsFontDatabaseBase::systemFont()
|
|||||||
QFont QWindowsFontDatabaseBase::systemDefaultFont()
|
QFont QWindowsFontDatabaseBase::systemDefaultFont()
|
||||||
{
|
{
|
||||||
// Qt 6: Obtain default GUI font (typically "Segoe UI, 9pt", see QTBUG-58610)
|
// Qt 6: Obtain default GUI font (typically "Segoe UI, 9pt", see QTBUG-58610)
|
||||||
NONCLIENTMETRICS ncm;
|
NONCLIENTMETRICS ncm = {};
|
||||||
ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT);
|
ncm.cbSize = sizeof(ncm);
|
||||||
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize , &ncm, 0);
|
SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0, defaultVerticalDPI());
|
||||||
const QFont systemFont = QWindowsFontDatabase::LOGFONT_to_QFont(ncm.lfMessageFont);
|
const QFont systemFont = QWindowsFontDatabase::LOGFONT_to_QFont(ncm.lfMessageFont);
|
||||||
qCDebug(lcQpaFonts) << __FUNCTION__ << systemFont;
|
qCDebug(lcQpaFonts) << __FUNCTION__ << systemFont;
|
||||||
return systemFont;
|
return systemFont;
|
||||||
|
@ -57,7 +57,6 @@ 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 QT_CONFIG(directwrite)
|
#if QT_CONFIG(directwrite)
|
||||||
|
@ -182,11 +182,8 @@ 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