More steps towards using wxFontInfo in all ports
Replace AccountForCompatValues() with InfoFromLegacyParams() which directly constructs wxFontInfo from the old-style parameters, applying all the compatibility hacks internally. There are no real changes in this commit, just simplify the code further and make wxFontInfo more central.
This commit is contained in:
@@ -574,13 +574,25 @@ protected:
|
||||
return (flags & wxFONTFLAG_STRIKETHROUGH) != 0;
|
||||
}
|
||||
|
||||
// For compatibility reasons, we continue to accept wxDEFAULT as meaning
|
||||
// "default font size" and wxNORMAL and similar deprecated constants
|
||||
// instead of wxFONT{WEIGHT,STYLE}_NORMAL. This function modifies its
|
||||
// parameters to account for this if necessary.
|
||||
static void AccountForCompatValues(int& pointSize,
|
||||
wxFontStyle& style,
|
||||
wxFontWeight& weight);
|
||||
// Create wxFontInfo object from the parameters passed to the legacy wxFont
|
||||
// ctor/Create() overload. This function implements the compatibility hack
|
||||
// which interprets wxDEFAULT value of size as meaning -1 and also supports
|
||||
// specifying wxNORMAL, wxLIGHT and wxBOLD as weight values.
|
||||
static wxFontInfo InfoFromLegacyParams(int pointSize,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding);
|
||||
|
||||
static wxFontInfo InfoFromLegacyParams(const wxSize& pixelSize,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding);
|
||||
|
||||
private:
|
||||
// the currently default encoding: by default, it's the default system
|
||||
|
@@ -44,10 +44,13 @@ public:
|
||||
const wxString& face = wxEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
||||
{
|
||||
AccountForCompatValues(size, style, weight);
|
||||
|
||||
wxFontInfo info(size);
|
||||
return DoCreate(info, family, style, weight, underlined, face, encoding);
|
||||
return DoCreate(InfoFromLegacyParams(size,
|
||||
family,
|
||||
style,
|
||||
weight,
|
||||
underlined,
|
||||
face,
|
||||
encoding));
|
||||
}
|
||||
|
||||
wxFont(const wxSize& pixelSize,
|
||||
@@ -78,8 +81,13 @@ public:
|
||||
const wxString& face = wxEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
||||
{
|
||||
wxFontInfo info(pixelSize);
|
||||
return DoCreate(info, family, style, weight, underlined, face, encoding);
|
||||
return DoCreate(InfoFromLegacyParams(pixelSize,
|
||||
family,
|
||||
style,
|
||||
weight,
|
||||
underlined,
|
||||
face,
|
||||
encoding));
|
||||
}
|
||||
|
||||
bool Create(const wxNativeFontInfo& info, WXHFONT hFont = 0);
|
||||
@@ -150,13 +158,7 @@ public:
|
||||
|
||||
protected:
|
||||
// Common helper of overloaded Create() methods.
|
||||
bool DoCreate(wxFontInfo& info,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined = false,
|
||||
const wxString& face = wxEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
bool DoCreate(const wxFontInfo& info);
|
||||
|
||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info) wxOVERRIDE;
|
||||
virtual wxFontFamily DoGetFamily() const wxOVERRIDE;
|
||||
|
@@ -540,10 +540,42 @@ bool wxFontBase::SetFaceName(const wxString& facename)
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void InitInfoWithLegacyParams(wxFontInfo& info,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
if ( static_cast<int>(style) == wxDEFAULT )
|
||||
style = wxFONTSTYLE_NORMAL;
|
||||
|
||||
if ( static_cast<int>(weight) == wxDEFAULT )
|
||||
weight = wxFONTWEIGHT_NORMAL;
|
||||
|
||||
info
|
||||
.Family(family)
|
||||
.Style(style)
|
||||
.Weight(wxFontBase::GetNumericWeightOf(weight))
|
||||
.Underlined(underlined)
|
||||
.FaceName(face)
|
||||
.Encoding(encoding);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
/* static */
|
||||
void wxFontBase::AccountForCompatValues(int& pointSize,
|
||||
wxFontStyle& style,
|
||||
wxFontWeight& weight)
|
||||
wxFontInfo wxFontBase::InfoFromLegacyParams(int pointSize,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
// Old code specifies wxDEFAULT instead of -1 or wxNORMAL instead of the
|
||||
// new type-safe wxFONTSTYLE_NORMAL or wxFONTWEIGHT_NORMAL, continue
|
||||
@@ -551,11 +583,29 @@ void wxFontBase::AccountForCompatValues(int& pointSize,
|
||||
if ( pointSize == wxDEFAULT )
|
||||
pointSize = -1;
|
||||
|
||||
if ( static_cast<int>(style) == wxDEFAULT )
|
||||
style = wxFONTSTYLE_NORMAL;
|
||||
wxFontInfo info(pointSize);
|
||||
|
||||
if ( static_cast<int>(weight) == wxDEFAULT )
|
||||
weight = wxFONTWEIGHT_NORMAL;
|
||||
InitInfoWithLegacyParams(info,
|
||||
family, style, weight, underlined, face, encoding);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxFontInfo wxFontBase::InfoFromLegacyParams(const wxSize& pixelSize,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
wxFontInfo info(pixelSize);
|
||||
|
||||
InitInfoWithLegacyParams(info,
|
||||
family, style, weight, underlined, face, encoding);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void wxFontBase::SetSymbolicSize(wxFontSymbolicSize size)
|
||||
|
@@ -253,15 +253,9 @@ bool wxFont::Create( int pointSize,
|
||||
{
|
||||
UnRef();
|
||||
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
|
||||
m_refData = new wxFontRefData(wxFontInfo(pointSize).
|
||||
Family(family).
|
||||
Style(style).
|
||||
Weight(GetNumericWeightOf(weight)).
|
||||
Underlined(underlined).
|
||||
FaceName(face).
|
||||
Encoding(encoding));
|
||||
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||
style, weight, underlined,
|
||||
face, encoding));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -58,13 +58,7 @@ class wxFontRefData : public wxGDIRefData
|
||||
{
|
||||
public:
|
||||
// from broken down font parameters, also default ctor
|
||||
wxFontRefData(int size = -1,
|
||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
||||
bool underlined = false,
|
||||
const wxString& faceName = wxEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
wxFontRefData(const wxFontInfo& info = wxFontInfo());
|
||||
|
||||
// from XFLD
|
||||
wxFontRefData(const wxString& fontname);
|
||||
@@ -276,12 +270,15 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data )
|
||||
m_nativeFontInfo.FromString(data.m_nativeFontInfo.ToString());
|
||||
}
|
||||
|
||||
wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style,
|
||||
wxFontWeight weight, bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
wxFontRefData::wxFontRefData(const wxFontInfo& info)
|
||||
{
|
||||
Init(size, family, style, weight, underlined, faceName, encoding);
|
||||
Init(info.GetPointSize(),
|
||||
info.GetFamily(),
|
||||
info.GetStyle(),
|
||||
info.GetWeight(),
|
||||
info.IsUnderlined(),
|
||||
info.GetFaceName(),
|
||||
info.GetEncoding());
|
||||
}
|
||||
|
||||
wxFontRefData::wxFontRefData(const wxString& fontname)
|
||||
@@ -460,10 +457,9 @@ bool wxFont::Create( int pointSize,
|
||||
{
|
||||
UnRef();
|
||||
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
|
||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
||||
underlined, face, encoding);
|
||||
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||
style, weight, underlined,
|
||||
face, encoding));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -72,15 +72,15 @@ class wxFontRefData: public wxGDIRefData
|
||||
friend class wxFont;
|
||||
|
||||
public:
|
||||
wxFontRefData(int size = wxDEFAULT,
|
||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
||||
bool underlined = false,
|
||||
const wxString& faceName = wxEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
||||
wxFontRefData(const wxFontInfo& info = wxFontInfo())
|
||||
{
|
||||
Init(size, family, style, weight, underlined, faceName, encoding);
|
||||
Init(info.GetPointSize(),
|
||||
info.GetFamily(),
|
||||
info.GetStyle(),
|
||||
info.GetWeight(),
|
||||
info.IsUnderlined(),
|
||||
info.GetFaceName(),
|
||||
info.GetEncoding());
|
||||
}
|
||||
|
||||
wxFontRefData(const wxFontRefData& data)
|
||||
@@ -223,10 +223,9 @@ bool wxFont::Create(int pointSize,
|
||||
{
|
||||
UnRef();
|
||||
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
|
||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
||||
underlined, faceName, encoding);
|
||||
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||
style, weight, underlined,
|
||||
faceName, encoding));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -761,23 +761,11 @@ bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
|
||||
return RealizeResource();
|
||||
}
|
||||
|
||||
bool wxFont::DoCreate(wxFontInfo& info,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
bool underlined,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
bool wxFont::DoCreate(const wxFontInfo& info)
|
||||
{
|
||||
UnRef();
|
||||
|
||||
m_refData = new wxFontRefData(info.
|
||||
Family(family).
|
||||
Style(style).
|
||||
Weight(GetNumericWeightOf(weight)).
|
||||
Underlined(underlined).
|
||||
FaceName(faceName).
|
||||
Encoding(encoding));
|
||||
m_refData = new wxFontRefData(info);
|
||||
|
||||
return RealizeResource();
|
||||
}
|
||||
|
@@ -521,15 +521,10 @@ bool wxFont::Create(int pointSize,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||
style, weight, underlined,
|
||||
faceName, encoding));
|
||||
|
||||
m_refData = new wxFontRefData(wxFontInfo(pointSize).
|
||||
Family(family).
|
||||
Style(style).
|
||||
Weight(GetNumericWeightOf(weight)).
|
||||
Underlined(underlined).
|
||||
FaceName(faceName).
|
||||
Encoding(encoding));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -188,7 +188,6 @@ wxFont::wxFont(const wxSize& pixelSize,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
m_refData = new wxFontRefData();
|
||||
Create(pixelSize, family, style, weight, underlined, face, encoding);
|
||||
}
|
||||
|
||||
@@ -200,27 +199,19 @@ wxFont::wxFont(int size,
|
||||
const wxString& face,
|
||||
wxFontEncoding encoding)
|
||||
{
|
||||
m_refData = new wxFontRefData();
|
||||
Create(wxSize(0, size), (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding);
|
||||
}
|
||||
|
||||
|
||||
bool wxFont::Create(wxSize size, wxFontFamily family, wxFontStyle style,
|
||||
wxFontWeight weight, bool underlined, const wxString& face,
|
||||
wxFontEncoding WXUNUSED(encoding) )
|
||||
wxFontEncoding encoding )
|
||||
{
|
||||
int pointSize = size.GetHeight();
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
UnRef();
|
||||
|
||||
if (!face.empty())
|
||||
M_FONTDATA.SetFaceName(face);
|
||||
else
|
||||
M_FONTDATA.SetFamily(family);
|
||||
|
||||
M_FONTDATA.SetStyle(style);
|
||||
M_FONTDATA.SetWeight(weight);
|
||||
M_FONTDATA.SetUnderlined(underlined);
|
||||
M_FONTDATA.SetPointSize(pointSize);
|
||||
m_refData = new wxFontRefData(InfoFromLegacyParams(size.GetHeight(), family,
|
||||
style, weight, underlined,
|
||||
face, encoding));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user