X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/177df6c5f6c24251cab056ce39e206ec3fd6b44b..04236b74cd5c82645aff3c99736291ebe2f52cc5:/src/gtk/font.cpp?ds=inline diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 8dbe0064bd..7f77a346fc 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -31,10 +31,7 @@ #include "wx/fontutil.h" #include "wx/tokenzr.h" -#include - #include "wx/gtk/private.h" -#include // ---------------------------------------------------------------------------- // constants @@ -43,25 +40,18 @@ // the default size (in points) for the fonts static const int wxDEFAULT_FONT_SIZE = 12; -// ---------------------------------------------------------------------------- -// wxScaledFontList: maps the font sizes to the GDK fonts for the given font -// ---------------------------------------------------------------------------- - -WX_DECLARE_HASH_MAP(int, GdkFont *, wxIntegerHash, wxIntegerEqual, - wxScaledFontList); - // ---------------------------------------------------------------------------- // wxFontRefData // ---------------------------------------------------------------------------- -class wxFontRefData : public wxObjectRefData +class wxFontRefData : public wxGDIRefData { public: // from broken down font parameters, also default ctor wxFontRefData(int size = -1, - int family = wxFONTFAMILY_DEFAULT, - int style = wxFONTSTYLE_NORMAL, - int weight = wxFONTWEIGHT_NORMAL, + wxFontFamily family = wxFONTFAMILY_DEFAULT, + wxFontStyle style = wxFONTSTYLE_NORMAL, + wxFontWeight weight = wxFONTWEIGHT_NORMAL, bool underlined = false, const wxString& faceName = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT); @@ -84,9 +74,9 @@ public: // setters: all of them also take care to modify m_nativeFontInfo if we // have it so as to not lose the information not carried by our fields void SetPointSize(int pointSize); - void SetFamily(int family); - void SetStyle(int style); - void SetWeight(int weight); + void SetFamily(wxFontFamily family); + void SetStyle(wxFontStyle style); + void SetWeight(wxFontWeight weight); void SetUnderlined(bool underlined); bool SetFaceName(const wxString& facename); void SetEncoding(wxFontEncoding encoding); @@ -100,9 +90,9 @@ public: protected: // common part of all ctors void Init(int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding); @@ -115,9 +105,9 @@ private: void ClearGdkFonts(); int m_pointSize; - int m_family, - m_style, - m_weight; + wxFontFamily m_family; + wxFontStyle m_style; + wxFontWeight m_weight; bool m_underlined; wxString m_faceName; wxFontEncoding m_encoding; @@ -130,14 +120,16 @@ private: friend class wxFont; }; +#define M_FONTDATA ((wxFontRefData*)m_refData) + // ---------------------------------------------------------------------------- // wxFontRefData // ---------------------------------------------------------------------------- void wxFontRefData::Init(int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) @@ -158,6 +150,8 @@ void wxFontRefData::Init(int pointSize, m_underlined = underlined; m_encoding = encoding; + if ( m_encoding == wxFONTENCODING_DEFAULT ) + m_encoding = wxFont::GetDefaultEncoding(); m_noAA = false; @@ -202,7 +196,7 @@ void wxFontRefData::InitFromNative() PangoFontDescription *desc = m_nativeFontInfo.description; // init fields - m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) ); + m_faceName = wxGTK_CONV_BACK_SYS(pango_font_description_get_family(desc)); // Pango sometimes needs to have a size int pango_size = pango_font_description_get_size( desc ); @@ -238,7 +232,7 @@ void wxFontRefData::InitFromNative() } wxFontRefData::wxFontRefData( const wxFontRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_pointSize = data.m_pointSize; m_family = data.m_family; @@ -258,8 +252,8 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data ) m_nativeFontInfo.FromString(data.m_nativeFontInfo.ToString()); } -wxFontRefData::wxFontRefData(int size, int family, int style, - int weight, bool underlined, +wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) { @@ -293,21 +287,21 @@ void wxFontRefData::SetPointSize(int pointSize) m_nativeFontInfo.SetPointSize(pointSize); } -void wxFontRefData::SetFamily(int family) +void wxFontRefData::SetFamily(wxFontFamily family) { m_family = family; // TODO: what are we supposed to do with m_nativeFontInfo here? } -void wxFontRefData::SetStyle(int style) +void wxFontRefData::SetStyle(wxFontStyle style) { m_style = style; m_nativeFontInfo.SetStyle((wxFontStyle)style); } -void wxFontRefData::SetWeight(int weight) +void wxFontRefData::SetWeight(wxFontWeight weight) { m_weight = weight; @@ -362,9 +356,9 @@ wxFont::wxFont(const wxNativeFontInfo& info) } bool wxFont::Create( int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& face, wxFontEncoding encoding) @@ -392,20 +386,6 @@ bool wxFont::Create(const wxString& fontname) return true; } -void wxFont::Unshare() -{ - if (!m_refData) - { - m_refData = new wxFontRefData(); - } - else - { - wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); - UnRef(); - m_refData = ref; - } -} - wxFont::~wxFont() { } @@ -430,11 +410,11 @@ wxString wxFont::GetFaceName() const : M_FONTDATA->m_faceName; } -int wxFont::GetFamily() const +wxFontFamily wxFont::GetFamily() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") ); - int ret = M_FONTDATA->m_family; + wxFontFamily ret = M_FONTDATA->m_family; if (M_FONTDATA->HasNativeFont()) // wxNativeFontInfo::GetFamily is expensive, must not call more than once ret = M_FONTDATA->m_nativeFontInfo.GetFamily(); @@ -445,17 +425,17 @@ int wxFont::GetFamily() const return ret; } -int wxFont::GetStyle() const +wxFontStyle wxFont::GetStyle() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + wxCHECK_MSG( Ok(), wxFONTSTYLE_MAX, wxT("invalid font") ); return M_FONTDATA->HasNativeFont() ? M_FONTDATA->m_nativeFontInfo.GetStyle() : M_FONTDATA->m_style; } -int wxFont::GetWeight() const +wxFontWeight wxFont::GetWeight() const { - wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); + wxCHECK_MSG( Ok(), wxFONTWEIGHT_MAX, wxT("invalid font") ); return M_FONTDATA->HasNativeFont() ? M_FONTDATA->m_nativeFontInfo.GetWeight() : M_FONTDATA->m_weight; @@ -484,7 +464,7 @@ bool wxFont::GetNoAntiAliasing() const const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { - wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") ); + wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); return &(M_FONTDATA->m_nativeFontInfo); } @@ -502,35 +482,35 @@ bool wxFont::IsFixedWidth() const void wxFont::SetPointSize(int pointSize) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetPointSize(pointSize); } -void wxFont::SetFamily(int family) +void wxFont::SetFamily(wxFontFamily family) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetFamily(family); } -void wxFont::SetStyle(int style) +void wxFont::SetStyle(wxFontStyle style) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetStyle(style); } -void wxFont::SetWeight(int weight) +void wxFont::SetWeight(wxFontWeight weight) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetWeight(weight); } bool wxFont::SetFaceName(const wxString& faceName) { - Unshare(); + AllocExclusive(); return M_FONTDATA->SetFaceName(faceName) && wxFontBase::SetFaceName(faceName); @@ -538,28 +518,38 @@ bool wxFont::SetFaceName(const wxString& faceName) void wxFont::SetUnderlined(bool underlined) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetUnderlined(underlined); } void wxFont::SetEncoding(wxFontEncoding encoding) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetEncoding(encoding); } void wxFont::DoSetNativeFontInfo( const wxNativeFontInfo& info ) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetNativeFontInfo( info ); } void wxFont::SetNoAntiAliasing( bool no ) { - Unshare(); + AllocExclusive(); M_FONTDATA->SetNoAntiAliasing( no ); } + +wxGDIRefData* wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData* wxFont::CloneGDIRefData(const wxGDIRefData* data) const +{ + return new wxFontRefData(*static_cast(data)); +}