X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9eddec696f06d65a80e7339b2fae14fcb55f8383..d7e2b52235d70e25d7797ce1dccd97fa6989f4b5:/src/x11/font.cpp diff --git a/src/x11/font.cpp b/src/x11/font.cpp index 7215b89230..0855e067a3 100644 --- a/src/x11/font.cpp +++ b/src/x11/font.cpp @@ -35,11 +35,12 @@ #include "wx/string.h" #include "wx/utils.h" // for wxGetDisplay() #include "wx/settings.h" + #include "wx/gdicmn.h" #endif -#include "wx/gdicmn.h" #include "wx/fontutil.h" // for wxNativeFontInfo #include "wx/tokenzr.h" +#include "wx/fontenum.h" #include "wx/x11/private.h" @@ -65,7 +66,7 @@ class wxXFont : public wxObject { public: wxXFont(); - ~wxXFont(); + virtual ~wxXFont(); WXFontStructPtr m_fontStruct; // XFontStruct WXDisplay* m_display; // XDisplay @@ -92,7 +93,7 @@ wxXFont::~wxXFont() // wxFontRefData // ---------------------------------------------------------------------------- -class wxFontRefData: public wxObjectRefData +class wxFontRefData: public wxGDIRefData { friend class wxFont; @@ -121,7 +122,7 @@ public: void SetStyle(int style); void SetWeight(int weight); void SetUnderlined(bool underlined); - void SetFaceName(const wxString& facename); + bool SetFaceName(const wxString& facename); void SetEncoding(wxFontEncoding encoding); void SetNoAntiAliasing( bool no = true ) { m_noAA = no; } @@ -164,6 +165,8 @@ protected: #endif }; +#define M_FONTDATA ((wxFontRefData*)m_refData) + // ---------------------------------------------------------------------------- // wxFontRefData // ---------------------------------------------------------------------------- @@ -184,37 +187,47 @@ void wxFontRefData::Init(int pointSize, m_style = style == wxDEFAULT ? wxFONTSTYLE_NORMAL : style; m_weight = weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight; - // and here, do we really want to forbid creation of the font of the size - // 90 (the value of wxDEFAULT)?? - m_pointSize = pointSize == wxDEFAULT || pointSize == -1 - ? wxDEFAULT_FONT_SIZE - : pointSize; - m_underlined = underlined; m_encoding = encoding; #if wxUSE_UNICODE + if ( m_nativeFontInfo.description ) + pango_font_description_free(m_nativeFontInfo.description); + // Create native font info m_nativeFontInfo.description = pango_font_description_new(); - // And set its values - switch (m_family) + // if a face name is specified, use it if it's available, otherwise use + // just the family + if ( faceName.empty() || !wxFontEnumerator::IsValidFacename(faceName) ) { - case wxFONTFAMILY_MODERN: - case wxFONTFAMILY_TELETYPE: - pango_font_description_set_family( m_nativeFontInfo.description, "monospace" ); - break; - case wxFONTFAMILY_ROMAN: - pango_font_description_set_family( m_nativeFontInfo.description, "serif" ); - break; - default: - pango_font_description_set_family( m_nativeFontInfo.description, "sans" ); - break; + // TODO: scan system for valid fonts matching the given family instead + // of hardcoding them here + switch ( m_family ) + { + case wxFONTFAMILY_TELETYPE: + m_faceName = wxT("monospace"); + break; + + case wxFONTFAMILY_ROMAN: + m_faceName = wxT("serif"); + break; + + default: + m_faceName = wxT("sans"); + } } - SetStyle( m_style ); - SetPointSize( m_pointSize ); - SetWeight( m_weight ); -#endif + else // specified face name is available, use it + { + m_faceName = faceName; + } + + m_nativeFontInfo.SetFaceName(m_faceName); + m_nativeFontInfo.SetWeight((wxFontWeight)m_weight); + m_nativeFontInfo.SetStyle((wxFontStyle)m_style); +#endif // wxUSE_UNICODE + + SetPointSize(pointSize); } void wxFontRefData::InitFromNative() @@ -243,23 +256,27 @@ void wxFontRefData::InitFromNative() break; } +// Not defined in some Pango versions +#define wxPANGO_WEIGHT_SEMIBOLD 600 + switch (pango_font_description_get_weight( desc )) { case PANGO_WEIGHT_ULTRALIGHT: - m_weight = wxFONTWEIGHT_LIGHT; - break; case PANGO_WEIGHT_LIGHT: m_weight = wxFONTWEIGHT_LIGHT; break; + + default: + wxFAIL_MSG(_T("unknown Pango font weight")); + // fall through + case PANGO_WEIGHT_NORMAL: m_weight = wxFONTWEIGHT_NORMAL; break; + + case wxPANGO_WEIGHT_SEMIBOLD: case PANGO_WEIGHT_BOLD: - m_weight = wxFONTWEIGHT_BOLD; - break; case PANGO_WEIGHT_ULTRABOLD: - m_weight = wxFONTWEIGHT_BOLD; - break; case PANGO_WEIGHT_HEAVY: m_weight = wxFONTWEIGHT_BOLD; break; @@ -308,8 +325,8 @@ void wxFontRefData::InitFromNative() } } - switch ( wxToupper(*m_nativeFontInfo. - GetXFontComponent(wxXLFD_SLANT).c_str()) ) + switch ( wxToupper( m_nativeFontInfo. + GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() ) { case _T('I'): // italique m_style = wxFONTSTYLE_ITALIC; @@ -385,7 +402,7 @@ void wxFontRefData::InitFromNative() } wxFontRefData::wxFontRefData( const wxFontRefData& data ) - : wxObjectRefData() + : wxGDIRefData() { m_pointSize = data.m_pointSize; m_family = data.m_family; @@ -448,13 +465,12 @@ wxFontRefData::~wxFontRefData() void wxFontRefData::SetPointSize(int pointSize) { - m_pointSize = pointSize; + // NB: Pango doesn't support point sizes less than 1 + m_pointSize = pointSize == wxDEFAULT || pointSize < 1 ? wxDEFAULT_FONT_SIZE + : pointSize; #if wxUSE_UNICODE - // Get native info - PangoFontDescription *desc = m_nativeFontInfo.description; - - pango_font_description_set_size( desc, m_pointSize * PANGO_SCALE ); + m_nativeFontInfo.SetPointSize(m_pointSize); #endif } @@ -503,9 +519,10 @@ void wxFontRefData::SetUnderlined(bool underlined) // the XLFD doesn't have "underlined" field anyhow } -void wxFontRefData::SetFaceName(const wxString& facename) +bool wxFontRefData::SetFaceName(const wxString& facename) { m_faceName = facename; + return true; } void wxFontRefData::SetEncoding(wxFontEncoding encoding) @@ -669,6 +686,16 @@ wxFont::~wxFont() { } +wxGDIRefData *wxFont::CreateGDIRefData() const +{ + return new wxFontRefData; +} + +wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); +} + // ---------------------------------------------------------------------------- // change the font attributes // ---------------------------------------------------------------------------- @@ -816,11 +843,12 @@ void wxFont::SetWeight(int weight) M_FONTDATA->SetWeight(weight); } -void wxFont::SetFaceName(const wxString& faceName) +bool wxFont::SetFaceName(const wxString& faceName) { Unshare(); - M_FONTDATA->SetFaceName(faceName); + return M_FONTDATA->SetFaceName(faceName) && + wxFontBase::SetFaceName(faceName); } void wxFont::SetUnderlined(bool underlined)