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__) && !defined(__WXMGL__)
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__) && !defined(__WXMGL__)
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 GetUnderlined() == font
.GetUnderlined() &&
144 GetFaceName() == font
.GetFaceName() &&
145 GetEncoding() == font
.GetEncoding()
149 bool wxFontBase::operator!=(const wxFont
& font
) const
151 return !(*this == font
);
154 wxString
wxFontBase::GetFamilyString() const
156 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
158 switch ( GetFamily() )
160 case wxDECORATIVE
: return wxT("wxDECORATIVE");
161 case wxROMAN
: return wxT("wxROMAN");
162 case wxSCRIPT
: return wxT("wxSCRIPT");
163 case wxSWISS
: return wxT("wxSWISS");
164 case wxMODERN
: return wxT("wxMODERN");
165 case wxTELETYPE
: return wxT("wxTELETYPE");
166 default: return wxT("wxDEFAULT");
170 wxString
wxFontBase::GetStyleString() const
172 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
174 switch ( GetStyle() )
176 case wxNORMAL
: return wxT("wxNORMAL");
177 case wxSLANT
: return wxT("wxSLANT");
178 case wxITALIC
: return wxT("wxITALIC");
179 default: return wxT("wxDEFAULT");
183 wxString
wxFontBase::GetWeightString() const
185 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
187 switch ( GetWeight() )
189 case wxNORMAL
: return wxT("wxNORMAL");
190 case wxBOLD
: return wxT("wxBOLD");
191 case wxLIGHT
: return wxT("wxLIGHT");
192 default: return wxT("wxDEFAULT");
196 #if !defined(__WXGTK__) && !defined(__WXMSW__) && !defined(__WXMGL__)
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 // These are the generic forms of FromString()/ToString.
204 // convert to/from the string representation: format is
205 // version;pointsize;family;style;weight;underlined;facename;encoding
207 bool wxNativeFontInfo::FromString(const wxString
& s
)
211 wxStringTokenizer
tokenizer(s
, _T(";"));
213 wxString token
= tokenizer
.GetNextToken();
215 // Ignore the version for now
218 token
= tokenizer
.GetNextToken();
219 if ( !token
.ToLong(&l
) )
223 token
= tokenizer
.GetNextToken();
224 if ( !token
.ToLong(&l
) )
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 faceName
= tokenizer
.GetNextToken();
247 token
= tokenizer
.GetNextToken();
248 if ( !token
.ToLong(&l
) )
250 encoding
= (wxFontEncoding
)l
;
255 wxString
wxNativeFontInfo::ToString() const
259 s
.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
272 #endif // generic wxNativeFontInfo implementation