Merge branch 'msw-fontinfo-v0-fix'

Fix a user visible regression after fractional point size changes: don't
create 0-sized fonts from the wxNativeFontInfo version 0 strings.

See https://github.com/wxWidgets/wxWidgets/pull/1422
This commit is contained in:
Vadim Zeitlin
2019-07-16 23:20:37 +02:00
2 changed files with 18 additions and 8 deletions

View File

@@ -118,7 +118,14 @@ public:
// set the XFLD // set the XFLD
void SetXFontName(const wxString& xFontName); void SetXFontName(const wxString& xFontName);
#elif defined(__WXMSW__) #elif defined(__WXMSW__)
wxNativeFontInfo(const LOGFONT& lf_); wxNativeFontInfo(const LOGFONT& lf_)
: lf(lf_),
pointSize(GetPointSizeFromLogFontHeight(lf.lfHeight))
{
}
// MSW-specific: get point size from LOGFONT height using the default DPI.
static float GetPointSizeFromLogFontHeight(int height);
// MSW-specific: get the height value in pixels using LOGFONT convention // MSW-specific: get the height value in pixels using LOGFONT convention
// (i.e. negative) corresponding to the given size in points and DPI. // (i.e. negative) corresponding to the given size in points and DPI.

View File

@@ -402,13 +402,13 @@ void wxFontRefData::Free()
// wxNativeFontInfo // wxNativeFontInfo
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxNativeFontInfo::wxNativeFontInfo(const LOGFONT& lf_) /* static */
: lf(lf_) float wxNativeFontInfo::GetPointSizeFromLogFontHeight(int height)
{ {
// Determine the size in points using the primary screen DPI as we don't // Determine the size in points using the primary screen DPI as we don't
// have anything else here. // have anything else here.
const float ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY); const float ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
pointSize = 72.0f * abs(lf.lfHeight) / ppi; return 72.0f * abs(height) / ppi;
} }
void wxNativeFontInfo::Init() void wxNativeFontInfo::Init()
@@ -535,8 +535,7 @@ void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
// We don't have the right DPI to use here neither, but we need to update // We don't have the right DPI to use here neither, but we need to update
// the point size too, so fall back to the default. // the point size too, so fall back to the default.
const float ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY); pointSize = GetPointSizeFromLogFontHeight(lf.lfHeight);
pointSize = 72.0f * pixelSize.GetHeight() / ppi;
} }
void wxNativeFontInfo::SetStyle(wxFontStyle style) void wxNativeFontInfo::SetStyle(wxFontStyle style)
@@ -659,11 +658,13 @@ bool wxNativeFontInfo::FromString(const wxString& s)
if ( !token.ToLong(&l) ) if ( !token.ToLong(&l) )
return false; return false;
bool setPointSizeFromHeight = false;
switch ( l ) switch ( l )
{ {
case 0: case 0:
// Fractional point size is not present in this version. // Fractional point size is not present in this version, it will be
pointSize = 0.0f; // set from lfHeight below in this case.
setPointSizeFromHeight = true;
break; break;
case 1: case 1:
@@ -686,6 +687,8 @@ bool wxNativeFontInfo::FromString(const wxString& s)
if ( !token.ToLong(&l) ) if ( !token.ToLong(&l) )
return false; return false;
lf.lfHeight = l; lf.lfHeight = l;
if ( setPointSizeFromHeight )
pointSize = GetPointSizeFromLogFontHeight(l);
token = tokenizer.GetNextToken(); token = tokenizer.GetNextToken();
if ( !token.ToLong(&l) ) if ( !token.ToLong(&l) )