Return wxFONTFAMILY_DEFAULT, not UNKNOWN, from wxFont::GetFamily().
Although returning wxFONTFAMILY_UNKNOWN when the font family is not recognized makes more sense, it breaks a lot of existing code including all the font-related code generated by DialogBlocks, so prefer to return wxFONTFAMILY_DEFAULT instead -- which can't be confused for a valid font family neither but can be passed to wxFont ctor or SetFamily() without problems. To ensure that this behaviour is correctly implemented by all ports, rename the existing wxFont::GetFamily() to DoGetFamily() and call the new method from wxFontBase::GetFamily() which adjusts the return value if needed. Closes #12330. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65670 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4a21ea9d9e
commit
59b7da02ff
@ -103,7 +103,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined() const;
|
||||
@ -149,6 +148,8 @@ protected:
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFont)
|
||||
};
|
||||
|
@ -71,7 +71,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual wxString GetFaceName() const;
|
||||
@ -97,6 +96,8 @@ protected:
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFont)
|
||||
};
|
||||
|
@ -214,7 +214,7 @@ public:
|
||||
virtual int GetPointSize() const = 0;
|
||||
virtual wxSize GetPixelSize() const;
|
||||
virtual bool IsUsingSizeInPixels() const;
|
||||
virtual wxFontFamily GetFamily() const = 0;
|
||||
wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const = 0;
|
||||
virtual wxFontWeight GetWeight() const = 0;
|
||||
virtual bool GetUnderlined() const = 0;
|
||||
@ -264,6 +264,10 @@ protected:
|
||||
// the function called by both overloads of SetNativeFontInfo()
|
||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
|
||||
|
||||
// The function called by public GetFamily(): it can return
|
||||
// wxFONTFAMILY_UNKNOWN unlike the public method (see comment there).
|
||||
virtual wxFontFamily DoGetFamily() const = 0;
|
||||
|
||||
private:
|
||||
// the currently default encoding: by default, it's the default system
|
||||
// encoding, but may be changed by the application using
|
||||
|
@ -78,7 +78,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual wxString GetFaceName() const;
|
||||
@ -111,6 +110,8 @@ protected:
|
||||
virtual wxGDIRefData* CreateGDIRefData() const;
|
||||
virtual wxGDIRefData* CloneGDIRefData(const wxGDIRefData* data) const;
|
||||
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFont)
|
||||
};
|
||||
|
@ -92,7 +92,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual wxString GetFaceName() const;
|
||||
@ -121,6 +120,7 @@ protected:
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
||||
virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFont)
|
||||
|
@ -87,7 +87,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual wxString GetFaceName() const;
|
||||
@ -113,6 +112,8 @@ protected:
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFont)
|
||||
};
|
||||
|
@ -83,7 +83,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined() const;
|
||||
@ -140,6 +139,7 @@ protected:
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
||||
virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
void Unshare();
|
||||
|
||||
|
@ -114,7 +114,6 @@ public:
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxSize GetPixelSize() const;
|
||||
virtual bool IsUsingSizeInPixels() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined() const;
|
||||
@ -159,6 +158,7 @@ protected:
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
|
||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
// implement wxObject virtuals which are used by AllocExclusive()
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
|
@ -93,7 +93,6 @@ public:
|
||||
// Implement base class pure virtuals
|
||||
//
|
||||
virtual int GetPointSize(void) const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined(void) const;
|
||||
@ -131,6 +130,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& rInfo);
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
// implement wxObject virtuals which are used by AllocExclusive()
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
|
@ -101,7 +101,6 @@ public:
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxSize GetPixelSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined() const;
|
||||
@ -168,6 +167,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
@ -99,7 +99,6 @@ public:
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxSize GetPixelSize() const;
|
||||
virtual bool IsUsingSizeInPixels() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined() const;
|
||||
@ -141,6 +140,7 @@ protected:
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
|
||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
// implement wxObject virtuals which are used by AllocExclusive()
|
||||
virtual wxGDIRefData *CreateGDIRefData() const;
|
||||
|
@ -80,7 +80,6 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int GetPointSize() const;
|
||||
virtual wxFontFamily GetFamily() const;
|
||||
virtual wxFontStyle GetStyle() const;
|
||||
virtual wxFontWeight GetWeight() const;
|
||||
virtual bool GetUnderlined() const;
|
||||
@ -129,6 +128,7 @@ protected:
|
||||
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
|
||||
|
||||
virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );
|
||||
virtual wxFontFamily DoGetFamily() const;
|
||||
|
||||
void Unshare();
|
||||
|
||||
|
@ -36,11 +36,9 @@ enum wxFontFamily
|
||||
/// See also wxFont::IsFixedWidth() for an easy way to test for monospace property.
|
||||
wxFONTFAMILY_TELETYPE = wxTELETYPE,
|
||||
|
||||
/// Returned by wxFont::GetFamily() when the face name of the font cannot
|
||||
/// be classified into one of the previous wxFontFamily values.
|
||||
wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX,
|
||||
|
||||
wxFONTFAMILY_MAX
|
||||
/// Invalid font family value, returned by wxFont::GetFamily() when the
|
||||
/// font is invalid for example.
|
||||
wxFONTFAMILY_UNKNOWN
|
||||
};
|
||||
|
||||
/**
|
||||
@ -422,16 +420,17 @@ public:
|
||||
virtual wxString GetFaceName() const;
|
||||
|
||||
/**
|
||||
Gets the font family.
|
||||
Gets the font family if possible.
|
||||
|
||||
As described in ::wxFontFamily docs the returned value acts as a rough,
|
||||
basic classification of the main font properties (look, spacing).
|
||||
|
||||
If the current font face name is not recognized by wxFont or by the
|
||||
underlying system, @c wxFONTFAMILY_UNKNOWN is returned.
|
||||
underlying system, @c wxFONTFAMILY_DEFAULT is returned.
|
||||
|
||||
Note that currently this function is rather unreliable (@c wxFONTFAMILY_UNKNOWN
|
||||
is returned in too many cases) and not particularly useful.
|
||||
Font families mostly make sense only for font creation; see SetFamily().
|
||||
Note that currently this function is not very precise and so not
|
||||
particularly useful. Font families mostly make sense only for font
|
||||
creation, see SetFamily().
|
||||
|
||||
@see SetFamily()
|
||||
*/
|
||||
|
@ -370,9 +370,8 @@ wxFontStyle wxFont::GetStyle() const
|
||||
return M_FONTDATA->m_info.style;
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
|
||||
return M_FONTDATA->m_info.family;
|
||||
}
|
||||
|
||||
|
@ -367,6 +367,20 @@ bool wxFontBase::operator==(const wxFont& font) const
|
||||
);
|
||||
}
|
||||
|
||||
wxFontFamily wxFontBase::GetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxFONTFAMILY_UNKNOWN, wxS("invalid font") );
|
||||
|
||||
// Don't return wxFONTFAMILY_UNKNOWN from here because it prevents the code
|
||||
// like wxFont(size, wxNORMAL_FONT->GetFamily(), ...) from working (see
|
||||
// #12330). This is really just a hack but it allows to keep compatibility
|
||||
// and doesn't really have any bad drawbacks so do this until someone comes
|
||||
// up with a better idea.
|
||||
const wxFontFamily family = DoGetFamily();
|
||||
|
||||
return family == wxFONTFAMILY_UNKNOWN ? wxFONTFAMILY_DEFAULT : family;
|
||||
}
|
||||
|
||||
wxString wxFontBase::GetFamilyString() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), "wxFONTFAMILY_DEFAULT", "invalid font" );
|
||||
|
@ -98,10 +98,8 @@ wxString wxFont::GetFaceName() const
|
||||
return M_FONTDATA->GetFaceName();
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->GetFamily();
|
||||
}
|
||||
|
||||
|
@ -333,10 +333,8 @@ wxString wxFont::GetFaceName() const
|
||||
return M_FONTDATA->m_nativeFontInfo.GetFaceName();
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->m_nativeFontInfo.GetFamily();
|
||||
}
|
||||
|
||||
|
@ -534,10 +534,8 @@ wxString wxFont::GetFaceName() const
|
||||
return M_FONTDATA->m_faceName;
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->m_family;
|
||||
}
|
||||
|
||||
|
@ -95,10 +95,8 @@ wxString wxFont::GetFaceName() const
|
||||
return M_FONTDATA->GetFaceName();
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->GetFamily();
|
||||
}
|
||||
|
||||
|
@ -455,10 +455,8 @@ wxString wxFont::GetFaceName() const
|
||||
return M_FONTDATA->m_faceName ;
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->m_family;
|
||||
}
|
||||
|
||||
|
@ -1016,10 +1016,8 @@ bool wxFont::IsUsingSizeInPixels() const
|
||||
return M_FONTDATA->IsUsingSizeInPixels();
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( IsOk(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->GetFamily();
|
||||
}
|
||||
|
||||
|
@ -1082,12 +1082,10 @@ int wxFont::GetPointSize() const
|
||||
return M_FONTDATA->GetPointSize();
|
||||
} // end of wxFont::GetPointSize
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->GetFamily();
|
||||
} // end of wxFont::GetFamily
|
||||
} // end of wxFont::DoGetFamily
|
||||
|
||||
wxFontStyle wxFont::GetStyle() const
|
||||
{
|
||||
|
@ -732,10 +732,8 @@ wxSize wxFont::GetPixelSize() const
|
||||
#endif
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( M_FONTDATA != NULL , wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->GetFamily();
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ bool wxFont::IsUsingSizeInPixels() const
|
||||
return false;
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
return wxFONTFAMILY_ROMAN;
|
||||
}
|
||||
|
@ -725,10 +725,8 @@ wxString wxFont::GetFaceName() const
|
||||
return M_FONTDATA->m_faceName;
|
||||
}
|
||||
|
||||
wxFontFamily wxFont::GetFamily() const
|
||||
wxFontFamily wxFont::DoGetFamily() const
|
||||
{
|
||||
wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
|
||||
|
||||
return M_FONTDATA->m_family;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user