From 2823e289d8e190fdcd4b0f39bfee68019ca32fb9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Sep 2018 17:49:21 +0200 Subject: [PATCH] Store fractional point size in wxMSW wxNativeFontInfo We can't losslessly recover the fractional point size from LOGFONT, so store it in parallel. --- include/wx/fontutil.h | 7 ++++++- src/msw/font.cpp | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index b117ec1b29..33e9313755 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -118,9 +118,14 @@ public: // set the XFLD void SetXFontName(const wxString& xFontName); #elif defined(__WXMSW__) - wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { } + wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_), pointSize(0.0f) { } LOGFONT lf; + + // MSW only has limited support for fractional point sizes and we need to + // store the fractional point size separately if it was initially specified + // as we can't losslessly recover it from LOGFONT later. + float pointSize; #elif defined(__WXOSX__) public: wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); } diff --git a/src/msw/font.cpp b/src/msw/font.cpp index f8ae3aaabb..9c8c48e2c6 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -440,10 +440,15 @@ void wxNativeFontInfo::Init() lf.lfQuality = wxSystemOptions::GetOptionInt("msw.font.no-proof-quality") ? DEFAULT_QUALITY : PROOF_QUALITY; + + pointSize = 0.0f; } float wxNativeFontInfo::GetFractionalPointSize() const { + if ( pointSize != 0.0f ) + return pointSize; + // FIXME: using the screen here results in incorrect font size calculation // for printing! const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY); @@ -531,6 +536,10 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const void wxNativeFontInfo::SetFractionalPointSize(float pointsize) { + // Store it to be able to return it from GetFractionalPointSize() later + // exactly. + pointSize = pointsize; + // FIXME: using the screen here results in incorrect font size calculation // for printing! const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);