1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/fontcmn.cpp
3 // Purpose: implementation of wxFontBase methods
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/fontutil.h"
36 #include "wx/tokenzr.h"
38 // ============================================================================
40 // ============================================================================
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxFontEncoding
wxFontBase::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
49 wxFont
*wxFontBase::New(int size
,
55 wxFontEncoding encoding
)
57 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
61 wxFont
*wxFontBase::New(const wxNativeFontInfo
& info
)
63 return new wxFont(info
);
67 wxFont
*wxFontBase::New(const wxString
& strNativeFontDesc
)
69 wxNativeFontInfo fontInfo
;
70 if ( !fontInfo
.FromString(strNativeFontDesc
) )
71 return (wxFont
*)NULL
;
76 wxNativeFontInfo
*wxFontBase::GetNativeFontInfo() const
78 #if !defined(__WXGTK__)
79 wxNativeFontInfo
*fontInfo
= new wxNativeFontInfo
;
81 fontInfo
->pointSize
= GetPointSize();
82 fontInfo
->family
= GetFamily();
83 fontInfo
->style
= GetStyle();
84 fontInfo
->weight
= GetWeight();
85 fontInfo
->underlined
= GetUnderlined();
86 fontInfo
->faceName
= GetFaceName();
87 fontInfo
->encoding
= GetEncoding();
91 return (wxNativeFontInfo
*)NULL
;
95 void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo
& info
)
97 #if !defined(__WXGTK__)
98 SetPointSize(info
.pointSize
);
99 SetFamily(info
.family
);
100 SetStyle(info
.style
);
101 SetWeight(info
.weight
);
102 SetUnderlined(info
.underlined
);
103 SetFaceName(info
.faceName
);
104 SetEncoding(info
.encoding
);
108 wxString
wxFontBase::GetNativeFontInfoDesc() const
111 wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
114 fontDesc
= fontInfo
->ToString();
121 wxFont
& wxFont::operator=(const wxFont
& font
)
126 return (wxFont
&)*this;
129 // VZ: is it correct to compare pointers and not the contents? (FIXME)
130 bool wxFontBase::operator==(const wxFont
& font
) const
132 return GetFontData() == font
.GetFontData();
135 bool wxFontBase::operator!=(const wxFont
& font
) const
137 return GetFontData() != font
.GetFontData();
140 wxString
wxFontBase::GetFamilyString() const
142 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
144 switch ( GetFamily() )
146 case wxDECORATIVE
: return wxT("wxDECORATIVE");
147 case wxROMAN
: return wxT("wxROMAN");
148 case wxSCRIPT
: return wxT("wxSCRIPT");
149 case wxSWISS
: return wxT("wxSWISS");
150 case wxMODERN
: return wxT("wxMODERN");
151 case wxTELETYPE
: return wxT("wxTELETYPE");
152 default: return wxT("wxDEFAULT");
156 wxString
wxFontBase::GetStyleString() const
158 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
160 switch ( GetStyle() )
162 case wxNORMAL
: return wxT("wxNORMAL");
163 case wxSLANT
: return wxT("wxSLANT");
164 case wxITALIC
: return wxT("wxITALIC");
165 default: return wxT("wxDEFAULT");
169 wxString
wxFontBase::GetWeightString() const
171 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
173 switch ( GetWeight() )
175 case wxNORMAL
: return wxT("wxNORMAL");
176 case wxBOLD
: return wxT("wxBOLD");
177 case wxLIGHT
: return wxT("wxLIGHT");
178 default: return wxT("wxDEFAULT");
182 #if !defined(__WXGTK__)
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 // These are the generic forms of FromString()/ToString.
190 // convert to/from the string representation: format is
191 // pointsize;family;style;weight;underlined;facename;encoding
193 bool wxNativeFontInfo::FromString(const wxString
& s
)
197 wxStringTokenizer
tokenizer(s
, _T(";"));
199 wxString token
= tokenizer
.GetNextToken();
200 if ( !token
.ToLong(&l
) )
204 token
= tokenizer
.GetNextToken();
205 if ( !token
.ToLong(&l
) )
209 token
= tokenizer
.GetNextToken();
210 if ( !token
.ToLong(&l
) )
214 token
= tokenizer
.GetNextToken();
215 if ( !token
.ToLong(&l
) )
219 token
= tokenizer
.GetNextToken();
220 if ( !token
.ToLong(&l
) )
224 faceName
= tokenizer
.GetNextToken();
228 token
= tokenizer
.GetNextToken();
229 if ( !token
.ToLong(&l
) )
231 encoding
= (wxFontEncoding
)l
;
236 wxString
wxNativeFontInfo::ToString() const
240 s
.Printf(_T("%d;%d;%d;%d;%d;%s;%d"),
252 #endif // generic wxNativeFontInfo implementation