]>
Commit | Line | Data |
---|---|---|
ffecfa5a JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/palmos/font.cpp | |
3 | // Purpose: wxFont class | |
e2731512 | 4 | // Author: William Osborne - minimal working wxPalmOS port |
ffecfa5a JS |
5 | // Modified by: |
6 | // Created: 10/14/04 | |
e2731512 | 7 | // RCS-ID: $Id$ |
ffecfa5a JS |
8 | // Copyright: (c) wxWidgets team |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
ffecfa5a JS |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
48a1108e WS |
27 | #include "wx/font.h" |
28 | ||
ffecfa5a | 29 | #ifndef WX_PRECOMP |
ffecfa5a JS |
30 | #include "wx/list.h" |
31 | #include "wx/utils.h" | |
32 | #include "wx/app.h" | |
ffecfa5a JS |
33 | #include "wx/log.h" |
34 | #include "wx/encinfo.h" | |
35 | #endif // WX_PRECOMP | |
36 | ||
37 | #include "wx/fontutil.h" | |
38 | #include "wx/fontmap.h" | |
39 | ||
40 | #include "wx/tokenzr.h" | |
41 | ||
42 | #if wxUSE_EXTENDED_RTTI | |
43 | ||
44 | wxBEGIN_ENUM( wxFontFamily ) | |
45 | wxENUM_MEMBER( wxDEFAULT ) | |
46 | wxENUM_MEMBER( wxDECORATIVE ) | |
47 | wxENUM_MEMBER( wxROMAN ) | |
48 | wxENUM_MEMBER( wxSCRIPT ) | |
49 | wxENUM_MEMBER( wxSWISS ) | |
50 | wxENUM_MEMBER( wxMODERN ) | |
51 | wxENUM_MEMBER( wxTELETYPE ) | |
52 | wxEND_ENUM( wxFontFamily ) | |
53 | ||
54 | wxBEGIN_ENUM( wxFontStyle ) | |
55 | wxENUM_MEMBER( wxNORMAL ) | |
56 | wxENUM_MEMBER( wxITALIC ) | |
57 | wxENUM_MEMBER( wxSLANT ) | |
58 | wxEND_ENUM( wxFontStyle ) | |
59 | ||
60 | wxBEGIN_ENUM( wxFontWeight ) | |
61 | wxENUM_MEMBER( wxNORMAL ) | |
62 | wxENUM_MEMBER( wxLIGHT ) | |
63 | wxENUM_MEMBER( wxBOLD ) | |
64 | wxEND_ENUM( wxFontWeight ) | |
65 | ||
66 | IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont, wxGDIObject,"wx/font.h") | |
67 | ||
68 | wxBEGIN_PROPERTIES_TABLE(wxFont) | |
69 | wxPROPERTY( Size,int, SetPointSize, GetPointSize, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
70 | wxPROPERTY( Family, int , SetFamily, GetFamily, (int)wxDEFAULT , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily | |
71 | wxPROPERTY( Style, int , SetStyle, GetStyle, (int)wxNORMAL , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle | |
72 | wxPROPERTY( Weight, int , SetWeight, GetWeight, (int)wxNORMAL , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight | |
73 | wxPROPERTY( Underlined, bool , SetUnderlined, GetUnderlined, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
74 | wxPROPERTY( Face, wxString , SetFaceName, GetFaceName, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
75 | wxPROPERTY( Encoding, wxFontEncoding , SetEncoding, GetEncoding, wxFONTENCODING_DEFAULT , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
76 | wxEND_PROPERTIES_TABLE() | |
77 | ||
78 | wxCONSTRUCTOR_6( wxFont , int , Size , int , Family , int , Style , int , Weight , bool , Underlined , wxString , Face ) | |
79 | ||
80 | wxBEGIN_HANDLERS_TABLE(wxFont) | |
81 | wxEND_HANDLERS_TABLE() | |
82 | ||
83 | #else | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) | |
85 | #endif | |
86 | ||
87 | ||
88 | // ---------------------------------------------------------------------------- | |
89 | // constants | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | // ---------------------------------------------------------------------------- | |
93 | // wxFontRefData - the internal description of the font | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | class WXDLLEXPORT wxFontRefData: public wxGDIRefData | |
97 | { | |
98 | public: | |
99 | // constructors | |
100 | wxFontRefData() | |
101 | { | |
4055ed82 WS |
102 | Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, |
103 | wxFONTWEIGHT_NORMAL, false, wxEmptyString, | |
ffecfa5a JS |
104 | wxFONTENCODING_DEFAULT); |
105 | } | |
106 | ||
107 | wxFontRefData(int size, | |
108 | const wxSize& pixelSize, | |
109 | bool sizeUsingPixels, | |
110 | int family, | |
111 | int style, | |
112 | int weight, | |
113 | bool underlined, | |
114 | const wxString& faceName, | |
115 | wxFontEncoding encoding) | |
116 | { | |
117 | Init(size, pixelSize, sizeUsingPixels, family, style, weight, | |
118 | underlined, faceName, encoding); | |
119 | } | |
120 | ||
121 | wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0) | |
122 | { | |
123 | Init(info, hFont); | |
124 | } | |
125 | ||
126 | wxFontRefData(const wxFontRefData& data) | |
127 | { | |
128 | if ( data.m_nativeFontInfoOk ) | |
129 | { | |
130 | Init(data.m_nativeFontInfo); | |
131 | } | |
132 | else | |
133 | { | |
134 | Init(data.m_pointSize, data.m_pixelSize, data.m_sizeUsingPixels, | |
135 | data.m_family, data.m_style, data.m_weight, | |
136 | data.m_underlined, data.m_faceName, data.m_encoding); | |
137 | } | |
138 | } | |
139 | ||
140 | virtual ~wxFontRefData(); | |
141 | ||
142 | // operations | |
143 | bool Alloc(wxFont *font); | |
144 | ||
145 | void Free(); | |
146 | ||
147 | // all wxFont accessors | |
148 | int GetPointSize() const | |
149 | { | |
150 | return m_nativeFontInfoOk ? m_nativeFontInfo.GetPointSize() | |
151 | : m_pointSize; | |
152 | } | |
153 | ||
154 | wxSize GetPixelSize() const | |
155 | { | |
156 | return m_nativeFontInfoOk ? m_nativeFontInfo.GetPixelSize() | |
157 | : m_pixelSize; | |
158 | } | |
159 | ||
160 | bool IsUsingSizeInPixels() const | |
161 | { | |
162 | return m_nativeFontInfoOk ? true : m_sizeUsingPixels; | |
163 | } | |
164 | ||
165 | int GetFamily() const | |
166 | { | |
167 | return m_family; | |
168 | } | |
169 | ||
170 | int GetStyle() const | |
171 | { | |
172 | return m_nativeFontInfoOk ? m_nativeFontInfo.GetStyle() | |
173 | : m_style; | |
174 | } | |
175 | ||
176 | int GetWeight() const | |
177 | { | |
178 | return m_nativeFontInfoOk ? m_nativeFontInfo.GetWeight() | |
179 | : m_weight; | |
180 | } | |
181 | ||
182 | bool GetUnderlined() const | |
183 | { | |
184 | return m_nativeFontInfoOk ? m_nativeFontInfo.GetUnderlined() | |
185 | : m_underlined; | |
186 | } | |
187 | ||
188 | wxString GetFaceName() const | |
189 | { | |
190 | wxString s; | |
191 | if ( m_nativeFontInfoOk ) | |
192 | s = m_nativeFontInfo.GetFaceName(); | |
193 | else | |
194 | s = m_faceName; | |
195 | ||
196 | return s; | |
197 | } | |
198 | ||
199 | wxFontEncoding GetEncoding() const | |
200 | { | |
201 | return m_nativeFontInfoOk ? m_nativeFontInfo.GetEncoding() | |
202 | : m_encoding; | |
203 | } | |
204 | ||
205 | WXHFONT GetHFONT() const { return m_hFont; } | |
206 | ||
207 | // ... and setters | |
208 | void SetPointSize(int pointSize) | |
209 | { | |
210 | if ( m_nativeFontInfoOk ) | |
211 | { | |
212 | m_nativeFontInfo.SetPointSize(pointSize); | |
213 | } | |
214 | else | |
215 | { | |
216 | m_pointSize = pointSize; | |
4055ed82 | 217 | m_sizeUsingPixels = false; |
ffecfa5a JS |
218 | } |
219 | } | |
220 | ||
221 | void SetPixelSize(const wxSize& pixelSize) | |
222 | { | |
223 | if ( m_nativeFontInfoOk ) | |
224 | { | |
225 | m_nativeFontInfo.SetPixelSize(pixelSize); | |
226 | } | |
227 | else | |
228 | { | |
229 | m_pixelSize = pixelSize; | |
4055ed82 | 230 | m_sizeUsingPixels = true; |
ffecfa5a JS |
231 | } |
232 | } | |
233 | ||
234 | void SetFamily(int family) | |
235 | { | |
236 | m_family = family; | |
237 | } | |
238 | ||
239 | void SetStyle(int style) | |
240 | { | |
241 | if ( m_nativeFontInfoOk ) | |
242 | m_nativeFontInfo.SetStyle((wxFontStyle)style); | |
243 | else | |
244 | m_style = style; | |
245 | } | |
246 | ||
247 | void SetWeight(int weight) | |
248 | { | |
249 | if ( m_nativeFontInfoOk ) | |
250 | m_nativeFontInfo.SetWeight((wxFontWeight)weight); | |
251 | else | |
252 | m_weight = weight; | |
253 | } | |
254 | ||
85ab460e | 255 | bool SetFaceName(const wxString& faceName) |
ffecfa5a JS |
256 | { |
257 | if ( m_nativeFontInfoOk ) | |
258 | m_nativeFontInfo.SetFaceName(faceName); | |
259 | else | |
260 | m_faceName = faceName; | |
261 | } | |
262 | ||
263 | void SetUnderlined(bool underlined) | |
264 | { | |
265 | if ( m_nativeFontInfoOk ) | |
266 | m_nativeFontInfo.SetUnderlined(underlined); | |
267 | else | |
268 | m_underlined = underlined; | |
269 | } | |
270 | ||
271 | void SetEncoding(wxFontEncoding encoding) | |
272 | { | |
273 | if ( m_nativeFontInfoOk ) | |
274 | m_nativeFontInfo.SetEncoding(encoding); | |
275 | else | |
276 | m_encoding = encoding; | |
277 | } | |
278 | ||
279 | // native font info tests | |
280 | bool HasNativeFontInfo() const { return m_nativeFontInfoOk; } | |
281 | ||
282 | const wxNativeFontInfo& GetNativeFontInfo() const | |
283 | { return m_nativeFontInfo; } | |
284 | ||
285 | protected: | |
286 | // common part of all ctors | |
287 | void Init(int size, | |
288 | const wxSize& pixelSize, | |
289 | bool sizeUsingPixels, | |
290 | int family, | |
291 | int style, | |
292 | int weight, | |
293 | bool underlined, | |
294 | const wxString& faceName, | |
295 | wxFontEncoding encoding); | |
296 | ||
297 | void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0); | |
298 | ||
299 | // font characterstics | |
300 | int m_pointSize; | |
301 | wxSize m_pixelSize; | |
302 | bool m_sizeUsingPixels; | |
303 | int m_family; | |
304 | int m_style; | |
305 | int m_weight; | |
306 | bool m_underlined; | |
307 | wxString m_faceName; | |
308 | wxFontEncoding m_encoding; | |
309 | ||
310 | // Windows font handle | |
311 | WXHFONT m_hFont; | |
312 | ||
313 | // Native font info | |
314 | wxNativeFontInfo m_nativeFontInfo; | |
315 | bool m_nativeFontInfoOk; | |
316 | }; | |
317 | ||
318 | // ============================================================================ | |
319 | // implementation | |
320 | // ============================================================================ | |
321 | ||
322 | // ---------------------------------------------------------------------------- | |
323 | // wxFontRefData | |
324 | // ---------------------------------------------------------------------------- | |
325 | ||
326 | void wxFontRefData::Init(int pointSize, | |
327 | const wxSize& pixelSize, | |
328 | bool sizeUsingPixels, | |
329 | int family, | |
330 | int style, | |
331 | int weight, | |
332 | bool underlined, | |
333 | const wxString& faceName, | |
334 | wxFontEncoding encoding) | |
335 | { | |
336 | } | |
337 | ||
338 | void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont) | |
339 | { | |
340 | } | |
341 | ||
342 | wxFontRefData::~wxFontRefData() | |
343 | { | |
344 | } | |
345 | ||
346 | bool wxFontRefData::Alloc(wxFont *font) | |
347 | { | |
348 | return false; | |
349 | } | |
350 | ||
351 | void wxFontRefData::Free() | |
352 | { | |
353 | } | |
354 | ||
355 | // ---------------------------------------------------------------------------- | |
356 | // wxNativeFontInfo | |
357 | // ---------------------------------------------------------------------------- | |
358 | ||
359 | void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize) | |
360 | { | |
361 | } | |
362 | ||
363 | // ---------------------------------------------------------------------------- | |
364 | // wxFont | |
365 | // ---------------------------------------------------------------------------- | |
366 | ||
ffecfa5a JS |
367 | bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont) |
368 | { | |
369 | return false; | |
370 | } | |
371 | ||
372 | wxFont::wxFont(const wxString& fontdesc) | |
373 | { | |
374 | } | |
375 | ||
376 | /* Constructor for a font. Note that the real construction is done | |
377 | * in wxDC::SetFont, when information is available about scaling etc. | |
378 | */ | |
379 | bool wxFont::DoCreate(int pointSize, | |
380 | const wxSize& pixelSize, | |
381 | bool sizeUsingPixels, | |
382 | int family, | |
383 | int style, | |
384 | int weight, | |
385 | bool underlined, | |
386 | const wxString& faceName, | |
387 | wxFontEncoding encoding) | |
388 | { | |
4055ed82 | 389 | return false; |
ffecfa5a JS |
390 | } |
391 | ||
392 | wxFont::~wxFont() | |
393 | { | |
394 | } | |
395 | ||
396 | // ---------------------------------------------------------------------------- | |
397 | // real implementation | |
398 | // ---------------------------------------------------------------------------- | |
399 | ||
400 | bool wxFont::RealizeResource() | |
401 | { | |
4055ed82 | 402 | return false; |
ffecfa5a JS |
403 | } |
404 | ||
405 | bool wxFont::FreeResource(bool WXUNUSED(force)) | |
406 | { | |
407 | return false; | |
408 | } | |
409 | ||
410 | WXHANDLE wxFont::GetResourceHandle() const | |
411 | { | |
412 | return (WXHANDLE)0; | |
413 | } | |
414 | ||
ffecfa5a JS |
415 | bool wxFont::IsFree() const |
416 | { | |
417 | return false; | |
418 | } | |
419 | ||
420 | void wxFont::Unshare() | |
421 | { | |
422 | } | |
423 | ||
424 | // ---------------------------------------------------------------------------- | |
425 | // change font attribute: we recreate font when doing it | |
426 | // ---------------------------------------------------------------------------- | |
427 | ||
428 | void wxFont::SetPointSize(int pointSize) | |
429 | { | |
430 | } | |
431 | ||
432 | void wxFont::SetPixelSize(const wxSize& pixelSize) | |
433 | { | |
434 | } | |
435 | ||
436 | void wxFont::SetFamily(int family) | |
437 | { | |
438 | } | |
439 | ||
440 | void wxFont::SetStyle(int style) | |
441 | { | |
442 | } | |
443 | ||
444 | void wxFont::SetWeight(int weight) | |
445 | { | |
446 | } | |
447 | ||
85ab460e | 448 | bool wxFont::SetFaceName(const wxString& faceName) |
ffecfa5a | 449 | { |
85ab460e | 450 | return true; |
ffecfa5a JS |
451 | } |
452 | ||
453 | void wxFont::SetUnderlined(bool underlined) | |
454 | { | |
455 | } | |
456 | ||
457 | void wxFont::SetEncoding(wxFontEncoding encoding) | |
458 | { | |
459 | } | |
460 | ||
461 | void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info) | |
462 | { | |
463 | } | |
464 | ||
465 | // ---------------------------------------------------------------------------- | |
466 | // accessors | |
467 | // ---------------------------------------------------------------------------- | |
468 | ||
469 | int wxFont::GetPointSize() const | |
470 | { | |
471 | return 0; | |
472 | } | |
473 | ||
474 | wxSize wxFont::GetPixelSize() const | |
475 | { | |
476 | return wxSize(0,0); | |
477 | } | |
478 | ||
479 | bool wxFont::IsUsingSizeInPixels() const | |
480 | { | |
481 | return false; | |
482 | } | |
483 | ||
484 | int wxFont::GetFamily() const | |
485 | { | |
486 | return wxFONTFAMILY_ROMAN; | |
487 | } | |
488 | ||
489 | int wxFont::GetStyle() const | |
490 | { | |
491 | return wxFONTSTYLE_NORMAL; | |
492 | } | |
493 | ||
494 | int wxFont::GetWeight() const | |
495 | { | |
496 | return wxFONTWEIGHT_NORMAL; | |
497 | } | |
498 | ||
499 | bool wxFont::GetUnderlined() const | |
500 | { | |
501 | return false; | |
502 | } | |
503 | ||
504 | wxString wxFont::GetFaceName() const | |
505 | { | |
506 | return wxEmptyString; | |
507 | } | |
508 | ||
509 | wxFontEncoding wxFont::GetEncoding() const | |
510 | { | |
511 | return wxFONTENCODING_SYSTEM; | |
512 | } | |
513 | ||
514 | const wxNativeFontInfo *wxFont::GetNativeFontInfo() const | |
515 | { | |
516 | return NULL; | |
517 | } | |
518 | ||
519 | bool wxFont::IsFixedWidth() const | |
520 | { | |
521 | return false; | |
522 | } |