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.
This commit is contained in:
Vadim Zeitlin
2018-12-30 16:25:41 +01:00
parent 90186f7740
commit 72a225924d
5 changed files with 10 additions and 42 deletions

View File

@@ -961,8 +961,6 @@ extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp
WXDLLIMPEXP_CORE void wxGetCursorPosMSW(POINT* pt); WXDLLIMPEXP_CORE void wxGetCursorPosMSW(POINT* pt);
WXDLLIMPEXP_CORE void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font); 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); WXDLLIMPEXP_CORE wxFontEncoding wxGetFontEncFromCharSet(int charset);
inline void wxSetWindowFont(HWND hwnd, const wxFont& font) inline void wxSetWindowFont(HWND hwnd, const wxFont& font)

View File

@@ -36,6 +36,8 @@
#include "wx/math.h" #include "wx/math.h"
#endif #endif
#include "wx/fontutil.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -118,7 +120,7 @@ int wxFontDialog::ShowModal()
if ( m_fontData.m_initialFont.IsOk() ) if ( m_fontData.m_initialFont.IsOk() )
{ {
flags |= CF_INITTOLOGFONTSTRUCT; flags |= CF_INITTOLOGFONTSTRUCT;
wxFillLogFont(&logFont, &m_fontData.m_initialFont); logFont = m_fontData.m_initialFont.GetNativeFontInfo()->lf;
} }
if ( m_fontData.m_fontColour.IsOk() ) if ( m_fontData.m_fontColour.IsOk() )
@@ -150,7 +152,7 @@ int wxFontDialog::ShowModal()
if ( ChooseFont(&chooseFontStruct) != 0 ) if ( ChooseFont(&chooseFontStruct) != 0 )
{ {
wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors); 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().facename = logFont.lfFaceName;
m_fontData.EncodingInfo().charset = logFont.lfCharSet; m_fontData.EncodingInfo().charset = logFont.lfCharSet;

View File

@@ -264,35 +264,3 @@ wxFontEncoding wxGetFontEncFromCharSet(int cs)
return fontEncoding; 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);
}

View File

@@ -345,7 +345,7 @@ extern wxFont wxGetCCDefaultFont()
0 0
) ) ) )
{ {
return wxFont(wxCreateFontFromLogFont(&lf)); return wxFont(lf);
} }
else else
{ {

View File

@@ -40,6 +40,7 @@
#include "wx/wxcrtvararg.h" #include "wx/wxcrtvararg.h"
#endif #endif
#include "wx/fontutil.h"
#include "wx/scopedptr.h" #include "wx/scopedptr.h"
#include "wx/stack.h" #include "wx/stack.h"
#include "wx/sysopt.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; CFM_ITALIC | CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT;
// fill in data from LOGFONT but recalculate lfHeight because we need // fill in data from LOGFONT but recalculate lfHeight because we need
// the real height in twips and not the negative number which // the real height in twips and not the negative number used inside
// wxFillLogFont() returns (this is correct in general and works with // LOGFONT returns (this is correct in general and works with
// the Windows font mapper, but not here) // the Windows font mapper, but not here)
wxFont font(style.GetFont()); wxFont font(style.GetFont());
LOGFONT lf; LOGFONT lf = font.GetNativeFontInfo()->lf;
wxFillLogFont(&lf, &font);
cf.yHeight = 20*font.GetPointSize(); // 1 pt = 20 twips cf.yHeight = 20*font.GetPointSize(); // 1 pt = 20 twips
cf.bCharSet = lf.lfCharSet; cf.bCharSet = lf.lfCharSet;
cf.bPitchAndFamily = lf.lfPitchAndFamily; cf.bPitchAndFamily = lf.lfPitchAndFamily;
@@ -3157,7 +3157,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
else else
lf.lfWeight = FW_NORMAL; lf.lfWeight = FW_NORMAL;
wxFont font = wxCreateFontFromLogFont(& lf); wxFont font(lf);
if (font.IsOk()) if (font.IsOk())
{ {
style.SetFont(font); style.SetFont(font);