Implement arbitrary font weight support for wxX11
This is mostly done to fix (half of) compilation errors after introduction of pure virtual wxFont::{Get,Set}NumericWeight() as wxFont in wxX11 couldn't be compiled any more as it didn't define them.
This commit is contained in:
parent
8ff36f98f3
commit
979d541072
@ -83,7 +83,7 @@ public:
|
|||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
virtual int GetPointSize() const;
|
virtual int GetPointSize() const;
|
||||||
virtual wxFontStyle GetStyle() const;
|
virtual wxFontStyle GetStyle() const;
|
||||||
virtual wxFontWeight GetWeight() const;
|
virtual int GetNumericWeight() const;
|
||||||
virtual bool GetUnderlined() const;
|
virtual bool GetUnderlined() const;
|
||||||
virtual bool GetStrikethrough() const wxOVERRIDE;
|
virtual bool GetStrikethrough() const wxOVERRIDE;
|
||||||
virtual wxString GetFaceName() const;
|
virtual wxString GetFaceName() const;
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
virtual void SetPointSize(int pointSize);
|
virtual void SetPointSize(int pointSize);
|
||||||
virtual void SetFamily(wxFontFamily family);
|
virtual void SetFamily(wxFontFamily family);
|
||||||
virtual void SetStyle(wxFontStyle style);
|
virtual void SetStyle(wxFontStyle style);
|
||||||
virtual void SetWeight(wxFontWeight weight);
|
virtual void SetNumericWeight(int weight);
|
||||||
virtual bool SetFaceName(const wxString& faceName);
|
virtual bool SetFaceName(const wxString& faceName);
|
||||||
virtual void SetUnderlined(bool underlined);
|
virtual void SetUnderlined(bool underlined);
|
||||||
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
|
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
|
||||||
|
@ -52,6 +52,28 @@
|
|||||||
static const int wxDEFAULT_FONT_SIZE = 12;
|
static const int wxDEFAULT_FONT_SIZE = 12;
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper functions
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static wxFontWeight ParseWeightString(wxString s)
|
||||||
|
{
|
||||||
|
s.MakeUpper();
|
||||||
|
|
||||||
|
if (s == "THIN") return wxFONTWEIGHT_THIN;
|
||||||
|
if (s == "EXTRALIGHT" || s == "ULTRALIGHT") return wxFONTWEIGHT_EXTRALIGHT;
|
||||||
|
if (s == "LIGHT") return wxFONTWEIGHT_LIGHT;
|
||||||
|
if (s == "NORMAL") return wxFONTWEIGHT_NORMAL;
|
||||||
|
if (s == "MEDIUM") return wxFONTWEIGHT_MEDIUM;
|
||||||
|
if (s == "DEMIBOLD" || s == "SEMIBOLD") return wxFONTWEIGHT_SEMIBOLD;
|
||||||
|
if (s == "BOLD") return wxFONTWEIGHT_BOLD;
|
||||||
|
if (s == "EXTRABOLD" || s == "ULTRABOLD") return wxFONTWEIGHT_EXTRABOLD;
|
||||||
|
if (s == "BLACK" || s == "HEAVY") return wxFONTWEIGHT_HEAVY;
|
||||||
|
if (s == "EXTRAHEAVY") return wxFONTWEIGHT_EXTRAHEAVY;
|
||||||
|
|
||||||
|
return wxFONTWEIGHT_NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
#else
|
#else
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -119,7 +141,7 @@ public:
|
|||||||
void SetPointSize(int pointSize);
|
void SetPointSize(int pointSize);
|
||||||
void SetFamily(wxFontFamily family);
|
void SetFamily(wxFontFamily family);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetWeight(wxFontWeight weight);
|
void SetNumericWeight(int weight);
|
||||||
void SetUnderlined(bool underlined);
|
void SetUnderlined(bool underlined);
|
||||||
void SetStrikethrough(bool strikethrough);
|
void SetStrikethrough(bool strikethrough);
|
||||||
bool SetFaceName(const wxString& facename);
|
bool SetFaceName(const wxString& facename);
|
||||||
@ -146,7 +168,7 @@ protected:
|
|||||||
int m_pointSize;
|
int m_pointSize;
|
||||||
wxFontFamily m_family;
|
wxFontFamily m_family;
|
||||||
wxFontStyle m_style;
|
wxFontStyle m_style;
|
||||||
wxFontWeight m_weight;
|
int m_weight;
|
||||||
bool m_underlined;
|
bool m_underlined;
|
||||||
bool m_strikethrough;
|
bool m_strikethrough;
|
||||||
wxString m_faceName;
|
wxString m_faceName;
|
||||||
@ -223,7 +245,7 @@ void wxFontRefData::Init(int pointSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_nativeFontInfo.SetFaceName(m_faceName);
|
m_nativeFontInfo.SetFaceName(m_faceName);
|
||||||
m_nativeFontInfo.SetWeight((wxFontWeight)m_weight);
|
m_nativeFontInfo.SetNumericWeight(m_weight);
|
||||||
m_nativeFontInfo.SetStyle((wxFontStyle)m_style);
|
m_nativeFontInfo.SetStyle((wxFontStyle)m_style);
|
||||||
m_nativeFontInfo.SetUnderlined(underlined);
|
m_nativeFontInfo.SetUnderlined(underlined);
|
||||||
#endif // wxUSE_UNICODE
|
#endif // wxUSE_UNICODE
|
||||||
@ -255,56 +277,18 @@ void wxFontRefData::InitFromNative()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not defined in some Pango versions
|
m_weight = pango_font_description_get_weight( desc );
|
||||||
#define wxPANGO_WEIGHT_SEMIBOLD 600
|
|
||||||
|
|
||||||
switch (pango_font_description_get_weight( desc ))
|
|
||||||
{
|
|
||||||
case PANGO_WEIGHT_ULTRALIGHT:
|
|
||||||
case PANGO_WEIGHT_LIGHT:
|
|
||||||
m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG(wxT("unknown Pango font weight"));
|
|
||||||
// fall through
|
|
||||||
|
|
||||||
case PANGO_WEIGHT_NORMAL:
|
|
||||||
m_weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case wxPANGO_WEIGHT_SEMIBOLD:
|
|
||||||
case PANGO_WEIGHT_BOLD:
|
|
||||||
case PANGO_WEIGHT_ULTRABOLD:
|
|
||||||
case PANGO_WEIGHT_HEAVY:
|
|
||||||
m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // X11
|
#else // X11
|
||||||
// get the font parameters from the XLFD
|
// get the font parameters from the XLFD
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY);
|
m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY);
|
||||||
|
|
||||||
m_weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
|
|
||||||
wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper();
|
wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper();
|
||||||
if ( !w.empty() && w != wxT('*') )
|
if ( !w.empty() && w != wxT('*') )
|
||||||
{
|
m_weight = ParseWeightString(w);
|
||||||
// the test below catches all of BOLD, EXTRABOLD, DEMIBOLD, ULTRABOLD
|
else
|
||||||
// and BLACK
|
m_weight = wxFONTWEIGHT_NORMAL;
|
||||||
if ( ((w[0u] == wxT('B') && (!wxStrcmp(w.c_str() + 1, wxT("OLD")) ||
|
|
||||||
!wxStrcmp(w.c_str() + 1, wxT("LACK"))))) ||
|
|
||||||
wxStrstr(w.c_str() + 1, wxT("BOLD")) )
|
|
||||||
{
|
|
||||||
m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
}
|
|
||||||
else if ( w == wxT("LIGHT") || w == wxT("THIN") )
|
|
||||||
{
|
|
||||||
m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( wxToupper( m_nativeFontInfo.
|
switch ( wxToupper( m_nativeFontInfo.
|
||||||
GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() )
|
GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() )
|
||||||
@ -486,7 +470,7 @@ void wxFontRefData::SetStyle(wxFontStyle style)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::SetWeight(wxFontWeight weight)
|
void wxFontRefData::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
m_weight = weight;
|
m_weight = weight;
|
||||||
}
|
}
|
||||||
@ -594,15 +578,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
|
|||||||
|
|
||||||
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
|
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
|
||||||
|
|
||||||
tmp = tn.GetNextToken().MakeUpper(); // weight
|
M_FONTDATA->m_weight = ParseWeightString(tn.GetNextToken()); // weight
|
||||||
if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
|
|
||||||
if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
|
|
||||||
tmp = tn.GetNextToken().MakeUpper(); // slant
|
tmp = tn.GetNextToken().MakeUpper(); // slant
|
||||||
if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
|
if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
|
||||||
@ -742,7 +718,7 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->m_style;
|
return M_FONTDATA->m_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
||||||
|
|
||||||
@ -844,11 +820,11 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
M_FONTDATA->SetNumericWeight(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::SetFaceName(const wxString& faceName)
|
bool wxFont::SetFaceName(const wxString& faceName)
|
||||||
|
Loading…
Reference in New Issue
Block a user