From 72a225924dbd590a674f30ca93d4efd54447cdb6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Dec 2018 16:25:41 +0100 Subject: [PATCH] Remove wxCreateFontFromLogFont() and wxFillLogFont() These functions are not really useful as converting between wxFont and LOGFONT can be done trivially by passing via wxNativeFontInfo and, in fact, wxCreateFontFromLogFont() managed to do the conversion wrongly by forgetting to update wxNativeFontInfo::pointSize member when changing wxNativeFontInfo::lf. This fixes one unit test failure after the latest changes, although not yet the other one, see the upcoming commit for this. --- include/wx/msw/private.h | 2 -- src/msw/fontdlg.cpp | 6 ++++-- src/msw/fontutil.cpp | 32 -------------------------------- src/msw/settings.cpp | 2 +- src/msw/textctrl.cpp | 10 +++++----- 5 files changed, 10 insertions(+), 42 deletions(-) diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 457ecb757d..1a426fd9ba 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -961,8 +961,6 @@ extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp WXDLLIMPEXP_CORE void wxGetCursorPosMSW(POINT* pt); WXDLLIMPEXP_CORE void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font); -WXDLLIMPEXP_CORE void wxFillLogFont(LOGFONT *logFont, const wxFont *font); -WXDLLIMPEXP_CORE wxFont wxCreateFontFromLogFont(const LOGFONT *logFont); WXDLLIMPEXP_CORE wxFontEncoding wxGetFontEncFromCharSet(int charset); inline void wxSetWindowFont(HWND hwnd, const wxFont& font) diff --git a/src/msw/fontdlg.cpp b/src/msw/fontdlg.cpp index 2f7e6bb8d5..8edd4a9f91 100644 --- a/src/msw/fontdlg.cpp +++ b/src/msw/fontdlg.cpp @@ -36,6 +36,8 @@ #include "wx/math.h" #endif +#include "wx/fontutil.h" + #include #include @@ -118,7 +120,7 @@ int wxFontDialog::ShowModal() if ( m_fontData.m_initialFont.IsOk() ) { flags |= CF_INITTOLOGFONTSTRUCT; - wxFillLogFont(&logFont, &m_fontData.m_initialFont); + logFont = m_fontData.m_initialFont.GetNativeFontInfo()->lf; } if ( m_fontData.m_fontColour.IsOk() ) @@ -150,7 +152,7 @@ int wxFontDialog::ShowModal() if ( ChooseFont(&chooseFontStruct) != 0 ) { wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors); - m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont); + m_fontData.m_chosenFont = wxFont(wxNativeFontInfo(logFont)); m_fontData.EncodingInfo().facename = logFont.lfFaceName; m_fontData.EncodingInfo().charset = logFont.lfCharSet; diff --git a/src/msw/fontutil.cpp b/src/msw/fontutil.cpp index 3a6489b392..975ba52a02 100644 --- a/src/msw/fontutil.cpp +++ b/src/msw/fontutil.cpp @@ -264,35 +264,3 @@ wxFontEncoding wxGetFontEncFromCharSet(int cs) return fontEncoding; } - -// ---------------------------------------------------------------------------- -// wxFont <-> LOGFONT conversion -// ---------------------------------------------------------------------------- - -void wxFillLogFont(LOGFONT *logFont, const wxFont *font) -{ - wxNativeFontInfo fi; - - // maybe we already have LOGFONT for this font? - const wxNativeFontInfo *pFI = font->GetNativeFontInfo(); - if ( !pFI ) - { - // use wxNativeFontInfo methods to build a LOGFONT for this font - fi.InitFromFont(*font); - - pFI = &fi; - } - - // transfer all the data to LOGFONT - *logFont = pFI->lf; -} - -wxFont wxCreateFontFromLogFont(const LOGFONT *logFont) -{ - wxNativeFontInfo info; - - info.lf = *logFont; - - return wxFont(info); -} - diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 3377b5b080..0581dc1a08 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -345,7 +345,7 @@ extern wxFont wxGetCCDefaultFont() 0 ) ) { - return wxFont(wxCreateFontFromLogFont(&lf)); + return wxFont(lf); } else { diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index fed5741b58..2fb9da0c49 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -40,6 +40,7 @@ #include "wx/wxcrtvararg.h" #endif +#include "wx/fontutil.h" #include "wx/scopedptr.h" #include "wx/stack.h" #include "wx/sysopt.h" @@ -2826,14 +2827,13 @@ bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr& style, long start, long end) CFM_ITALIC | CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT; // fill in data from LOGFONT but recalculate lfHeight because we need - // the real height in twips and not the negative number which - // wxFillLogFont() returns (this is correct in general and works with + // the real height in twips and not the negative number used inside + // LOGFONT returns (this is correct in general and works with // the Windows font mapper, but not here) wxFont font(style.GetFont()); - LOGFONT lf; - wxFillLogFont(&lf, &font); + LOGFONT lf = font.GetNativeFontInfo()->lf; cf.yHeight = 20*font.GetPointSize(); // 1 pt = 20 twips cf.bCharSet = lf.lfCharSet; cf.bPitchAndFamily = lf.lfPitchAndFamily; @@ -3157,7 +3157,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) else lf.lfWeight = FW_NORMAL; - wxFont font = wxCreateFontFromLogFont(& lf); + wxFont font(lf); if (font.IsOk()) { style.SetFont(font);