From 8ff36f98f353ab1fd91c30cacebb90f30e035559 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 5 Sep 2018 02:16:10 +0200 Subject: [PATCH] Move {Get,Set}Weight() implementations to wxFontBase Implement these methods in the base class in terms of {Get,Set}NumericWeight() in order to avoid having to do it for each platform. No real changes. --- include/wx/font.h | 23 +++++++++++++++-------- include/wx/gtk/font.h | 2 -- include/wx/msw/font.h | 2 -- include/wx/osx/font.h | 2 -- src/common/fontcmn.cpp | 12 ++++++++++++ src/gtk/font.cpp | 14 -------------- src/msw/font.cpp | 28 +--------------------------- src/osx/carbon/font.cpp | 27 +-------------------------- 8 files changed, 29 insertions(+), 81 deletions(-) diff --git a/include/wx/font.h b/include/wx/font.h index 249859fc16..d325e5c959 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -352,7 +352,6 @@ public: virtual bool IsUsingSizeInPixels() const; wxFontFamily GetFamily() const; virtual wxFontStyle GetStyle() const = 0; - virtual wxFontWeight GetWeight() const = 0; virtual int GetNumericWeight() const = 0; virtual bool GetUnderlined() const = 0; virtual bool GetStrikethrough() const { return false; } @@ -360,6 +359,9 @@ public: virtual wxFontEncoding GetEncoding() const = 0; virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0; + // Accessors that can be overridden in the platform-specific code but for + // which we provide a reasonable default implementation in the base class. + virtual wxFontWeight GetWeight() const; virtual bool IsFixedWidth() const; wxString GetNativeFontInfoDesc() const; @@ -370,7 +372,6 @@ public: virtual void SetPixelSize( const wxSize& pixelSize ); virtual void SetFamily( wxFontFamily family ) = 0; virtual void SetStyle( wxFontStyle style ) = 0; - virtual void SetWeight( wxFontWeight weight ) = 0; virtual void SetNumericWeight( int weight ) = 0; virtual void SetUnderlined( bool underlined ) = 0; @@ -380,6 +381,10 @@ public: void SetNativeFontInfo(const wxNativeFontInfo& info) { DoSetNativeFontInfo(info); } + // Similarly to the accessors above, the functions in this group have a + // reasonable default implementation in the base class. + virtual void SetWeight( wxFontWeight weight ); + bool SetNativeFontInfo(const wxString& info); bool SetNativeFontInfoUserDesc(const wxString& info); @@ -413,6 +418,14 @@ public: wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;) #endif // WXWIN_COMPATIBILITY_2_8 + wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants instead of raw values") + void SetWeight(int weight) + { SetWeight(static_cast(weight)); } + + wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants instead of wxLIGHT/wxNORMAL/wxBOLD") + void SetWeight(wxDeprecatedGUIConstants weight) + { SetWeight(static_cast(weight)); } + // from the font components wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants") static wxFont *New( @@ -500,18 +513,12 @@ WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font); wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \ void SetStyle(int style) \ { SetStyle((wxFontStyle)style); } \ - wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants") \ - void SetWeight(int weight) \ - { SetWeight((wxFontWeight)weight); } \ wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \ void SetFamily(wxDeprecatedGUIConstants family) \ { SetFamily((wxFontFamily)family); } \ wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \ void SetStyle(wxDeprecatedGUIConstants style) \ { SetStyle((wxFontStyle)style); } \ - wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants") \ - void SetWeight(wxDeprecatedGUIConstants weight) \ - { SetWeight((wxFontWeight)weight); } \ \ /* functions for modifying font in place */ \ wxFont& MakeBold(); \ diff --git a/include/wx/gtk/font.h b/include/wx/gtk/font.h index 20359e319b..149be51b84 100644 --- a/include/wx/gtk/font.h +++ b/include/wx/gtk/font.h @@ -66,7 +66,6 @@ public: // implement base class pure virtuals virtual float GetFractionalPointSize() const wxOVERRIDE; virtual wxFontStyle GetStyle() const wxOVERRIDE; - virtual wxFontWeight GetWeight() const wxOVERRIDE; virtual int GetNumericWeight() const wxOVERRIDE; virtual wxString GetFaceName() const wxOVERRIDE; virtual bool GetUnderlined() const wxOVERRIDE; @@ -78,7 +77,6 @@ public: virtual void SetPointSize(float pointSize) wxOVERRIDE; virtual void SetFamily(wxFontFamily family) wxOVERRIDE; virtual void SetStyle(wxFontStyle style) wxOVERRIDE; - virtual void SetWeight(wxFontWeight weight) wxOVERRIDE; virtual void SetNumericWeight(int weight) wxOVERRIDE; virtual bool SetFaceName( const wxString& faceName ) wxOVERRIDE; virtual void SetUnderlined( bool underlined ) wxOVERRIDE; diff --git a/include/wx/msw/font.h b/include/wx/msw/font.h index 2e4fade8f2..000d840c32 100644 --- a/include/wx/msw/font.h +++ b/include/wx/msw/font.h @@ -89,7 +89,6 @@ public: virtual wxSize GetPixelSize() const wxOVERRIDE; virtual bool IsUsingSizeInPixels() const wxOVERRIDE; virtual wxFontStyle GetStyle() const wxOVERRIDE; - virtual wxFontWeight GetWeight() const wxOVERRIDE; virtual int GetNumericWeight() const wxOVERRIDE; virtual bool GetUnderlined() const wxOVERRIDE; virtual bool GetStrikethrough() const wxOVERRIDE; @@ -101,7 +100,6 @@ public: virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE; virtual void SetFamily(wxFontFamily family) wxOVERRIDE; virtual void SetStyle(wxFontStyle style) wxOVERRIDE; - virtual void SetWeight(wxFontWeight weight) wxOVERRIDE; virtual void SetNumericWeight(int weight) wxOVERRIDE; virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE; virtual void SetUnderlined(bool underlined) wxOVERRIDE; diff --git a/include/wx/osx/font.h b/include/wx/osx/font.h index 5078cd32ce..2494d78604 100644 --- a/include/wx/osx/font.h +++ b/include/wx/osx/font.h @@ -122,7 +122,6 @@ public: virtual float GetFractionalPointSize() const wxOVERRIDE; virtual wxSize GetPixelSize() const wxOVERRIDE; virtual wxFontStyle GetStyle() const wxOVERRIDE; - virtual wxFontWeight GetWeight() const wxOVERRIDE; virtual int GetNumericWeight() const wxOVERRIDE; virtual bool GetUnderlined() const wxOVERRIDE; virtual bool GetStrikethrough() const wxOVERRIDE; @@ -135,7 +134,6 @@ public: virtual void SetPointSize(float pointSize) wxOVERRIDE; virtual void SetFamily(wxFontFamily family) wxOVERRIDE; virtual void SetStyle(wxFontStyle style) wxOVERRIDE; - virtual void SetWeight(wxFontWeight weight) wxOVERRIDE; virtual void SetNumericWeight(int weight) wxOVERRIDE; virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE; virtual void SetUnderlined(bool underlined) wxOVERRIDE; diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 2e5f9784e5..5c168279d6 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -294,6 +294,13 @@ wxSize wxFontBase::GetPixelSize() const return wxSize(dc.GetCharWidth(), dc.GetCharHeight()); } +wxFontWeight wxFontBase::GetWeight() const +{ + wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" ); + + return GetWeightClosestToNumericValue(GetNumericWeight()); +} + bool wxFontBase::IsUsingSizeInPixels() const { return false; @@ -362,6 +369,11 @@ void wxFontBase::SetPixelSize( const wxSize& pixelSize ) SetPointSize(largestGood); } +void wxFontBase::SetWeight(wxFontWeight weight) +{ + SetNumericWeight(GetNumericWeightOf(weight)); +} + void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info) { #ifdef wxNO_NATIVE_FONTINFO diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index bcd3ffbbdd..a3d3c5b1dd 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -372,13 +372,6 @@ wxFontStyle wxFont::GetStyle() const return M_FONTDATA->m_nativeFontInfo.GetStyle(); } -wxFontWeight wxFont::GetWeight() const -{ - wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" ); - - return M_FONTDATA->m_nativeFontInfo.GetWeight(); -} - int wxFont::GetNumericWeight() const { wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" ); @@ -447,13 +440,6 @@ void wxFont::SetStyle(wxFontStyle style) M_FONTDATA->SetStyle(style); } -void wxFont::SetWeight(wxFontWeight weight) -{ - AllocExclusive(); - - M_FONTDATA->SetWeight(weight); -} - void wxFont::SetNumericWeight(int weight) { AllocExclusive(); diff --git a/src/msw/font.cpp b/src/msw/font.cpp index a356e10c50..dc7a8c723a 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -123,11 +123,6 @@ public: return m_nativeFontInfo.GetStyle(); } - wxFontWeight GetWeight() const - { - return m_nativeFontInfo.GetWeight(); - } - int GetNumericWeight() const { return m_nativeFontInfo.GetNumericWeight(); @@ -214,13 +209,6 @@ public: m_nativeFontInfo.SetStyle(style); } - void SetWeight(wxFontWeight weight) - { - Free(); - - m_nativeFontInfo.SetWeight(weight); - } - void SetNumericWeight(int weight) { Free(); @@ -374,7 +362,7 @@ void wxFontRefData::Init(int pointSize, SetPointSize(pointSize == -1 ? wxNORMAL_FONT->GetPointSize() : pointSize); SetStyle(style); - SetWeight(weight); + m_nativeFontInfo.SetWeight(weight); SetUnderlined(underlined); SetStrikethrough(strikethrough); @@ -929,13 +917,6 @@ void wxFont::SetStyle(wxFontStyle style) M_FONTDATA->SetStyle(style); } -void wxFont::SetWeight(wxFontWeight weight) -{ - AllocExclusive(); - - M_FONTDATA->SetWeight(weight); -} - void wxFont::SetNumericWeight(int weight) { AllocExclusive(); @@ -1025,13 +1006,6 @@ wxFontStyle wxFont::GetStyle() const return M_FONTDATA->GetStyle(); } -wxFontWeight wxFont::GetWeight() const -{ - wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" ); - - return M_FONTDATA->GetWeight(); -} - int wxFont::GetNumericWeight() const { wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font")); diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index cfac98ee0e..cc680674e9 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -72,8 +72,6 @@ public: wxFontStyle GetStyle() const { return m_info.GetStyle(); } - wxFontWeight GetWeight() const { return m_info.GetWeight(); } - int GetNumericWeight() const { return m_info.GetNumericWeight(); } bool GetUnderlined() const { return m_info.GetUnderlined(); } @@ -121,15 +119,6 @@ public: } } - void SetWeight(wxFontWeight weight) - { - if (m_info.GetWeight() != weight) - { - m_info.SetWeight(weight); - Free(); - } - } - void SetNumericWeight(int weight) { if (m_info.GetNumericWeight() != weight) @@ -312,7 +301,7 @@ void wxFontRefData::Init(float size, else SetFamily(family); SetPointSize(size < 0 ? wxNORMAL_FONT->GetFractionalPointSize() : size); - SetWeight(weight); + SetNumericWeight(weight); SetStyle(style); SetUnderlined(underlined); SetStrikethrough(strikethrough); @@ -651,13 +640,6 @@ void wxFont::SetStyle(wxFontStyle style) M_FONTDATA->SetStyle(style); } -void wxFont::SetWeight(wxFontWeight weight) -{ - AllocExclusive(); - - M_FONTDATA->SetWeight(weight); -} - void wxFont::SetNumericWeight(int weight) { AllocExclusive(); @@ -738,13 +720,6 @@ wxFontStyle wxFont::GetStyle() const return M_FONTDATA->GetStyle(); } -wxFontWeight wxFont::GetWeight() const -{ - wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font")); - - return M_FONTDATA->GetWeight(); -} - int wxFont::GetNumericWeight() const { wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));