diff --git a/include/wx/font.h b/include/wx/font.h index ec64650c14..2e2281c530 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -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 diff --git a/include/wx/msw/font.h b/include/wx/msw/font.h index 887b2dfd0f..ee803d9cce 100644 --- a/include/wx/msw/font.h +++ b/include/wx/msw/font.h @@ -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; diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index bd279a46fb..deb3b3d2f2 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -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(style) == wxDEFAULT ) + style = wxFONTSTYLE_NORMAL; + + if ( static_cast(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(style) == wxDEFAULT ) - style = wxFONTSTYLE_NORMAL; + wxFontInfo info(pointSize); - if ( static_cast(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) diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index d023e6db79..2359965aee 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -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; } diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index 4fbfe8c92a..532e20442f 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -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; } diff --git a/src/motif/font.cpp b/src/motif/font.cpp index 76c63d3c9c..3e5d07e25f 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -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; } diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 6fa270c79e..5f7f34c6c6 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -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(); } diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index c677301481..7de7178551 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -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; } diff --git a/src/qt/font.cpp b/src/qt/font.cpp index 95c2b11566..d6b5ae3174 100644 --- a/src/qt/font.cpp +++ b/src/qt/font.cpp @@ -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; }