Windows QPA: Hardcode a limit for the default point size

Windows uses deprecated API to obtain the default font which
has been observed to return bogus sizes in multi monitor setups.
Apply a limit in this case and add fixme comment for Qt 6.

Task-number: QTBUG-49374
Task-number: QTBUG-58610
Change-Id: I6e805ec792a3f425961a48ef4c4329c3cdf302b6
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Friedemann Kleint 2016-07-20 15:47:16 +02:00
parent e938150412
commit a72513cab7

View File

@ -1621,6 +1621,7 @@ void QWindowsFontDatabase::refUniqueFont(const QString &uniqueFont)
m_uniqueFontData[uniqueFont].refCount.ref();
}
// ### fixme Qt 6 (QTBUG-58610): See comment at QWindowsFontDatabase::systemDefaultFont()
HFONT QWindowsFontDatabase::systemFont()
{
static const HFONT stock_sysfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
@ -1961,12 +1962,31 @@ QFontEngine *QWindowsFontDatabase::createEngine(const QFontDef &request, const Q
QFont QWindowsFontDatabase::systemDefaultFont()
{
#if QT_VERSION >= 0x060000
// Qt 6: Obtain default GUI font (typically "Segoe UI, 9pt", see QTBUG-58610)
NONCLIENTMETRICS ncm;
ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize , &ncm, 0);
const QFont systemFont = QWindowsFontDatabase::LOGFONT_to_QFont(ncm.lfMessageFont);
#else
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"));
// Qt 5 by (Qt 4) legacy uses GetStockObject(DEFAULT_GUI_FONT) to
// obtain the default GUI font (typically "MS Shell Dlg 2, 8pt"). This has been
// long deprecated; the message font of the NONCLIENTMETRICS structure obtained by
// SystemParametersInfo(SPI_GETNONCLIENTMETRICS) should be used instead (see
// QWindowsTheme::refreshFonts(), typically "Segoe UI, 9pt"), which is larger.
// In single monitor setups, the point sizes revolve around 8 (depending on UI
// scale factor, but not proportional to it). However, in multi monitor setups,
// where the DPI of the primary monitor are smaller than those of the secondary,
// large bogus values are returned. Limit to 8.25 in that case.
if (GetSystemMetrics(SM_CMONITORS) > 1 && systemFont.pointSizeF() > 8.25)
systemFont.setPointSizeF(8.25);
#endif // Qt 5
qCDebug(lcQpaFonts) << __FUNCTION__ << systemFont;
return systemFont;
}