+ wxCHECK_MSG( IsOk(), "wxFONTWEIGHT_DEFAULT", "invalid font" );
+
+ switch ( GetWeight() )
+ {
+ case wxFONTWEIGHT_NORMAL: return "wxFONTWEIGHT_NORMAL";
+ case wxFONTWEIGHT_BOLD: return "wxFONTWEIGHT_BOLD";
+ case wxFONTWEIGHT_LIGHT: return "wxFONTWEIGHT_LIGHT";
+ default: return "wxFONTWEIGHT_DEFAULT";
+ }
+}
+
+bool wxFontBase::SetFaceName(const wxString& facename)
+{
+#if wxUSE_FONTENUM
+ if (!wxFontEnumerator::IsValidFacename(facename))
+ {
+ UnRef(); // make IsOk() return false
+ return false;
+ }
+#else // !wxUSE_FONTENUM
+ wxUnusedVar(facename);
+#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
+
+ return true;
+}
+
+void wxFontBase::SetSymbolicSize(wxFontSymbolicSize size)
+{
+ SetSymbolicSizeRelativeTo(size, wxNORMAL_FONT->GetPointSize());
+}
+
+/* static */
+int wxFontBase::AdjustToSymbolicSize(wxFontSymbolicSize size, int base)
+{
+ // Using a fixed factor (1.2, from CSS2) is a bad idea as explained at
+ // http://www.w3.org/TR/CSS21/fonts.html#font-size-props so use the values
+ // from http://style.cleverchimp.com/font_size_intervals/altintervals.html
+ // instead.
+ static const float factors[] = { 0.60f, 0.75f, 0.89f, 1.f, 1.2f, 1.5f, 2.f };
+
+ wxCOMPILE_TIME_ASSERT
+ (
+ WXSIZEOF(factors) == wxFONTSIZE_XX_LARGE - wxFONTSIZE_XX_SMALL + 1,
+ WrongFontSizeFactorsSize
+ );
+
+ return wxRound(factors[size - wxFONTSIZE_XX_SMALL]*base);
+}
+
+wxFont& wxFont::MakeBold()
+{
+ SetWeight(wxFONTWEIGHT_BOLD);
+ return *this;
+}
+
+wxFont wxFont::Bold() const
+{
+ wxFont font(*this);
+ font.MakeBold();
+ return font;
+}
+
+wxFont& wxFont::MakeItalic()
+{
+ SetStyle(wxFONTSTYLE_ITALIC);
+ return *this;
+}
+
+wxFont wxFont::Italic() const
+{
+ wxFont font(*this);
+ font.MakeItalic();
+ return font;
+}
+
+wxFont& wxFont::MakeUnderlined()
+{
+ SetUnderlined(true);
+ return *this;
+}
+
+wxFont wxFont::Underlined() const
+{
+ wxFont font(*this);
+ font.MakeUnderlined();
+ return font;
+}
+
+wxFont wxFont::Strikethrough() const
+{
+ wxFont font(*this);
+ font.MakeStrikethrough();
+ return font;
+}
+
+wxFont& wxFont::MakeStrikethrough()
+{
+ SetStrikethrough(true);
+ return *this;
+}
+
+wxFont& wxFont::Scale(float x)
+{
+ SetPointSize(int(x*GetPointSize() + 0.5));
+ return *this;
+}
+
+wxFont wxFont::Scaled(float x) const
+{
+ wxFont font(*this);
+ font.Scale(x);
+ return font;
+}
+
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+// Up to now, there are no native implementations of this function:
+void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames)
+{
+#if wxUSE_FONTENUM
+ for (size_t i=0; i < facenames.GetCount(); i++)
+ {
+ if (wxFontEnumerator::IsValidFacename(facenames[i]))
+ {
+ SetFaceName(facenames[i]);
+ return;
+ }
+ }
+
+ // set the first valid facename we can find on this system
+ wxString validfacename = wxFontEnumerator::GetFacenames().Item(0);
+ wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename.c_str());
+ SetFaceName(validfacename);
+#else // !wxUSE_FONTENUM
+ SetFaceName(facenames[0]);
+#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
+}
+
+
+#ifdef wxNO_NATIVE_FONTINFO
+
+// These are the generic forms of FromString()/ToString.
+//
+// convert to/from the string representation: the general format is
+// "version;the rest..." with currently defined versions being:
+//
+// 0;pointsize;family;style;weight;underlined;facename;encoding
+// 1;pointsize;family;style;weight;underlined;strikethrough;facename;encoding
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+ long l;
+ unsigned long version;
+
+ wxStringTokenizer tokenizer(s, wxT(";"));
+
+ wxString token = tokenizer.GetNextToken();
+ if ( !token.ToULong(&version) || version > 1 )
+ return false;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ pointSize = (int)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ family = (wxFontFamily)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ style = (wxFontStyle)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ weight = (wxFontWeight)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ underlined = l != 0;
+
+ if ( version == 1 )
+ {
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ strikethrough = l != 0;
+ }
+
+ faceName = tokenizer.GetNextToken();
+
+#ifndef __WXMAC__
+ if( !faceName )
+ return false;
+#endif
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ encoding = (wxFontEncoding)l;
+
+ return true;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+ wxString s;
+
+ s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
+ 1, // version
+ pointSize,
+ family,
+ (int)style,
+ (int)weight,
+ underlined,
+ strikethrough,
+ faceName.GetData(),
+ (int)encoding);
+
+ return s;
+}
+
+void wxNativeFontInfo::Init()
+{
+ pointSize = 0;
+ family = wxFONTFAMILY_DEFAULT;
+ style = wxFONTSTYLE_NORMAL;
+ weight = wxFONTWEIGHT_NORMAL;
+ underlined = false;
+ strikethrough = false;
+ faceName.clear();
+ encoding = wxFONTENCODING_DEFAULT;
+}
+
+int wxNativeFontInfo::GetPointSize() const
+{
+ return pointSize;
+}
+
+wxFontStyle wxNativeFontInfo::GetStyle() const
+{
+ return style;
+}
+
+wxFontWeight wxNativeFontInfo::GetWeight() const
+{
+ return weight;
+}
+
+bool wxNativeFontInfo::GetUnderlined() const
+{
+ return underlined;
+}
+
+bool wxNativeFontInfo::GetStrikethrough() const
+{
+ return strikethrough;
+}
+
+wxString wxNativeFontInfo::GetFaceName() const
+{
+ return faceName;
+}
+
+wxFontFamily wxNativeFontInfo::GetFamily() const
+{
+ return family;
+}
+
+wxFontEncoding wxNativeFontInfo::GetEncoding() const
+{
+ return encoding;
+}
+
+void wxNativeFontInfo::SetPointSize(int pointsize)
+{
+ pointSize = pointsize;
+}
+
+void wxNativeFontInfo::SetStyle(wxFontStyle style_)
+{
+ style = style_;
+}
+
+void wxNativeFontInfo::SetWeight(wxFontWeight weight_)
+{
+ weight = weight_;
+}
+
+void wxNativeFontInfo::SetUnderlined(bool underlined_)
+{
+ underlined = underlined_;
+}
+
+void wxNativeFontInfo::SetStrikethrough(bool strikethrough_)
+{
+ strikethrough = strikethrough_;
+}
+
+bool wxNativeFontInfo::SetFaceName(const wxString& facename_)
+{
+ faceName = facename_;
+ return true;
+}
+
+void wxNativeFontInfo::SetFamily(wxFontFamily family_)
+{
+ family = family_;
+}
+
+void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_)
+{
+ encoding = encoding_;
+}
+
+#endif // generic wxNativeFontInfo implementation
+
+// conversion to/from user-readable string: this is used in the generic
+// versions and under MSW as well because there is no standard font description
+// format there anyhow (but there is a well-defined standard for X11 fonts used
+// by wxGTK and wxMotif)
+
+#if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__)
+
+wxString wxNativeFontInfo::ToUserString() const
+{
+ wxString desc;
+
+ // first put the adjectives, if any - this is English-centric, of course,
+ // but what else can we do?
+ if ( GetUnderlined() )
+ {
+ desc << _("underlined");
+ }
+
+ if ( GetStrikethrough() )
+ {
+ desc << _("strikethrough");
+ }