From 054c5c4af7821528b24b7f4eb5d125e39e936e9a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Sep 2018 19:13:18 +0200 Subject: [PATCH] Implement support for numeric weights specified in wxFontInfo Update the major ports to use wxFontInfo::GetNumericWeight() instead of GetWeight(). --- include/wx/osx/font.h | 18 +++--------------- src/gtk/font.cpp | 15 ++++++++------- src/msw/font.cpp | 13 +++++++------ src/osx/carbon/font.cpp | 26 +++++++++++++++++++++----- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/include/wx/osx/font.h b/include/wx/osx/font.h index e0b1ac86d3..50ebb978d0 100644 --- a/include/wx/osx/font.h +++ b/include/wx/osx/font.h @@ -36,19 +36,7 @@ public: // ctors and such wxFont() { } - wxFont(const wxFontInfo& info) - { - Create(info.GetFractionalPointSize(), - info.GetFamily(), - info.GetStyle(), - info.GetWeight(), - info.IsUnderlined(), - info.GetFaceName(), - info.GetEncoding()); - - if ( info.IsUsingSizeInPixels() ) - SetPixelSize(info.GetPixelSize()); - } + wxFont(const wxFontInfo& info); wxFont( wxOSXSystemFont systemFont ); wxFont(CTFontRef font); @@ -71,7 +59,7 @@ public: wxFont(float size, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined = false, const wxString& face = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT) @@ -102,7 +90,7 @@ public: bool Create(float size, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined = false, const wxString& face = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT); diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 5b80f897dc..7ad3e9ec11 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -50,7 +50,7 @@ public: wxFontRefData(float size = -1.0f, wxFontFamily family = wxFONTFAMILY_DEFAULT, wxFontStyle style = wxFONTSTYLE_NORMAL, - wxFontWeight weight = wxFONTWEIGHT_NORMAL, + int weight = wxFONTWEIGHT_NORMAL, bool underlined = false, bool strikethrough = false, const wxString& faceName = wxEmptyString, @@ -83,7 +83,7 @@ protected: void Init(float pointSize, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -109,7 +109,7 @@ private: void wxFontRefData::Init(float pointSize, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -138,7 +138,7 @@ void wxFontRefData::Init(float pointSize, pointSize < 0 ? static_cast(wxDEFAULT_FONT_SIZE) : pointSize ); - SetWeight( weight ); + SetNumericWeight( weight ); SetUnderlined( underlined ); SetStrikethrough( strikethrough ); } @@ -161,7 +161,7 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data ) } wxFontRefData::wxFontRefData(float size, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, bool underlined, bool strikethrough, + int weight, bool underlined, bool strikethrough, const wxString& faceName, wxFontEncoding encoding) { @@ -288,7 +288,7 @@ wxFont::wxFont(const wxFontInfo& info) m_refData = new wxFontRefData(info.GetFractionalPointSize(), info.GetFamily(), info.GetStyle(), - info.GetWeight(), + info.GetNumericWeight(), info.IsUnderlined(), info.IsStrikethrough(), info.GetFaceName(), @@ -312,7 +312,8 @@ bool wxFont::Create( int pointSize, AccountForCompatValues(pointSize, style, weight); m_refData = new wxFontRefData(wxFontInfo::ToFloatPointSize(pointSize), - family, style, weight, + family, style, + GetNumericWeightOf(weight), underlined, false, face, encoding); return true; diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 6eac089019..a2111bcdc9 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -70,7 +70,7 @@ public: bool sizeUsingPixels, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -272,7 +272,7 @@ protected: bool sizeUsingPixels, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -347,7 +347,7 @@ void wxFontRefData::Init(float pointSize, bool sizeUsingPixels, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -371,7 +371,7 @@ void wxFontRefData::Init(float pointSize, } SetStyle(style); - m_nativeFontInfo.SetWeight(weight); + SetNumericWeight(weight); SetUnderlined(underlined); SetStrikethrough(strikethrough); @@ -801,7 +801,7 @@ wxFont::wxFont(const wxFontInfo& info) info.IsUsingSizeInPixels(), info.GetFamily(), info.GetStyle(), - info.GetWeight(), + info.GetNumericWeight(), info.IsUnderlined(), info.IsStrikethrough(), info.GetFaceName(), @@ -833,7 +833,8 @@ bool wxFont::DoCreate(int pointSize, m_refData = new wxFontRefData(wxFontInfo::ToFloatPointSize(pointSize), pixelSize, sizeUsingPixels, - family, style, weight, + family, style, + GetNumericWeightOf(weight), underlined, false, faceName, encoding); return RealizeResource(); diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index d2e1967eaa..d15b5fd189 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -45,7 +45,7 @@ public: wxFontRefData(float size, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -173,7 +173,7 @@ protected: void Init(float size, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -289,7 +289,7 @@ void wxFontRefData::Init() void wxFontRefData::Init(float size, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, bool strikethrough, const wxString& faceName, @@ -540,6 +540,20 @@ wxFont::wxFont(const wxString& fontdesc) (void)Create(info); } +wxFont::wxFont(const wxFontInfo& info) +{ + Create(info.GetFractionalPointSize(), + info.GetFamily(), + info.GetStyle(), + info.GetNumericWeight(), + info.IsUnderlined(), + info.GetFaceName(), + info.GetEncoding()); + + if ( info.IsUsingSizeInPixels() ) + SetPixelSize(info.GetPixelSize()); +} + wxFont::wxFont(int size, int family, int style, @@ -555,7 +569,7 @@ wxFont::wxFont(int size, bool wxFont::Create(float pointSize, wxFontFamily family, wxFontStyle style, - wxFontWeight weight, + int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) @@ -579,7 +593,9 @@ bool wxFont::Create(int pointSize, AccountForCompatValues(pointSize, style, weight); return Create(wxFontInfo::ToFloatPointSize(pointSize), - family, style, weight, underlined, faceName, encoding); + family, style, + GetNumericWeightOf(weight), + underlined, faceName, encoding); } wxFont::~wxFont()