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