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