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/gdicmn.h"
36 #include "wx/fontutil.h" // for wxNativeFontInfo
38 #include "wx/tokenzr.h"
40 // ============================================================================
42 // ============================================================================
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 wxFontEncoding
wxFontBase::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
51 wxFont
*wxFontBase::New(int size
,
57 wxFontEncoding encoding
)
59 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
63 wxFont
*wxFontBase::New(const wxNativeFontInfo
& info
)
65 return new wxFont(info
);
69 wxFont
*wxFontBase::New(const wxString
& strNativeFontDesc
)
71 wxNativeFontInfo fontInfo
;
72 if ( !fontInfo
.FromString(strNativeFontDesc
) )
73 return new wxFont(*wxNORMAL_FONT
);
78 wxNativeFontInfo
*wxFontBase::GetNativeFontInfo() const
80 #if !defined(__WXGTK__) && !defined(__WXMSW__)
81 wxNativeFontInfo
*fontInfo
= new wxNativeFontInfo
;
83 fontInfo
->pointSize
= GetPointSize();
84 fontInfo
->family
= GetFamily();
85 fontInfo
->style
= GetStyle();
86 fontInfo
->weight
= GetWeight();
87 fontInfo
->underlined
= GetUnderlined();
88 fontInfo
->faceName
= GetFaceName();
89 fontInfo
->encoding
= GetEncoding();
93 return (wxNativeFontInfo
*)NULL
;
97 void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo
& info
)
99 #if !defined(__WXGTK__) && !defined(__WXMSW__)
100 SetPointSize(info
.pointSize
);
101 SetFamily(info
.family
);
102 SetStyle(info
.style
);
103 SetWeight(info
.weight
);
104 SetUnderlined(info
.underlined
);
105 SetFaceName(info
.faceName
);
106 SetEncoding(info
.encoding
);
112 wxString
wxFontBase::GetNativeFontInfoDesc() const
115 wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
118 fontDesc
= fontInfo
->ToString();
125 void wxFontBase::SetNativeFontInfo(const wxString
& info
)
127 wxNativeFontInfo fontInfo
;
128 if ( !info
.empty() && fontInfo
.FromString(info
) )
130 SetNativeFontInfo(fontInfo
);
134 wxFont
& wxFont::operator=(const wxFont
& font
)
139 return (wxFont
&)*this;
142 bool wxFontBase::operator==(const wxFont
& font
) const
144 // either it is the same font, i.e. they share the same common data or they
145 // have different ref datas but still describe the same font
146 return GetFontData() == font
.GetFontData() ||
149 GetPointSize() == font
.GetPointSize() &&
150 GetFamily() == font
.GetFamily() &&
151 GetStyle() == font
.GetStyle() &&
152 GetWeight() == font
.GetWeight() &&
153 GetUnderlined() == font
.GetUnderlined() &&
154 GetFaceName() == font
.GetFaceName() &&
155 GetEncoding() == font
.GetEncoding()
159 bool wxFontBase::operator!=(const wxFont
& font
) const
161 return !(*this == font
);
164 wxString
wxFontBase::GetFamilyString() const
166 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
168 switch ( GetFamily() )
170 case wxDECORATIVE
: return wxT("wxDECORATIVE");
171 case wxROMAN
: return wxT("wxROMAN");
172 case wxSCRIPT
: return wxT("wxSCRIPT");
173 case wxSWISS
: return wxT("wxSWISS");
174 case wxMODERN
: return wxT("wxMODERN");
175 case wxTELETYPE
: return wxT("wxTELETYPE");
176 default: return wxT("wxDEFAULT");
180 wxString
wxFontBase::GetStyleString() const
182 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
184 switch ( GetStyle() )
186 case wxNORMAL
: return wxT("wxNORMAL");
187 case wxSLANT
: return wxT("wxSLANT");
188 case wxITALIC
: return wxT("wxITALIC");
189 default: return wxT("wxDEFAULT");
193 wxString
wxFontBase::GetWeightString() const
195 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
197 switch ( GetWeight() )
199 case wxNORMAL
: return wxT("wxNORMAL");
200 case wxBOLD
: return wxT("wxBOLD");
201 case wxLIGHT
: return wxT("wxLIGHT");
202 default: return wxT("wxDEFAULT");
206 #if !defined(__WXGTK__) && !defined(__WXMSW__)
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 // These are the generic forms of FromString()/ToString.
214 // convert to/from the string representation: format is
215 // version;pointsize;family;style;weight;underlined;facename;encoding
217 bool wxNativeFontInfo::FromString(const wxString
& s
)
221 wxStringTokenizer
tokenizer(s
, _T(";"));
223 wxString token
= tokenizer
.GetNextToken();
225 // Ignore the version for now
228 token
= tokenizer
.GetNextToken();
229 if ( !token
.ToLong(&l
) )
233 token
= tokenizer
.GetNextToken();
234 if ( !token
.ToLong(&l
) )
238 token
= tokenizer
.GetNextToken();
239 if ( !token
.ToLong(&l
) )
243 token
= tokenizer
.GetNextToken();
244 if ( !token
.ToLong(&l
) )
248 token
= tokenizer
.GetNextToken();
249 if ( !token
.ToLong(&l
) )
253 faceName
= tokenizer
.GetNextToken();
257 token
= tokenizer
.GetNextToken();
258 if ( !token
.ToLong(&l
) )
260 encoding
= (wxFontEncoding
)l
;
265 wxString
wxNativeFontInfo::ToString() const
269 s
.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
282 #endif // generic wxNativeFontInfo implementation