diff --git a/include/wx/msw/font.h b/include/wx/msw/font.h index a121282f89..05edfdf958 100644 --- a/include/wx/msw/font.h +++ b/include/wx/msw/font.h @@ -110,10 +110,6 @@ public: virtual ~wxFont(); - // wxFontBase overridden functions - virtual wxString GetNativeFontInfoDesc() const; - virtual wxString GetNativeFontInfoUserDesc() const; - // implement base class pure virtuals virtual int GetPointSize() const; virtual wxSize GetPixelSize() const; diff --git a/interface/wx/font.h b/interface/wx/font.h index f702fdb665..a4283059b0 100644 --- a/interface/wx/font.h +++ b/interface/wx/font.h @@ -442,7 +442,9 @@ public: /** Returns the platform-dependent string completely describing this font. - Returned string is always non-empty. + + Returned string is always non-empty unless the font is invalid (in + which case an assert is triggered). Note that the returned string is not meant to be shown or edited by the user: a typical use of this function is for serializing in string-form a wxFont object. @@ -453,7 +455,9 @@ public: /** Returns a user-friendly string for this font object. - Returned string is always non-empty. + + Returned string is always non-empty unless the font is invalid (in + which case an assert is triggered). The string does not encode all wxFont infos under all platforms; e.g. under wxMSW the font family is not present in the returned string. diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 0725335a58..a59e671c5b 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -284,6 +284,8 @@ void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info) wxString wxFontBase::GetNativeFontInfoDesc() const { + wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); + wxString fontDesc; const wxNativeFontInfo *fontInfo = GetNativeFontInfo(); if ( fontInfo ) @@ -301,6 +303,8 @@ wxString wxFontBase::GetNativeFontInfoDesc() const wxString wxFontBase::GetNativeFontInfoUserDesc() const { + wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); + wxString fontDesc; const wxNativeFontInfo *fontInfo = GetNativeFontInfo(); if ( fontInfo ) diff --git a/src/msw/font.cpp b/src/msw/font.cpp index f22d5aefdf..832ce661a8 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -213,8 +213,7 @@ public: WXHFONT GetHFONT() const { - if ( !m_hFont ) - const_cast(this)->Alloc(); + AllocIfNeeded(); return (WXHFONT)m_hFont; } @@ -290,6 +289,10 @@ public: const wxNativeFontInfo& GetNativeFontInfo() const { + // we need to create the font now to get the corresponding LOGFONT if + // it hadn't been done yet + AllocIfNeeded(); + // ensure that we have a valid face name in our font information: // GetFaceName() will try to retrieve it from our HFONT and save it if // it was successful @@ -319,6 +322,12 @@ protected: void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0); + void AllocIfNeeded() const + { + if ( !m_hFont ) + const_cast(this)->Alloc(); + } + // retrieve the face name really being used by the font: this is used to // get the face name selected by the system when we don't specify it (but // use just the family for example) @@ -1055,24 +1064,6 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const return IsOk() ? &(M_FONTDATA->GetNativeFontInfo()) : NULL; } -wxString wxFont::GetNativeFontInfoDesc() const -{ - wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); - - // be sure we have an HFONT associated... - const_cast(this)->RealizeResource(); - return wxFontBase::GetNativeFontInfoDesc(); -} - -wxString wxFont::GetNativeFontInfoUserDesc() const -{ - wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") ); - - // be sure we have an HFONT associated... - const_cast(this)->RealizeResource(); - return wxFontBase::GetNativeFontInfoUserDesc(); -} - bool wxFont::IsFixedWidth() const { wxCHECK_MSG( IsOk(), false, wxT("invalid font") );