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
);
110 wxString
wxFontBase::GetNativeFontInfoDesc() const
113 wxNativeFontInfo
*fontInfo
= GetNativeFontInfo();
116 fontDesc
= fontInfo
->ToString();
123 wxFont
& wxFont::operator=(const wxFont
& font
)
128 return (wxFont
&)*this;
131 bool wxFontBase::operator==(const wxFont
& font
) const
133 // either it is the same font, i.e. they share the same common data or they
134 // have different ref datas but still describe the same font
135 return GetFontData() == font
.GetFontData() ||
138 GetPointSize() == font
.GetPointSize() &&
139 GetFamily() == font
.GetFamily() &&
140 GetStyle() == font
.GetStyle() &&
141 GetUnderlined() == font
.GetUnderlined() &&
142 GetFaceName() == font
.GetFaceName() &&
143 GetEncoding() == font
.GetEncoding()
147 bool wxFontBase::operator!=(const wxFont
& font
) const
149 return !(*this == font
);
152 wxString
wxFontBase::GetFamilyString() const
154 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
156 switch ( GetFamily() )
158 case wxDECORATIVE
: return wxT("wxDECORATIVE");
159 case wxROMAN
: return wxT("wxROMAN");
160 case wxSCRIPT
: return wxT("wxSCRIPT");
161 case wxSWISS
: return wxT("wxSWISS");
162 case wxMODERN
: return wxT("wxMODERN");
163 case wxTELETYPE
: return wxT("wxTELETYPE");
164 default: return wxT("wxDEFAULT");
168 wxString
wxFontBase::GetStyleString() const
170 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
172 switch ( GetStyle() )
174 case wxNORMAL
: return wxT("wxNORMAL");
175 case wxSLANT
: return wxT("wxSLANT");
176 case wxITALIC
: return wxT("wxITALIC");
177 default: return wxT("wxDEFAULT");
181 wxString
wxFontBase::GetWeightString() const
183 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
185 switch ( GetWeight() )
187 case wxNORMAL
: return wxT("wxNORMAL");
188 case wxBOLD
: return wxT("wxBOLD");
189 case wxLIGHT
: return wxT("wxLIGHT");
190 default: return wxT("wxDEFAULT");
194 #if !defined(__WXGTK__) && !defined(__WXMSW__)
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 // These are the generic forms of FromString()/ToString.
202 // convert to/from the string representation: format is
203 // version;pointsize;family;style;weight;underlined;facename;encoding
205 bool wxNativeFontInfo::FromString(const wxString
& s
)
209 wxStringTokenizer
tokenizer(s
, _T(";"));
211 wxString token
= tokenizer
.GetNextToken();
213 // Ignore the version for now
216 token
= tokenizer
.GetNextToken();
217 if ( !token
.ToLong(&l
) )
221 token
= tokenizer
.GetNextToken();
222 if ( !token
.ToLong(&l
) )
226 token
= tokenizer
.GetNextToken();
227 if ( !token
.ToLong(&l
) )
231 token
= tokenizer
.GetNextToken();
232 if ( !token
.ToLong(&l
) )
236 token
= tokenizer
.GetNextToken();
237 if ( !token
.ToLong(&l
) )
241 faceName
= tokenizer
.GetNextToken();
245 token
= tokenizer
.GetNextToken();
246 if ( !token
.ToLong(&l
) )
248 encoding
= (wxFontEncoding
)l
;
253 wxString
wxNativeFontInfo::ToString() const
257 s
.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
270 #endif // generic wxNativeFontInfo implementation