From 3bf5a59b5e058bebffcf9d87f03550b4ecf93e73 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Sep 2003 01:23:37 +0000 Subject: [PATCH] pointer returned by GetNativeFontInfo() is now const and must not be deleted (replaces patch 810192) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/font.h | 1 + include/wx/font.h | 2 +- include/wx/fontutil.h | 22 ++++++++ include/wx/gtk/font.h | 2 +- include/wx/gtk1/font.h | 2 +- include/wx/mac/font.h | 98 +---------------------------------- include/wx/mgl/font.h | 1 + include/wx/motif/font.h | 2 +- include/wx/msw/font.h | 2 +- include/wx/os2/font.h | 2 +- include/wx/x11/font.h | 2 +- src/cocoa/font.cpp | 5 ++ src/common/fontcmn.cpp | 27 ++-------- src/gtk/font.cpp | 4 +- src/gtk1/font.cpp | 4 +- src/mac/carbon/font.cpp | 111 +++++++++++++++++++++++++++++++++++++++- src/mac/font.cpp | 111 +++++++++++++++++++++++++++++++++++++++- src/mgl/font.cpp | 10 ++++ src/motif/font.cpp | 4 +- src/msw/font.cpp | 8 ++- src/msw/fontutil.cpp | 30 +++-------- src/os2/font.cpp | 7 ++- src/x11/font.cpp | 4 +- 23 files changed, 291 insertions(+), 170 deletions(-) diff --git a/include/wx/cocoa/font.h b/include/wx/cocoa/font.h index 65b868c80a..863837c428 100644 --- a/include/wx/cocoa/font.h +++ b/include/wx/cocoa/font.h @@ -152,6 +152,7 @@ public: virtual bool GetUnderlined() const; virtual wxString GetFaceName() const; virtual wxFontEncoding GetEncoding() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual void SetPointSize(int pointSize); virtual void SetFamily(int family); diff --git a/include/wx/font.h b/include/wx/font.h index 83a00873cc..a8781d4db4 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -156,7 +156,7 @@ public: virtual bool GetUnderlined() const = 0; virtual wxString GetFaceName() const = 0; virtual wxFontEncoding GetEncoding() const = 0; - virtual wxNativeFontInfo *GetNativeFontInfo() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0; virtual bool IsFixedWidth() const; diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index da045f1c53..5ff0cded08 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -139,6 +139,28 @@ public: // reset to the default state void Init(); + // init with the parameters of the given font + void InitFromFont(const wxFont& font) + { + // translate all font parameters + SetStyle((wxFontStyle)font.GetStyle()); + SetWeight((wxFontWeight)font.GetWeight()); + SetUnderlined(font.GetUnderlined()); + SetPointSize(font.GetPointSize()); + + // set the family/facename + SetFamily((wxFontFamily)font.GetFamily()); + const wxString& facename = font.GetFaceName(); + if ( !facename.empty() ) + { + SetFaceName(facename); + } + + // deal with encoding now (it may override the font family and facename + // so do it after setting them) + SetEncoding(font.GetEncoding()); + } + // accessors and modifiers for the font elements int GetPointSize() const; wxFontStyle GetStyle() const; diff --git a/include/wx/gtk/font.h b/include/wx/gtk/font.h index 2465dc3554..9d66ddc909 100644 --- a/include/wx/gtk/font.h +++ b/include/wx/gtk/font.h @@ -84,7 +84,7 @@ public: virtual wxString GetFaceName() const; virtual bool GetUnderlined() const; virtual wxFontEncoding GetEncoding() const; - virtual wxNativeFontInfo *GetNativeFontInfo() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual bool IsFixedWidth() const; virtual void SetPointSize( int pointSize ); diff --git a/include/wx/gtk1/font.h b/include/wx/gtk1/font.h index 2465dc3554..9d66ddc909 100644 --- a/include/wx/gtk1/font.h +++ b/include/wx/gtk1/font.h @@ -84,7 +84,7 @@ public: virtual wxString GetFaceName() const; virtual bool GetUnderlined() const; virtual wxFontEncoding GetEncoding() const; - virtual wxNativeFontInfo *GetNativeFontInfo() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual bool IsFixedWidth() const; virtual void SetPointSize( int pointSize ); diff --git a/include/wx/mac/font.h b/include/wx/mac/font.h index d57d048e9b..08551a88bd 100644 --- a/include/wx/mac/font.h +++ b/include/wx/mac/font.h @@ -16,103 +16,6 @@ #pragma interface "font.h" #endif -class WXDLLEXPORT wxFontRefData: public wxGDIRefData -{ - friend class WXDLLEXPORT wxFont; -public: - wxFontRefData() - : m_fontId(0) - , m_pointSize(10) - , m_family(wxDEFAULT) - , m_style(wxNORMAL) - , m_weight(wxNORMAL) - , m_underlined(FALSE) - , m_faceName(wxT("Geneva")) - , m_encoding(wxFONTENCODING_DEFAULT) - , m_macFontNum(0) - , m_macFontSize(0) - , m_macFontStyle(0) - , m_macATSUFontID() - { - Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, - wxT("Geneva"), wxFONTENCODING_DEFAULT); - } - - wxFontRefData(const wxFontRefData& data) - : wxGDIRefData() - , m_fontId(data.m_fontId) - , m_pointSize(data.m_pointSize) - , m_family(data.m_family) - , m_style(data.m_style) - , m_weight(data.m_weight) - , m_underlined(data.m_underlined) - , m_faceName(data.m_faceName) - , m_encoding(data.m_encoding) - , m_macFontNum(data.m_macFontNum) - , m_macFontSize(data.m_macFontSize) - , m_macFontStyle(data.m_macFontStyle) - , m_macATSUFontID(data.m_macATSUFontID) - { - Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, - data.m_underlined, data.m_faceName, data.m_encoding); - } - - wxFontRefData(int size, - int family, - int style, - int weight, - bool underlined, - const wxString& faceName, - wxFontEncoding encoding) - : m_fontId(0) - , m_pointSize(size) - , m_family(family) - , m_style(style) - , m_weight(weight) - , m_underlined(underlined) - , m_faceName(faceName) - , m_encoding(encoding) - , m_macFontNum(0) - , m_macFontSize(0) - , m_macFontStyle(0) - , m_macATSUFontID(0) - { - Init(size, family, style, weight, underlined, faceName, encoding); - } - - virtual ~wxFontRefData(); - void SetNoAntiAliasing( bool no = TRUE ) { m_noAA = no; } - bool GetNoAntiAliasing() { return m_noAA; } - -protected: - // common part of all ctors - void Init(int size, - int family, - int style, - int weight, - bool underlined, - const wxString& faceName, - wxFontEncoding encoding); - - // font characterstics - int m_fontId; - int m_pointSize; - int m_family; - int m_style; - int m_weight; - bool m_underlined; - wxString m_faceName; - wxFontEncoding m_encoding; - bool m_noAA; // No anti-aliasing - -public: - short m_macFontNum; - short m_macFontSize; - unsigned char m_macFontStyle; - wxUint32 m_macATSUFontID; -public: - void MacFindFont() ; -}; // ---------------------------------------------------------------------------- // wxFont // ---------------------------------------------------------------------------- @@ -174,6 +77,7 @@ public: virtual bool GetUnderlined() const; virtual wxString GetFaceName() const; virtual wxFontEncoding GetEncoding() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual void SetPointSize(int pointSize); virtual void SetFamily(int family); diff --git a/include/wx/mgl/font.h b/include/wx/mgl/font.h index 5381f3184d..6a105bf6fc 100644 --- a/include/wx/mgl/font.h +++ b/include/wx/mgl/font.h @@ -81,6 +81,7 @@ public: virtual bool GetUnderlined() const; virtual wxFontEncoding GetEncoding() const; virtual bool IsFixedWidth() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual void SetPointSize(int pointSize); virtual void SetFamily(int family); diff --git a/include/wx/motif/font.h b/include/wx/motif/font.h index 62be50f08e..80d1a4f841 100644 --- a/include/wx/motif/font.h +++ b/include/wx/motif/font.h @@ -67,7 +67,7 @@ public: virtual bool GetUnderlined() const; virtual wxString GetFaceName() const; virtual wxFontEncoding GetEncoding() const; - virtual wxNativeFontInfo *GetNativeFontInfo() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual void SetPointSize(int pointSize); virtual void SetFamily(int family); diff --git a/include/wx/msw/font.h b/include/wx/msw/font.h index 69acbfcc63..13674e03c5 100644 --- a/include/wx/msw/font.h +++ b/include/wx/msw/font.h @@ -72,7 +72,7 @@ public: virtual bool GetUnderlined() const; virtual wxString GetFaceName() const; virtual wxFontEncoding GetEncoding() const; - virtual wxNativeFontInfo* GetNativeFontInfo() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual void SetPointSize(int pointSize); virtual void SetFamily(int family); diff --git a/include/wx/os2/font.h b/include/wx/os2/font.h index 53dcf28490..896e5a261c 100644 --- a/include/wx/os2/font.h +++ b/include/wx/os2/font.h @@ -93,7 +93,7 @@ public: virtual bool GetUnderlined(void) const; virtual wxString GetFaceName(void) const; virtual wxFontEncoding GetEncoding(void) const; - virtual wxNativeFontInfo* GetNativeFontInfo() const; + virtual const wxNativeFontInfo* GetNativeFontInfo() const; virtual void SetPointSize(int nPointSize); virtual void SetFamily(int nFamily); diff --git a/include/wx/x11/font.h b/include/wx/x11/font.h index 4887c66551..a4739023f6 100644 --- a/include/wx/x11/font.h +++ b/include/wx/x11/font.h @@ -71,7 +71,7 @@ public: virtual bool GetUnderlined() const; virtual wxString GetFaceName() const; virtual wxFontEncoding GetEncoding() const; - virtual wxNativeFontInfo *GetNativeFontInfo() const; + virtual const wxNativeFontInfo *GetNativeFontInfo() const; virtual bool IsFixedWidth() const; diff --git a/src/cocoa/font.cpp b/src/cocoa/font.cpp index c907342aa5..485e447653 100644 --- a/src/cocoa/font.cpp +++ b/src/cocoa/font.cpp @@ -80,6 +80,11 @@ int wxFont::GetWeight() const return 0; } +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const +{ + return NULL; +} + void wxGetNativeFontEncoding(wxFontEncoding, wxNativeEncodingInfo*); bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index f1b77746b2..7c3412b48d 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -131,25 +131,6 @@ bool wxFontBase::IsFixedWidth() const return GetFamily() == wxFONTFAMILY_TELETYPE; } -wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const -{ -#ifdef wxNO_NATIVE_FONTINFO - wxNativeFontInfo *fontInfo = new wxNativeFontInfo(); - - fontInfo->SetPointSize(GetPointSize()); - fontInfo->SetFamily((wxFontFamily)GetFamily()); - fontInfo->SetStyle((wxFontStyle)GetStyle()); - fontInfo->SetWeight((wxFontWeight)GetWeight()); - fontInfo->SetUnderlined(GetUnderlined()); - fontInfo->SetFaceName(GetFaceName()); - fontInfo->SetEncoding(GetEncoding()); - - return fontInfo; -#else - return (wxNativeFontInfo *)NULL; -#endif -} - void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info) { #ifdef wxNO_NATIVE_FONTINFO @@ -168,11 +149,10 @@ void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info) wxString wxFontBase::GetNativeFontInfoDesc() const { wxString fontDesc; - wxNativeFontInfo *fontInfo = GetNativeFontInfo(); + const wxNativeFontInfo *fontInfo = GetNativeFontInfo(); if ( fontInfo ) { fontDesc = fontInfo->ToString(); - delete fontInfo; } return fontDesc; @@ -181,11 +161,10 @@ wxString wxFontBase::GetNativeFontInfoDesc() const wxString wxFontBase::GetNativeFontInfoUserDesc() const { wxString fontDesc; - wxNativeFontInfo *fontInfo = GetNativeFontInfo(); + const wxNativeFontInfo *fontInfo = GetNativeFontInfo(); if ( fontInfo ) { fontDesc = fontInfo->ToUserString(); - delete fontInfo; } return fontDesc; @@ -362,7 +341,7 @@ wxString wxNativeFontInfo::ToString() const void wxNativeFontInfo::Init() { - pointSize = wxNORMAL_FONT->GetPointSize(); + pointSize = 0; family = wxFONTFAMILY_DEFAULT; style = wxFONTSTYLE_NORMAL; weight = wxFONTWEIGHT_NORMAL; diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index f62f55b840..eef97f198b 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -790,7 +790,7 @@ bool wxFont::GetNoAntiAliasing() return M_FONTDATA->m_noAA; } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); @@ -799,7 +799,7 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const GetInternalFont(); #endif - return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); + return &(M_FONTDATA->m_nativeFontInfo); } bool wxFont::IsFixedWidth() const diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index f62f55b840..eef97f198b 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -790,7 +790,7 @@ bool wxFont::GetNoAntiAliasing() return M_FONTDATA->m_noAA; } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); @@ -799,7 +799,7 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const GetInternalFont(); #endif - return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); + return &(M_FONTDATA->m_nativeFontInfo); } bool wxFont::IsFixedWidth() const diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index d94805d819..bb1c2b4939 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -6,7 +6,7 @@ // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -29,6 +29,106 @@ IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) #endif +class WXDLLEXPORT wxFontRefData: public wxGDIRefData +{ + friend class WXDLLEXPORT wxFont; +public: + wxFontRefData() + : m_fontId(0) + , m_pointSize(10) + , m_family(wxDEFAULT) + , m_style(wxNORMAL) + , m_weight(wxNORMAL) + , m_underlined(FALSE) + , m_faceName(wxT("Geneva")) + , m_encoding(wxFONTENCODING_DEFAULT) + , m_macFontNum(0) + , m_macFontSize(0) + , m_macFontStyle(0) + , m_macATSUFontID() + { + Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, + wxT("Geneva"), wxFONTENCODING_DEFAULT); + } + + wxFontRefData(const wxFontRefData& data) + : wxGDIRefData() + , m_fontId(data.m_fontId) + , m_pointSize(data.m_pointSize) + , m_family(data.m_family) + , m_style(data.m_style) + , m_weight(data.m_weight) + , m_underlined(data.m_underlined) + , m_faceName(data.m_faceName) + , m_encoding(data.m_encoding) + , m_macFontNum(data.m_macFontNum) + , m_macFontSize(data.m_macFontSize) + , m_macFontStyle(data.m_macFontStyle) + , m_macATSUFontID(data.m_macATSUFontID) + { + Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, + data.m_underlined, data.m_faceName, data.m_encoding); + } + + wxFontRefData(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) + : m_fontId(0) + , m_pointSize(size) + , m_family(family) + , m_style(style) + , m_weight(weight) + , m_underlined(underlined) + , m_faceName(faceName) + , m_encoding(encoding) + , m_macFontNum(0) + , m_macFontSize(0) + , m_macFontStyle(0) + , m_macATSUFontID(0) + { + Init(size, family, style, weight, underlined, faceName, encoding); + } + + virtual ~wxFontRefData(); + void SetNoAntiAliasing( bool no = TRUE ) { m_noAA = no; } + bool GetNoAntiAliasing() { return m_noAA; } + +protected: + // common part of all ctors + void Init(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding); + + // font characterstics + int m_fontId; + int m_pointSize; + int m_family; + int m_style; + int m_weight; + bool m_underlined; + wxString m_faceName; + wxFontEncoding m_encoding; + bool m_noAA; // No anti-aliasing + +public: + short m_macFontNum; + short m_macFontSize; + unsigned char m_macFontStyle; + wxUint32 m_macATSUFontID; + + wxNativeFontInfo m_info; + +public: + void MacFindFont() ; +}; // ============================================================================ // implementation // ============================================================================ @@ -313,3 +413,12 @@ bool wxFont::GetNoAntiAliasing() return M_FONTDATA->m_noAA; } +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); + + M_FONTDATA->m_info.InitFromFont(*this); + + return &(M_FONTDATA->m_info); +} + diff --git a/src/mac/font.cpp b/src/mac/font.cpp index d94805d819..bb1c2b4939 100644 --- a/src/mac/font.cpp +++ b/src/mac/font.cpp @@ -6,7 +6,7 @@ // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -29,6 +29,106 @@ IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) #endif +class WXDLLEXPORT wxFontRefData: public wxGDIRefData +{ + friend class WXDLLEXPORT wxFont; +public: + wxFontRefData() + : m_fontId(0) + , m_pointSize(10) + , m_family(wxDEFAULT) + , m_style(wxNORMAL) + , m_weight(wxNORMAL) + , m_underlined(FALSE) + , m_faceName(wxT("Geneva")) + , m_encoding(wxFONTENCODING_DEFAULT) + , m_macFontNum(0) + , m_macFontSize(0) + , m_macFontStyle(0) + , m_macATSUFontID() + { + Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE, + wxT("Geneva"), wxFONTENCODING_DEFAULT); + } + + wxFontRefData(const wxFontRefData& data) + : wxGDIRefData() + , m_fontId(data.m_fontId) + , m_pointSize(data.m_pointSize) + , m_family(data.m_family) + , m_style(data.m_style) + , m_weight(data.m_weight) + , m_underlined(data.m_underlined) + , m_faceName(data.m_faceName) + , m_encoding(data.m_encoding) + , m_macFontNum(data.m_macFontNum) + , m_macFontSize(data.m_macFontSize) + , m_macFontStyle(data.m_macFontStyle) + , m_macATSUFontID(data.m_macATSUFontID) + { + Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, + data.m_underlined, data.m_faceName, data.m_encoding); + } + + wxFontRefData(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) + : m_fontId(0) + , m_pointSize(size) + , m_family(family) + , m_style(style) + , m_weight(weight) + , m_underlined(underlined) + , m_faceName(faceName) + , m_encoding(encoding) + , m_macFontNum(0) + , m_macFontSize(0) + , m_macFontStyle(0) + , m_macATSUFontID(0) + { + Init(size, family, style, weight, underlined, faceName, encoding); + } + + virtual ~wxFontRefData(); + void SetNoAntiAliasing( bool no = TRUE ) { m_noAA = no; } + bool GetNoAntiAliasing() { return m_noAA; } + +protected: + // common part of all ctors + void Init(int size, + int family, + int style, + int weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding); + + // font characterstics + int m_fontId; + int m_pointSize; + int m_family; + int m_style; + int m_weight; + bool m_underlined; + wxString m_faceName; + wxFontEncoding m_encoding; + bool m_noAA; // No anti-aliasing + +public: + short m_macFontNum; + short m_macFontSize; + unsigned char m_macFontStyle; + wxUint32 m_macATSUFontID; + + wxNativeFontInfo m_info; + +public: + void MacFindFont() ; +}; // ============================================================================ // implementation // ============================================================================ @@ -313,3 +413,12 @@ bool wxFont::GetNoAntiAliasing() return M_FONTDATA->m_noAA; } +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); + + M_FONTDATA->m_info.InitFromFont(*this); + + return &(M_FONTDATA->m_info); +} + diff --git a/src/mgl/font.cpp b/src/mgl/font.cpp index d044a439ce..06d972feee 100644 --- a/src/mgl/font.cpp +++ b/src/mgl/font.cpp @@ -74,6 +74,8 @@ private: wxMGLFontLibrary *m_library; bool m_valid; + wxNativeFontInfo m_info; + friend class wxFont; }; @@ -264,6 +266,14 @@ bool wxFont::IsFixedWidth() const return (bool)(M_FONTDATA->m_library->GetFamily()->GetInfo()->isFixed); } +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); + + M_FONTDATA->m_info.InitFromFont(*this); + + return &(M_FONTDATA->m_info); +} // ---------------------------------------------------------------------------- // change font attributes diff --git a/src/motif/font.cpp b/src/motif/font.cpp index c4c0f9fcd6..06637b118d 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -485,14 +485,14 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->m_encoding; } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); if(M_FONTDATA->m_nativeFontInfo.GetXFontName().IsEmpty()) GetInternalFont(); - return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); + return &(M_FONTDATA->m_nativeFontInfo); } // ---------------------------------------------------------------------------- diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 296142c585..ae8752a780 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -948,12 +948,10 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->GetEncoding(); } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { - if ( M_FONTDATA->HasNativeFontInfo() ) - return new wxNativeFontInfo(M_FONTDATA->GetNativeFontInfo()); - - return 0; + return M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo()) + : NULL; } bool wxFont::IsFixedWidth() const diff --git a/src/msw/fontutil.cpp b/src/msw/fontutil.cpp index 8f9844def7..a74885be8a 100644 --- a/src/msw/fontutil.cpp +++ b/src/msw/fontutil.cpp @@ -234,36 +234,20 @@ wxFontEncoding wxGetFontEncFromCharSet(int cs) void wxFillLogFont(LOGFONT *logFont, const wxFont *font) { + wxNativeFontInfo fi; + // maybe we already have LOGFONT for this font? - wxNativeFontInfo *fontinfo = font->GetNativeFontInfo(); - if ( !fontinfo ) + const wxNativeFontInfo *pFI = font->GetNativeFontInfo(); + if ( !pFI ) { // use wxNativeFontInfo methods to build a LOGFONT for this font - fontinfo = new wxNativeFontInfo; - - // translate all font parameters - fontinfo->SetStyle((wxFontStyle)font->GetStyle()); - fontinfo->SetWeight((wxFontWeight)font->GetWeight()); - fontinfo->SetUnderlined(font->GetUnderlined()); - fontinfo->SetPointSize(font->GetPointSize()); - - // set the family/facename - fontinfo->SetFamily((wxFontFamily)font->GetFamily()); - wxString facename = font->GetFaceName(); - if ( !facename.empty() ) - { - fontinfo->SetFaceName(facename); - } + fi.InitFromFont(*font); - // deal with encoding now (it may override the font family and facename - // so do it after setting them) - fontinfo->SetEncoding(font->GetEncoding()); + pFI = &fi; } // transfer all the data to LOGFONT - *logFont = fontinfo->lf; - - delete fontinfo; + *logFont = pFI->lf; } wxFont wxCreateFontFromLogFont(const LOGFONT *logFont) diff --git a/src/os2/font.cpp b/src/os2/font.cpp index 52e3ec4d2e..5588a0a013 100644 --- a/src/os2/font.cpp +++ b/src/os2/font.cpp @@ -1140,11 +1140,10 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->GetEncoding(); } // end of wxFont::GetEncoding -wxNativeFontInfo* wxFont::GetNativeFontInfo() const +const wxNativeFontInfo* wxFont::GetNativeFontInfo() const { - if (M_FONTDATA->HasNativeFontInfo()) - return new wxNativeFontInfo(M_FONTDATA->GetNativeFontInfo()); - return 0; + return M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo()) + : NULL; } // end of wxFont::GetNativeFontInfo // diff --git a/src/x11/font.cpp b/src/x11/font.cpp index 773246bbe6..bc698ba148 100644 --- a/src/x11/font.cpp +++ b/src/x11/font.cpp @@ -752,7 +752,7 @@ bool wxFont::GetNoAntiAliasing() return M_FONTDATA->m_noAA; } -wxNativeFontInfo *wxFont::GetNativeFontInfo() const +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); @@ -762,7 +762,7 @@ wxNativeFontInfo *wxFont::GetNativeFontInfo() const GetInternalFont(); #endif - return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo); + return &(M_FONTDATA->m_nativeFontInfo); } bool wxFont::IsFixedWidth() const -- 2.45.2