]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: common/fontcmn.cpp | |
3 | // Purpose: implementation of wxFontBase methods | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 20.09.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWindows team | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "fontbase.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/font.h" | |
33 | #endif // WX_PRECOMP | |
34 | ||
35 | #include "wx/fontutil.h" // for wxNativeFontInfo | |
36 | ||
37 | #include "wx/tokenzr.h" | |
38 | ||
39 | // ============================================================================ | |
40 | // implementation | |
41 | // ============================================================================ | |
42 | ||
43 | // ---------------------------------------------------------------------------- | |
44 | // wxFontBase | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
47 | wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM; | |
48 | ||
49 | /* static */ | |
50 | wxFont *wxFontBase::New(int size, | |
51 | int family, | |
52 | int style, | |
53 | int weight, | |
54 | bool underlined, | |
55 | const wxString& face, | |
56 | wxFontEncoding encoding) | |
57 | { | |
58 | return new wxFont(size, family, style, weight, underlined, face, encoding); | |
59 | } | |
60 | ||
61 | /* static */ | |
62 | wxFont *wxFontBase::New(const wxNativeFontInfo& info) | |
63 | { | |
64 | return new wxFont(info); | |
65 | } | |
66 | ||
67 | /* static */ | |
68 | wxFont *wxFontBase::New(const wxString& strNativeFontDesc) | |
69 | { | |
70 | wxNativeFontInfo fontInfo; | |
71 | if ( !fontInfo.FromString(strNativeFontDesc) ) | |
72 | return (wxFont *)NULL; | |
73 | ||
74 | return New(fontInfo); | |
75 | } | |
76 | ||
77 | wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const | |
78 | { | |
79 | #if !defined(__WXGTK__) | |
80 | wxNativeFontInfo *fontInfo = new wxNativeFontInfo; | |
81 | ||
82 | fontInfo->pointSize = GetPointSize(); | |
83 | fontInfo->family = GetFamily(); | |
84 | fontInfo->style = GetStyle(); | |
85 | fontInfo->weight = GetWeight(); | |
86 | fontInfo->underlined = GetUnderlined(); | |
87 | fontInfo->faceName = GetFaceName(); | |
88 | fontInfo->encoding = GetEncoding(); | |
89 | ||
90 | return fontInfo; | |
91 | #else | |
92 | return (wxNativeFontInfo *)NULL; | |
93 | #endif | |
94 | } | |
95 | ||
96 | void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info) | |
97 | { | |
98 | #if !defined(__WXGTK__) | |
99 | SetPointSize(info.pointSize); | |
100 | SetFamily(info.family); | |
101 | SetStyle(info.style); | |
102 | SetWeight(info.weight); | |
103 | SetUnderlined(info.underlined); | |
104 | SetFaceName(info.faceName); | |
105 | SetEncoding(info.encoding); | |
106 | #endif | |
107 | } | |
108 | ||
109 | wxString wxFontBase::GetNativeFontInfoDesc() const | |
110 | { | |
111 | wxString fontDesc; | |
112 | wxNativeFontInfo *fontInfo = GetNativeFontInfo(); | |
113 | if ( fontInfo ) | |
114 | { | |
115 | fontDesc = fontInfo->ToString(); | |
116 | delete fontInfo; | |
117 | } | |
118 | ||
119 | return fontDesc; | |
120 | } | |
121 | ||
122 | wxFont& wxFont::operator=(const wxFont& font) | |
123 | { | |
124 | if ( this != &font ) | |
125 | Ref(font); | |
126 | ||
127 | return (wxFont &)*this; | |
128 | } | |
129 | ||
130 | // VZ: is it correct to compare pointers and not the contents? (FIXME) | |
131 | bool wxFontBase::operator==(const wxFont& font) const | |
132 | { | |
133 | return GetFontData() == font.GetFontData(); | |
134 | } | |
135 | ||
136 | bool wxFontBase::operator!=(const wxFont& font) const | |
137 | { | |
138 | return GetFontData() != font.GetFontData(); | |
139 | } | |
140 | ||
141 | wxString wxFontBase::GetFamilyString() const | |
142 | { | |
143 | wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); | |
144 | ||
145 | switch ( GetFamily() ) | |
146 | { | |
147 | case wxDECORATIVE: return wxT("wxDECORATIVE"); | |
148 | case wxROMAN: return wxT("wxROMAN"); | |
149 | case wxSCRIPT: return wxT("wxSCRIPT"); | |
150 | case wxSWISS: return wxT("wxSWISS"); | |
151 | case wxMODERN: return wxT("wxMODERN"); | |
152 | case wxTELETYPE: return wxT("wxTELETYPE"); | |
153 | default: return wxT("wxDEFAULT"); | |
154 | } | |
155 | } | |
156 | ||
157 | wxString wxFontBase::GetStyleString() const | |
158 | { | |
159 | wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); | |
160 | ||
161 | switch ( GetStyle() ) | |
162 | { | |
163 | case wxNORMAL: return wxT("wxNORMAL"); | |
164 | case wxSLANT: return wxT("wxSLANT"); | |
165 | case wxITALIC: return wxT("wxITALIC"); | |
166 | default: return wxT("wxDEFAULT"); | |
167 | } | |
168 | } | |
169 | ||
170 | wxString wxFontBase::GetWeightString() const | |
171 | { | |
172 | wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); | |
173 | ||
174 | switch ( GetWeight() ) | |
175 | { | |
176 | case wxNORMAL: return wxT("wxNORMAL"); | |
177 | case wxBOLD: return wxT("wxBOLD"); | |
178 | case wxLIGHT: return wxT("wxLIGHT"); | |
179 | default: return wxT("wxDEFAULT"); | |
180 | } | |
181 | } | |
182 | ||
183 | #if !defined(__WXGTK__) | |
184 | ||
185 | // ---------------------------------------------------------------------------- | |
186 | // wxNativeFontInfo | |
187 | // ---------------------------------------------------------------------------- | |
188 | ||
189 | // These are the generic forms of FromString()/ToString. | |
190 | // | |
191 | // convert to/from the string representation: format is | |
192 | // pointsize;family;style;weight;underlined;facename;encoding | |
193 | ||
194 | bool wxNativeFontInfo::FromString(const wxString& s) | |
195 | { | |
196 | long l; | |
197 | ||
198 | wxStringTokenizer tokenizer(s, _T(";")); | |
199 | ||
200 | wxString token = tokenizer.GetNextToken(); | |
201 | if ( !token.ToLong(&l) ) | |
202 | return FALSE; | |
203 | pointSize = (int)l; | |
204 | ||
205 | token = tokenizer.GetNextToken(); | |
206 | if ( !token.ToLong(&l) ) | |
207 | return FALSE; | |
208 | family = (int)l; | |
209 | ||
210 | token = tokenizer.GetNextToken(); | |
211 | if ( !token.ToLong(&l) ) | |
212 | return FALSE; | |
213 | style = (int)l; | |
214 | ||
215 | token = tokenizer.GetNextToken(); | |
216 | if ( !token.ToLong(&l) ) | |
217 | return FALSE; | |
218 | weight = (int)l; | |
219 | ||
220 | token = tokenizer.GetNextToken(); | |
221 | if ( !token.ToLong(&l) ) | |
222 | return FALSE; | |
223 | underlined = l != 0; | |
224 | ||
225 | faceName = tokenizer.GetNextToken(); | |
226 | if( !faceName ) | |
227 | return FALSE; | |
228 | ||
229 | token = tokenizer.GetNextToken(); | |
230 | if ( !token.ToLong(&l) ) | |
231 | return FALSE; | |
232 | encoding = (wxFontEncoding)l; | |
233 | ||
234 | return TRUE; | |
235 | } | |
236 | ||
237 | wxString wxNativeFontInfo::ToString() const | |
238 | { | |
239 | wxString s; | |
240 | ||
241 | s.Printf(_T("%d;%d;%d;%d;%d;%s;%d"), | |
242 | pointSize, | |
243 | family, | |
244 | style, | |
245 | weight, | |
246 | underlined, | |
247 | faceName.GetData(), | |
248 | (int)encoding); | |
249 | ||
250 | return s; | |
251 | } | |
252 | ||
253 | #endif // generic wxNativeFontInfo implementation | |
254 |