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 wxFont
& wxFont::operator=(const wxFont
& font
)
130 return (wxFont
&)*this;
133 bool wxFontBase::operator==(const wxFont
& font
) const
135 // either it is the same font, i.e. they share the same common data or they
136 // have different ref datas but still describe the same font
137 return GetFontData() == font
.GetFontData() ||
140 GetPointSize() == font
.GetPointSize() &&
141 GetFamily() == font
.GetFamily() &&
142 GetStyle() == font
.GetStyle() &&
143 GetWeight() == font
.GetWeight() &&
144 GetUnderlined() == font
.GetUnderlined() &&
145 GetFaceName() == font
.GetFaceName() &&
146 GetEncoding() == font
.GetEncoding()
150 bool wxFontBase::operator!=(const wxFont
& font
) const
152 return !(*this == font
);
155 wxString
wxFontBase::GetFamilyString() const
157 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
159 switch ( GetFamily() )
161 case wxDECORATIVE
: return wxT("wxDECORATIVE");
162 case wxROMAN
: return wxT("wxROMAN");
163 case wxSCRIPT
: return wxT("wxSCRIPT");
164 case wxSWISS
: return wxT("wxSWISS");
165 case wxMODERN
: return wxT("wxMODERN");
166 case wxTELETYPE
: return wxT("wxTELETYPE");
167 default: return wxT("wxDEFAULT");
171 wxString
wxFontBase::GetStyleString() const
173 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
175 switch ( GetStyle() )
177 case wxNORMAL
: return wxT("wxNORMAL");
178 case wxSLANT
: return wxT("wxSLANT");
179 case wxITALIC
: return wxT("wxITALIC");
180 default: return wxT("wxDEFAULT");
184 wxString
wxFontBase::GetWeightString() const
186 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
188 switch ( GetWeight() )
190 case wxNORMAL
: return wxT("wxNORMAL");
191 case wxBOLD
: return wxT("wxBOLD");
192 case wxLIGHT
: return wxT("wxLIGHT");
193 default: return wxT("wxDEFAULT");
197 #if !defined(__WXGTK__) && !defined(__WXMSW__)
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 // These are the generic forms of FromString()/ToString.
205 // convert to/from the string representation: format is
206 // version;pointsize;family;style;weight;underlined;facename;encoding
208 bool wxNativeFontInfo::FromString(const wxString
& s
)
212 wxStringTokenizer
tokenizer(s
, _T(";"));
214 wxString token
= tokenizer
.GetNextToken();
216 // Ignore the version for now
219 token
= tokenizer
.GetNextToken();
220 if ( !token
.ToLong(&l
) )
224 token
= tokenizer
.GetNextToken();
225 if ( !token
.ToLong(&l
) )
229 token
= tokenizer
.GetNextToken();
230 if ( !token
.ToLong(&l
) )
234 token
= tokenizer
.GetNextToken();
235 if ( !token
.ToLong(&l
) )
239 token
= tokenizer
.GetNextToken();
240 if ( !token
.ToLong(&l
) )
244 faceName
= tokenizer
.GetNextToken();
248 token
= tokenizer
.GetNextToken();
249 if ( !token
.ToLong(&l
) )
251 encoding
= (wxFontEncoding
)l
;
256 wxString
wxNativeFontInfo::ToString() const
260 s
.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
273 #endif // generic wxNativeFontInfo implementation