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 // VZ: is it correct to compare pointers and not the contents? (FIXME)
132 bool wxFontBase::operator==(const wxFont
& font
) const
134 return GetFontData() == font
.GetFontData();
137 bool wxFontBase::operator!=(const wxFont
& font
) const
139 return GetFontData() != font
.GetFontData();
142 wxString
wxFontBase::GetFamilyString() const
144 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
146 switch ( GetFamily() )
148 case wxDECORATIVE
: return wxT("wxDECORATIVE");
149 case wxROMAN
: return wxT("wxROMAN");
150 case wxSCRIPT
: return wxT("wxSCRIPT");
151 case wxSWISS
: return wxT("wxSWISS");
152 case wxMODERN
: return wxT("wxMODERN");
153 case wxTELETYPE
: return wxT("wxTELETYPE");
154 default: return wxT("wxDEFAULT");
158 wxString
wxFontBase::GetStyleString() const
160 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
162 switch ( GetStyle() )
164 case wxNORMAL
: return wxT("wxNORMAL");
165 case wxSLANT
: return wxT("wxSLANT");
166 case wxITALIC
: return wxT("wxITALIC");
167 default: return wxT("wxDEFAULT");
171 wxString
wxFontBase::GetWeightString() const
173 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
175 switch ( GetWeight() )
177 case wxNORMAL
: return wxT("wxNORMAL");
178 case wxBOLD
: return wxT("wxBOLD");
179 case wxLIGHT
: return wxT("wxLIGHT");
180 default: return wxT("wxDEFAULT");
184 #if !defined(__WXGTK__) && !defined(__WXMSW__)
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 // These are the generic forms of FromString()/ToString.
192 // convert to/from the string representation: format is
193 // version;pointsize;family;style;weight;underlined;facename;encoding
195 bool wxNativeFontInfo::FromString(const wxString
& s
)
199 wxStringTokenizer
tokenizer(s
, _T(";"));
201 wxString token
= tokenizer
.GetNextToken();
203 // Ignore the version for now
206 token
= tokenizer
.GetNextToken();
207 if ( !token
.ToLong(&l
) )
211 token
= tokenizer
.GetNextToken();
212 if ( !token
.ToLong(&l
) )
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 faceName
= tokenizer
.GetNextToken();
235 token
= tokenizer
.GetNextToken();
236 if ( !token
.ToLong(&l
) )
238 encoding
= (wxFontEncoding
)l
;
243 wxString
wxNativeFontInfo::ToString() const
247 s
.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"),
260 #endif // generic wxNativeFontInfo implementation