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/tokenzr.h"
37 // ============================================================================
39 // ============================================================================
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 wxFontEncoding
wxFontBase::ms_encodingDefault
= wxFONTENCODING_SYSTEM
;
48 wxFont
*wxFontBase::New(int size
,
54 wxFontEncoding encoding
)
56 return new wxFont(size
, family
, style
, weight
, underlined
, face
, encoding
);
60 wxFont
*wxFontBase::New(const wxNativeFontInfo
& info
)
62 return new wxFont(info
);
65 wxNativeFontInfo
wxFontBase::GetNativeFontInfo() const
67 #if !defined(__WXGTK__)
68 wxNativeFontInfo fontInfo
;
70 fontInfo
.pointSize
= GetPointSize();
71 fontInfo
.family
= GetFamily();
72 fontInfo
.style
= GetStyle();
73 fontInfo
.weight
= GetWeight();
74 fontInfo
.underlined
= GetUnderlined();
75 fontInfo
.faceName
= GetFaceName();
76 fontInfo
.encoding
= GetEncoding();
80 return wxNullNativeFontInfo
;
84 void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo
& info
)
86 #if !defined(__WXGTK__)
87 SetPointSize(info
.pointSize
);
88 SetFamily(info
.family
);
90 SetWeight(info
.weight
);
91 SetUnderlined(info
.underlined
);
92 SetFaceName(info
.faceName
);
93 SetEncoding(info
.encoding
);
97 wxFont
& wxFont::operator=(const wxFont
& font
)
102 return (wxFont
&)*this;
105 // VZ: is it correct to compare pointers and not the contents? (FIXME)
106 bool wxFontBase::operator==(const wxFont
& font
) const
108 return GetFontData() == font
.GetFontData();
111 bool wxFontBase::operator!=(const wxFont
& font
) const
113 return GetFontData() != font
.GetFontData();
116 wxString
wxFontBase::GetFamilyString() const
118 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
120 switch ( GetFamily() )
122 case wxDECORATIVE
: return wxT("wxDECORATIVE");
123 case wxROMAN
: return wxT("wxROMAN");
124 case wxSCRIPT
: return wxT("wxSCRIPT");
125 case wxSWISS
: return wxT("wxSWISS");
126 case wxMODERN
: return wxT("wxMODERN");
127 case wxTELETYPE
: return wxT("wxTELETYPE");
128 default: return wxT("wxDEFAULT");
132 wxString
wxFontBase::GetStyleString() const
134 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
136 switch ( GetStyle() )
138 case wxNORMAL
: return wxT("wxNORMAL");
139 case wxSLANT
: return wxT("wxSLANT");
140 case wxITALIC
: return wxT("wxITALIC");
141 default: return wxT("wxDEFAULT");
145 wxString
wxFontBase::GetWeightString() const
147 wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") );
149 switch ( GetWeight() )
151 case wxNORMAL
: return wxT("wxNORMAL");
152 case wxBOLD
: return wxT("wxBOLD");
153 case wxLIGHT
: return wxT("wxLIGHT");
154 default: return wxT("wxDEFAULT");
158 #if !defined(__WXGTK__)
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 // These are the generic forms of FromString()/ToString.
166 // convert to/from the string representation: format is
167 // pointsize;family;style;weight;underlined;facename;encoding
169 bool wxNativeFontInfo::FromString(const wxString
& s
)
173 wxStringTokenizer
tokenizer(s
, _T(";"));
175 wxString token
= tokenizer
.GetNextToken();
176 if ( !token
.ToLong(&l
) )
180 token
= tokenizer
.GetNextToken();
181 if ( !token
.ToLong(&l
) )
185 token
= tokenizer
.GetNextToken();
186 if ( !token
.ToLong(&l
) )
190 token
= tokenizer
.GetNextToken();
191 if ( !token
.ToLong(&l
) )
195 token
= tokenizer
.GetNextToken();
196 if ( !token
.ToLong(&l
) )
200 faceName
= tokenizer
.GetNextToken();
204 token
= tokenizer
.GetNextToken();
205 if ( !token
.ToLong(&l
) )
207 encoding
= (wxFontEncoding
)l
;
212 wxString
wxNativeFontInfo::ToString() const
216 s
.Printf("%d;%d;%d;%d;%d;%s;%d",