]>
Commit | Line | Data |
---|---|---|
0c5d3e1c VZ |
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 | ||
1b68e0b5 RR |
20 | #ifdef __GNUG__ |
21 | #pragma implementation "fontbase.h" | |
22 | #endif | |
23 | ||
0c5d3e1c VZ |
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 | ||
09fcd889 | 35 | #include "wx/gdicmn.h" |
76e23cdb VZ |
36 | #include "wx/fontutil.h" // for wxNativeFontInfo |
37 | ||
30764ab5 VZ |
38 | #include "wx/tokenzr.h" |
39 | ||
0c5d3e1c VZ |
40 | // ============================================================================ |
41 | // implementation | |
42 | // ============================================================================ | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // wxFontBase | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | wxFontEncoding wxFontBase::ms_encodingDefault = wxFONTENCODING_SYSTEM; | |
49 | ||
7beba2fc | 50 | /* static */ |
0c5d3e1c VZ |
51 | wxFont *wxFontBase::New(int size, |
52 | int family, | |
53 | int style, | |
54 | int weight, | |
55 | bool underlined, | |
56 | const wxString& face, | |
57 | wxFontEncoding encoding) | |
58 | { | |
59 | return new wxFont(size, family, style, weight, underlined, face, encoding); | |
60 | } | |
61 | ||
30764ab5 VZ |
62 | /* static */ |
63 | wxFont *wxFontBase::New(const wxNativeFontInfo& info) | |
64 | { | |
65 | return new wxFont(info); | |
66 | } | |
67 | ||
7826e2dd VZ |
68 | /* static */ |
69 | wxFont *wxFontBase::New(const wxString& strNativeFontDesc) | |
30764ab5 | 70 | { |
30764ab5 | 71 | wxNativeFontInfo fontInfo; |
7826e2dd | 72 | if ( !fontInfo.FromString(strNativeFontDesc) ) |
09fcd889 | 73 | return new wxFont(*wxNORMAL_FONT); |
7826e2dd VZ |
74 | |
75 | return New(fontInfo); | |
76 | } | |
77 | ||
78 | wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const | |
79 | { | |
09fcd889 | 80 | #if !defined(__WXGTK__) && !defined(__WXMSW__) |
7826e2dd | 81 | wxNativeFontInfo *fontInfo = new wxNativeFontInfo; |
30764ab5 | 82 | |
7826e2dd VZ |
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(); | |
30764ab5 VZ |
90 | |
91 | return fontInfo; | |
92 | #else | |
7826e2dd | 93 | return (wxNativeFontInfo *)NULL; |
30764ab5 VZ |
94 | #endif |
95 | } | |
96 | ||
97 | void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info) | |
98 | { | |
09fcd889 | 99 | #if !defined(__WXGTK__) && !defined(__WXMSW__) |
30764ab5 VZ |
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); | |
107 | #endif | |
108 | } | |
109 | ||
7826e2dd VZ |
110 | wxString wxFontBase::GetNativeFontInfoDesc() const |
111 | { | |
112 | wxString fontDesc; | |
113 | wxNativeFontInfo *fontInfo = GetNativeFontInfo(); | |
114 | if ( fontInfo ) | |
115 | { | |
116 | fontDesc = fontInfo->ToString(); | |
117 | delete fontInfo; | |
118 | } | |
119 | ||
120 | return fontDesc; | |
121 | } | |
122 | ||
0c5d3e1c VZ |
123 | wxFont& wxFont::operator=(const wxFont& font) |
124 | { | |
125 | if ( this != &font ) | |
126 | Ref(font); | |
127 | ||
128 | return (wxFont &)*this; | |
129 | } | |
130 | ||
0c5d3e1c VZ |
131 | bool wxFontBase::operator==(const wxFont& font) const |
132 | { | |
8bf30fe9 VZ |
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() || | |
136 | ( | |
137 | Ok() == font.Ok() && | |
138 | GetPointSize() == font.GetPointSize() && | |
139 | GetFamily() == font.GetFamily() && | |
140 | GetStyle() == font.GetStyle() && | |
141 | GetUnderlined() == font.GetUnderlined() && | |
142 | GetFaceName() == font.GetFaceName() && | |
143 | GetEncoding() == font.GetEncoding() | |
144 | ); | |
0c5d3e1c VZ |
145 | } |
146 | ||
147 | bool wxFontBase::operator!=(const wxFont& font) const | |
148 | { | |
8bf30fe9 | 149 | return !(*this == font); |
0c5d3e1c VZ |
150 | } |
151 | ||
152 | wxString wxFontBase::GetFamilyString() const | |
153 | { | |
223d09f6 | 154 | wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); |
0c5d3e1c VZ |
155 | |
156 | switch ( GetFamily() ) | |
157 | { | |
223d09f6 KB |
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"); | |
0c5d3e1c VZ |
165 | } |
166 | } | |
167 | ||
168 | wxString wxFontBase::GetStyleString() const | |
169 | { | |
223d09f6 | 170 | wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); |
0c5d3e1c VZ |
171 | |
172 | switch ( GetStyle() ) | |
173 | { | |
223d09f6 KB |
174 | case wxNORMAL: return wxT("wxNORMAL"); |
175 | case wxSLANT: return wxT("wxSLANT"); | |
176 | case wxITALIC: return wxT("wxITALIC"); | |
177 | default: return wxT("wxDEFAULT"); | |
0c5d3e1c VZ |
178 | } |
179 | } | |
180 | ||
181 | wxString wxFontBase::GetWeightString() const | |
182 | { | |
223d09f6 | 183 | wxCHECK_MSG( Ok(), wxT("wxDEFAULT"), wxT("invalid font") ); |
0c5d3e1c VZ |
184 | |
185 | switch ( GetWeight() ) | |
186 | { | |
223d09f6 KB |
187 | case wxNORMAL: return wxT("wxNORMAL"); |
188 | case wxBOLD: return wxT("wxBOLD"); | |
189 | case wxLIGHT: return wxT("wxLIGHT"); | |
190 | default: return wxT("wxDEFAULT"); | |
0c5d3e1c VZ |
191 | } |
192 | } | |
193 | ||
09fcd889 | 194 | #if !defined(__WXGTK__) && !defined(__WXMSW__) |
30764ab5 VZ |
195 | |
196 | // ---------------------------------------------------------------------------- | |
197 | // wxNativeFontInfo | |
198 | // ---------------------------------------------------------------------------- | |
199 | ||
200 | // These are the generic forms of FromString()/ToString. | |
201 | // | |
202 | // convert to/from the string representation: format is | |
09fcd889 | 203 | // version;pointsize;family;style;weight;underlined;facename;encoding |
30764ab5 VZ |
204 | |
205 | bool wxNativeFontInfo::FromString(const wxString& s) | |
206 | { | |
207 | long l; | |
208 | ||
209 | wxStringTokenizer tokenizer(s, _T(";")); | |
210 | ||
211 | wxString token = tokenizer.GetNextToken(); | |
09fcd889 VZ |
212 | // |
213 | // Ignore the version for now | |
214 | // | |
215 | ||
216 | token = tokenizer.GetNextToken(); | |
30764ab5 VZ |
217 | if ( !token.ToLong(&l) ) |
218 | return FALSE; | |
219 | pointSize = (int)l; | |
220 | ||
221 | token = tokenizer.GetNextToken(); | |
222 | if ( !token.ToLong(&l) ) | |
223 | return FALSE; | |
224 | family = (int)l; | |
225 | ||
226 | token = tokenizer.GetNextToken(); | |
227 | if ( !token.ToLong(&l) ) | |
228 | return FALSE; | |
229 | style = (int)l; | |
230 | ||
231 | token = tokenizer.GetNextToken(); | |
232 | if ( !token.ToLong(&l) ) | |
233 | return FALSE; | |
234 | weight = (int)l; | |
235 | ||
236 | token = tokenizer.GetNextToken(); | |
237 | if ( !token.ToLong(&l) ) | |
238 | return FALSE; | |
189e08b4 | 239 | underlined = l != 0; |
30764ab5 VZ |
240 | |
241 | faceName = tokenizer.GetNextToken(); | |
242 | if( !faceName ) | |
243 | return FALSE; | |
244 | ||
245 | token = tokenizer.GetNextToken(); | |
246 | if ( !token.ToLong(&l) ) | |
247 | return FALSE; | |
248 | encoding = (wxFontEncoding)l; | |
249 | ||
250 | return TRUE; | |
251 | } | |
252 | ||
253 | wxString wxNativeFontInfo::ToString() const | |
254 | { | |
255 | wxString s; | |
256 | ||
09fcd889 VZ |
257 | s.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"), |
258 | 0, // version | |
30764ab5 VZ |
259 | pointSize, |
260 | family, | |
261 | style, | |
262 | weight, | |
263 | underlined, | |
264 | faceName.GetData(), | |
265 | (int)encoding); | |
266 | ||
267 | return s; | |
268 | } | |
269 | ||
7826e2dd | 270 | #endif // generic wxNativeFontInfo implementation |
30764ab5 | 271 |