wxFont::GetNativeFontInfoDesc() and GetNativeFontInfoUserDesc() were
overridden just to ensure that the font is realized but it makes sense to do
it in wxFontRefData::GetNativeFontInfo() itself as detecting the face name
won't work if the font is not realized anyhow. And then we don't need these
functions at all as the only thing they do is checking that the font is valid
when they are called but this can be done in the base class itself as this
should happen in all ports (document that this is the case).
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62717
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
- // wxFontBase overridden functions
- virtual wxString GetNativeFontInfoDesc() const;
- virtual wxString GetNativeFontInfoUserDesc() const;
-
// implement base class pure virtuals
virtual int GetPointSize() const;
virtual wxSize GetPixelSize() const;
// implement base class pure virtuals
virtual int GetPointSize() const;
virtual wxSize GetPixelSize() const;
/**
Returns the platform-dependent string completely describing this font.
/**
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.
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.
/**
Returns a user-friendly string for this font object.
/**
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.
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.
wxString wxFontBase::GetNativeFontInfoDesc() const
{
wxString wxFontBase::GetNativeFontInfoDesc() const
{
+ wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );
+
wxString fontDesc;
const wxNativeFontInfo *fontInfo = GetNativeFontInfo();
if ( fontInfo )
wxString fontDesc;
const wxNativeFontInfo *fontInfo = GetNativeFontInfo();
if ( fontInfo )
wxString wxFontBase::GetNativeFontInfoUserDesc() const
{
wxString wxFontBase::GetNativeFontInfoUserDesc() const
{
+ wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );
+
wxString fontDesc;
const wxNativeFontInfo *fontInfo = GetNativeFontInfo();
if ( fontInfo )
wxString fontDesc;
const wxNativeFontInfo *fontInfo = GetNativeFontInfo();
if ( fontInfo )
WXHFONT GetHFONT() const
{
WXHFONT GetHFONT() const
{
- if ( !m_hFont )
- const_cast<wxFontRefData *>(this)->Alloc();
return (WXHFONT)m_hFont;
}
return (WXHFONT)m_hFont;
}
const wxNativeFontInfo& GetNativeFontInfo() const
{
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
// 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
void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
+ void AllocIfNeeded() const
+ {
+ if ( !m_hFont )
+ const_cast<wxFontRefData *>(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)
// 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)
return IsOk() ? &(M_FONTDATA->GetNativeFontInfo()) : NULL;
}
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<wxFont*>(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<wxFont*>(this)->RealizeResource();
- return wxFontBase::GetNativeFontInfoUserDesc();
-}
-
bool wxFont::IsFixedWidth() const
{
wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
bool wxFont::IsFixedWidth() const
{
wxCHECK_MSG( IsOk(), false, wxT("invalid font") );