Fix size of the font returned from wxFontDialog in wxMSW

Ensure that the font has exactly the point size entered in the dialog,
rather than having a fractional point size close, but not identical, to
it, as happened before due to first rounding the result of converting
the point size to pixels and then _not_ rounding the result of the
reverse conversion.

This resulted in wxFont::GetPointSize() returning the correct value, but
not GetFractionalPointSize(). Now the latter returns the same, correctly
rounded, value too.
This commit is contained in:
Vadim Zeitlin 2022-04-18 15:45:10 +01:00
parent 91f1be23dd
commit 87a0472485

View File

@ -206,7 +206,18 @@ int wxFontDialog::ShowModal()
);
}
m_fontData.m_chosenFont = wxFont(wxNativeFontInfo(logFont, parent));
wxFont f(wxNativeFontInfo(logFont, parent));
// The native dialog allows selecting only integer font sizes in
// points, but converting them to pixel height loses precision and so
// converting them back to points may result in a fractional value
// different from the value selected in the dialog. So ensure that we
// use exactly the same font size in points as what was selected in the
// dialog by rounding the possibly fractional value to the integer ones
// entered there.
f.SetPointSize(wxRound(f.GetFractionalPointSize()));
m_fontData.m_chosenFont = f;
m_fontData.EncodingInfo().facename = logFont.lfFaceName;
m_fontData.EncodingInfo().charset = logFont.lfCharSet;