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"
35 #include "wx/fontutil.h" // for wxNativeFontInfo
37 #include "wx/tokenzr.h"
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxFontEncoding
wxFontBase::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
50 wxFont
*wxFontBase::New(int size
,
56 wxFontEncoding encoding
)
58 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
62 wxFont
*wxFontBase::New(const wxNativeFontInfo
& info
)
64 return new wxFont(info
);
68 wxFont
*wxFontBase::New(const wxString
& strNativeFontDesc
)
70 wxNativeFontInfo fontInfo
;
71 if ( !fontInfo
.FromString(strNativeFontDesc
) )
72 return (wxFont
*)NULL
;
77 wxNativeFontInfo
*wxFontBase::GetNativeFontInfo() const
79 #if !defined(__WXGTK__)
80 wxNativeFontInfo
*fontInfo
= new wxNativeFontInfo
;
82 fontInfo
->pointSize
= GetPointSize();
83 fontInfo
->family
= GetFamily();
84 fontInfo
->style
= GetStyle();
85 fontInfo
->weight
= GetWeight();
86 fontInfo
->underlined
= GetUnderlined();
87 fontInfo
->faceName
= GetFaceName();
88 fontInfo
->encoding
= GetEncoding();
92 return (wxNativeFontInfo
*)NULL
;
96 void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo
& info
)
98 #if !defined(__WXGTK__)
99 SetPointSize(info
.pointSize
);
100 SetFamily(info
.family
);
101 SetStyle(info
.style
);
102 SetWeight(info
.weight
);
103 SetUnderlined(info
.underlined
);
104 SetFaceName(info
.faceName
);
105 SetEncoding(info
.encoding
);
109 wxString
wxFontBase::GetNativeFontInfoDesc() const
112 wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
115 fontDesc
= fontInfo
->ToString();
122 wxFont
& wxFont::operator=(const wxFont
& font
)
127 return (wxFont
&)*this;
130 // VZ: is it correct to compare pointers and not the contents? (FIXME)
131 bool wxFontBase::operator==(const wxFont
& font
) const
133 return GetFontData() == font
.GetFontData();
136 bool wxFontBase::operator!=(const wxFont
& font
) const
138 return GetFontData() != font
.GetFontData();
141 wxString
wxFontBase::GetFamilyString() const
143 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
145 switch ( GetFamily() )
147 case wxDECORATIVE
: return wxT("wxDECORATIVE");
148 case wxROMAN
: return wxT("wxROMAN");
149 case wxSCRIPT
: return wxT("wxSCRIPT");
150 case wxSWISS
: return wxT("wxSWISS");
151 case wxMODERN
: return wxT("wxMODERN");
152 case wxTELETYPE
: return wxT("wxTELETYPE");
153 default: return wxT("wxDEFAULT");
157 wxString
wxFontBase::GetStyleString() const
159 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
161 switch ( GetStyle() )
163 case wxNORMAL
: return wxT("wxNORMAL");
164 case wxSLANT
: return wxT("wxSLANT");
165 case wxITALIC
: return wxT("wxITALIC");
166 default: return wxT("wxDEFAULT");
170 wxString
wxFontBase::GetWeightString() const
172 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
174 switch ( GetWeight() )
176 case wxNORMAL
: return wxT("wxNORMAL");
177 case wxBOLD
: return wxT("wxBOLD");
178 case wxLIGHT
: return wxT("wxLIGHT");
179 default: return wxT("wxDEFAULT");
183 #if !defined(__WXGTK__)
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 // These are the generic forms of FromString()/ToString.
191 // convert to/from the string representation: format is
192 // pointsize;family;style;weight;underlined;facename;encoding
194 bool wxNativeFontInfo::FromString(const wxString
& s
)
198 wxStringTokenizer
tokenizer(s
, _T(";"));
200 wxString token
= tokenizer
.GetNextToken();
201 if ( !token
.ToLong(&l
) )
205 token
= tokenizer
.GetNextToken();
206 if ( !token
.ToLong(&l
) )
210 token
= tokenizer
.GetNextToken();
211 if ( !token
.ToLong(&l
) )
215 token
= tokenizer
.GetNextToken();
216 if ( !token
.ToLong(&l
) )
220 token
= tokenizer
.GetNextToken();
221 if ( !token
.ToLong(&l
) )
225 faceName
= tokenizer
.GetNextToken();
229 token
= tokenizer
.GetNextToken();
230 if ( !token
.ToLong(&l
) )
232 encoding
= (wxFontEncoding
)l
;
237 wxString
wxNativeFontInfo::ToString() const
241 s
.Printf(_T("%d;%d;%d;%d;%d;%s;%d"),
253 #endif // generic wxNativeFontInfo implementation