From b686d77aaf5767c6f93f949995fde167fa335578 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 21 Aug 2019 14:21:11 +0200 Subject: [PATCH] Fix font height handling in MSW wxNativeFontInfo::FromString() This is similar to 228cd926e27589ee514682513cc8d89aabc9a603, but extends the fix to v1 strings, as even though they have the "point size" field, this field may still contain 0, resulting in the same problem as with v0 strings, i.e. 0-sized fonts. Closes #18467. --- src/msw/font.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 3d7d7e0f33..e3e8012042 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -658,13 +658,15 @@ bool wxNativeFontInfo::FromString(const wxString& s) if ( !token.ToLong(&l) ) return false; - bool setPointSizeFromHeight = false; + // If fractional point size is not present (which can happen if we have a + // string in version 0 or even with version 1 if it doesn't contain a valid + // point size), ensure that we set it from lfHeight below. + bool setPointSizeFromHeight = true; switch ( l ) { case 0: - // Fractional point size is not present in this version, it will be - // set from lfHeight below in this case. - setPointSizeFromHeight = true; + // Fractional point size is not present in this version, so nothing + // special to do. break; case 1: @@ -672,9 +674,17 @@ bool wxNativeFontInfo::FromString(const wxString& s) double d; if ( !tokenizer.GetNextToken().ToCDouble(&d) ) return false; - pointSize = static_cast(d); - if ( static_cast(pointSize) != d ) - return false; + + // If the size is present but 0, ignore it and still use + // lfHeight, as with v0 strings. + if ( !wxIsNullDouble(d) ) + { + pointSize = static_cast(d); + if ( static_cast(pointSize) != d ) + return false; + + setPointSizeFromHeight = false; + } } break;