]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
521bf4ff | 2 | // Name: src/os2/font.cpp |
0e320a79 | 3 | // Purpose: wxFont class |
21802234 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
21802234 | 6 | // Created: 10/06/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
21802234 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
6670f564 WS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
21802234 DW |
15 | // ============================================================================ |
16 | // declarations | |
17 | // ============================================================================ | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | // headers | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
48a1108e WS |
23 | #include "wx/font.h" |
24 | ||
21802234 DW |
25 | #ifndef WX_PRECOMP |
26 | #include <stdio.h> | |
21802234 DW |
27 | #include "wx/list.h" |
28 | #include "wx/utils.h" | |
29 | #include "wx/app.h" | |
6eb280e9 | 30 | #include "wx/log.h" |
21802234 DW |
31 | #endif // WX_PRECOMP |
32 | ||
33 | #include "wx/os2/private.h" | |
0e320a79 | 34 | |
cc95f4f9 DW |
35 | #include "wx/fontutil.h" |
36 | #include "wx/fontmap.h" | |
bd6685b3 | 37 | #include "wx/encinfo.h" |
cc95f4f9 DW |
38 | |
39 | #include "wx/tokenzr.h" | |
21802234 | 40 | |
6670f564 WS |
41 | #include <malloc.h> |
42 | ||
cc95f4f9 | 43 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) |
0e320a79 | 44 | |
21802234 DW |
45 | // ---------------------------------------------------------------------------- |
46 | // wxFontRefData - the internal description of the font | |
47 | // ---------------------------------------------------------------------------- | |
48 | ||
49 | class WXDLLEXPORT wxFontRefData: public wxGDIRefData | |
0e320a79 | 50 | { |
21802234 DW |
51 | public: |
52 | wxFontRefData() | |
53 | { | |
17b1d76b | 54 | Init(-1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, |
0fba44b4 | 55 | wxEmptyString, wxFONTENCODING_DEFAULT); |
21802234 DW |
56 | } |
57 | ||
e99762c0 | 58 | wxFontRefData( int nSize |
98ecc3aa FM |
59 | ,wxFontFamily nFamily |
60 | ,wxFontStyle nStyle | |
61 | ,wxFontWeight nWeight | |
e99762c0 DW |
62 | ,bool bUnderlined |
63 | ,const wxString& sFaceName | |
64 | ,wxFontEncoding vEncoding | |
65 | ) | |
21802234 | 66 | { |
cc95f4f9 DW |
67 | Init( nSize |
68 | ,nFamily | |
69 | ,nStyle | |
70 | ,nWeight | |
71 | ,bUnderlined | |
72 | ,sFaceName | |
73 | ,vEncoding | |
74 | ); | |
75 | } | |
76 | ||
77 | wxFontRefData( const wxNativeFontInfo& rInfo | |
78 | ,WXHFONT hFont = 0 | |
79 | ,WXHANDLE hPS = 0 | |
80 | ) | |
81 | { | |
82 | Init( rInfo | |
83 | ,hFont | |
84 | ,hPS | |
85 | ); | |
86 | } | |
87 | ||
88 | wxFontRefData(const wxFontRefData& rData) | |
89 | { | |
90 | Init( rData.m_nPointSize | |
91 | ,rData.m_nFamily | |
92 | ,rData.m_nStyle | |
93 | ,rData.m_nWeight | |
94 | ,rData.m_bUnderlined | |
95 | ,rData.m_sFaceName | |
96 | ,rData.m_vEncoding | |
97 | ); | |
98 | m_nFontId = rData.m_nFontId; | |
21802234 | 99 | } |
0e320a79 | 100 | |
21802234 DW |
101 | virtual ~wxFontRefData(); |
102 | ||
cc95f4f9 DW |
103 | // |
104 | // Operations | |
105 | // | |
106 | bool Alloc(wxFont* pFont); | |
107 | void Free(void); | |
108 | ||
109 | // | |
110 | // All wxFont accessors | |
111 | // | |
112 | inline int GetPointSize(void) const | |
113 | { | |
2c1e8f2e DW |
114 | // |
115 | // We don't use the actual native font point size since it is | |
116 | // the chosen physical font, which is usually only and approximation | |
117 | // of the desired outline font. The actual displayable point size | |
118 | // is the one stored in the refData | |
119 | // | |
120 | return m_nPointSize; | |
cc95f4f9 DW |
121 | } |
122 | ||
98ecc3aa | 123 | inline wxFontFamily GetFamily(void) const |
cc95f4f9 DW |
124 | { |
125 | return m_nFamily; | |
126 | } | |
127 | ||
98ecc3aa | 128 | inline wxFontStyle GetStyle(void) const |
cc95f4f9 DW |
129 | { |
130 | return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetStyle() | |
131 | : m_nStyle; | |
132 | } | |
133 | ||
98ecc3aa | 134 | inline wxFontWeight GetWeight(void) const |
cc95f4f9 DW |
135 | { |
136 | return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetWeight() | |
137 | : m_nWeight; | |
138 | } | |
139 | ||
140 | inline bool GetUnderlined(void) const | |
141 | { | |
142 | return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetUnderlined() | |
143 | : m_bUnderlined; | |
144 | } | |
145 | ||
146 | inline wxString GetFaceName(void) const | |
147 | { | |
148 | wxString sFaceName; | |
149 | ||
150 | if (m_bNativeFontInfoOk) | |
151 | sFaceName = m_vNativeFontInfo.GetFaceName(); | |
152 | else | |
153 | sFaceName = m_sFaceName; | |
154 | ||
155 | return sFaceName; | |
156 | } | |
157 | ||
158 | inline wxFontEncoding GetEncoding(void) const | |
159 | { | |
160 | return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetEncoding() | |
161 | : m_vEncoding; | |
162 | } | |
163 | ||
164 | inline WXHFONT GetHFONT(void) const { return m_hFont; } | |
165 | inline HPS GetPS(void) const { return m_hPS; } | |
166 | inline PFONTMETRICS GetFM(void) const { return m_pFM; } | |
167 | inline int GetNumFonts(void) const { return m_nNumFonts; } | |
168 | ||
169 | // ... and setters | |
170 | inline void SetPointSize(int nPointSize) | |
171 | { | |
172 | if (m_bNativeFontInfoOk) | |
173 | m_vNativeFontInfo.SetPointSize(nPointSize); | |
174 | else | |
175 | m_nPointSize = nPointSize; | |
176 | } | |
177 | ||
98ecc3aa | 178 | inline void SetFamily(wxFontFamily nFamily) |
cc95f4f9 DW |
179 | { |
180 | m_nFamily = nFamily; | |
181 | } | |
182 | ||
98ecc3aa | 183 | inline void SetStyle(wxFontStyle nStyle) |
cc95f4f9 DW |
184 | { |
185 | if (m_bNativeFontInfoOk) | |
98ecc3aa | 186 | m_vNativeFontInfo.SetStyle(nStyle); |
cc95f4f9 DW |
187 | else |
188 | m_nStyle = nStyle; | |
189 | } | |
190 | ||
98ecc3aa | 191 | inline void SetWeight(wxFontWeight nWeight) |
cc95f4f9 DW |
192 | { |
193 | if (m_bNativeFontInfoOk) | |
98ecc3aa | 194 | m_vNativeFontInfo.SetWeight(nWeight); |
cc95f4f9 DW |
195 | else |
196 | m_nWeight = nWeight; | |
197 | } | |
198 | ||
85ab460e | 199 | inline bool SetFaceName(const wxString& sFaceName) |
cc95f4f9 DW |
200 | { |
201 | if (m_bNativeFontInfoOk) | |
85ab460e | 202 | return m_vNativeFontInfo.SetFaceName(sFaceName); |
cc95f4f9 DW |
203 | else |
204 | m_sFaceName = sFaceName; | |
85ab460e | 205 | return true; |
cc95f4f9 DW |
206 | } |
207 | ||
208 | inline void SetUnderlined(bool bUnderlined) | |
209 | { | |
210 | if (m_bNativeFontInfoOk) | |
211 | m_vNativeFontInfo.SetUnderlined(bUnderlined); | |
212 | else | |
213 | m_bUnderlined = bUnderlined; | |
214 | } | |
215 | ||
216 | inline void SetEncoding(wxFontEncoding vEncoding) | |
217 | { | |
218 | if (m_bNativeFontInfoOk) | |
219 | m_vNativeFontInfo.SetEncoding(vEncoding); | |
220 | else | |
221 | m_vEncoding = vEncoding; | |
222 | } | |
223 | ||
224 | inline void SetPS(HPS hPS) | |
225 | { | |
226 | m_hPS = hPS; | |
227 | } | |
228 | ||
229 | inline void SetFM(PFONTMETRICS pFM) | |
230 | { | |
231 | m_pFM = pFM; | |
232 | } | |
233 | ||
234 | inline void SetNumFonts(int nNumFonts) | |
235 | { | |
236 | m_nNumFonts = nNumFonts; | |
237 | } | |
238 | ||
239 | // | |
240 | // Native font info tests | |
241 | // | |
242 | bool HasNativeFontInfo() const { return m_bNativeFontInfoOk; } | |
243 | ||
244 | const wxNativeFontInfo& GetNativeFontInfo() const | |
245 | { return m_vNativeFontInfo; } | |
246 | ||
21802234 | 247 | protected: |
cc95f4f9 DW |
248 | // |
249 | // Common part of all ctors | |
250 | // | |
e99762c0 | 251 | void Init( int nSize |
46f83c8e FM |
252 | ,wxFontFamily nFamily |
253 | ,wxFontStyle nStyle | |
254 | ,wxFontWeight nWeight | |
e99762c0 DW |
255 | ,bool bUnderlined |
256 | ,const wxString& rsFaceName | |
257 | ,wxFontEncoding vEncoding | |
258 | ); | |
259 | ||
cc95f4f9 DW |
260 | void Init( const wxNativeFontInfo& rInfo |
261 | ,WXHFONT hFont = 0 | |
262 | ,WXHANDLE hPS = 0 | |
263 | ); | |
e99762c0 | 264 | // |
6670f564 | 265 | // If true, the pointer to the actual font is temporary and SHOULD NOT BE |
21802234 | 266 | // DELETED by destructor |
e99762c0 DW |
267 | // |
268 | bool m_bTemporary; | |
269 | int m_nFontId; | |
270 | ||
271 | // | |
272 | // Font characterstics | |
273 | // | |
274 | int m_nPointSize; | |
0951e426 FM |
275 | wxFontFamily m_nFamily; |
276 | wxFontStyle m_nStyle; | |
277 | wxFontWeight m_nWeight; | |
e99762c0 DW |
278 | bool m_bUnderlined; |
279 | wxString m_sFaceName; | |
280 | wxFontEncoding m_vEncoding; | |
cc95f4f9 DW |
281 | WXHFONT m_hFont; |
282 | ||
283 | // | |
284 | // Native font info | |
285 | // | |
286 | wxNativeFontInfo m_vNativeFontInfo; | |
287 | bool m_bNativeFontInfoOk; | |
e99762c0 DW |
288 | |
289 | // | |
290 | // Some PM specific stuff | |
291 | // | |
cc95f4f9 DW |
292 | PFONTMETRICS m_pFM; // array of FONTMETRICS structs |
293 | int m_nNumFonts; // number of fonts in array | |
294 | HPS m_hPS; // PS handle this font belongs to | |
295 | FATTRS m_vFattrs; // Current fattrs struct | |
296 | FACENAMEDESC m_vFname; // Current facename struct | |
297 | bool m_bInternalPS; // Internally generated PS? | |
e99762c0 | 298 | }; // end of CLASS wxFontRefData |
21802234 | 299 | |
68c95704 | 300 | #define M_FONTDATA ((wxFontRefData*)m_refData) |
873fd4af | 301 | |
21802234 DW |
302 | // ============================================================================ |
303 | // implementation | |
304 | // ============================================================================ | |
305 | ||
306 | // ---------------------------------------------------------------------------- | |
307 | // wxFontRefData | |
308 | // ---------------------------------------------------------------------------- | |
309 | ||
e99762c0 DW |
310 | void wxFontRefData::Init( |
311 | int nPointSize | |
98ecc3aa FM |
312 | , wxFontFamily nFamily |
313 | , wxFontStyle nStyle | |
314 | , wxFontWeight nWeight | |
e99762c0 DW |
315 | , bool bUnderlined |
316 | , const wxString& rsFaceName | |
317 | , wxFontEncoding vEncoding | |
318 | ) | |
0e320a79 | 319 | { |
e99762c0 DW |
320 | m_nStyle = nStyle; |
321 | m_nPointSize = nPointSize; | |
322 | m_nFamily = nFamily; | |
323 | m_nStyle = nStyle; | |
324 | m_nWeight = nWeight; | |
325 | m_bUnderlined = bUnderlined; | |
326 | m_sFaceName = rsFaceName; | |
327 | m_vEncoding = vEncoding; | |
cc95f4f9 DW |
328 | m_hFont = 0; |
329 | ||
8ecff181 | 330 | m_bNativeFontInfoOk = false; |
cc95f4f9 | 331 | |
e99762c0 | 332 | m_nFontId = 0; |
8ecff181 | 333 | m_bTemporary = false; |
e99762c0 DW |
334 | m_pFM = (PFONTMETRICS)NULL; |
335 | m_hPS = NULLHANDLE; | |
336 | m_nNumFonts = 0; | |
337 | } // end of wxFontRefData::Init | |
0e320a79 | 338 | |
cc95f4f9 DW |
339 | void wxFontRefData::Init( |
340 | const wxNativeFontInfo& rInfo | |
341 | , WXHFONT hFont //this is the FontId -- functions as the hFont for OS/2 | |
342 | , WXHANDLE hPS // Presentation Space we are using | |
343 | ) | |
344 | { | |
345 | // | |
346 | // hFont may be zero, or it be passed in case we really want to | |
347 | // use the exact font created in the underlying system | |
348 | // (for example where we can't guarantee conversion from HFONT | |
349 | // to LOGFONT back to HFONT) | |
350 | // | |
351 | m_hFont = hFont; | |
352 | m_nFontId = (int)hFont; | |
353 | ||
6670f564 | 354 | m_bNativeFontInfoOk = true; |
cc95f4f9 DW |
355 | m_vNativeFontInfo = rInfo; |
356 | ||
a23692f0 | 357 | if (hPS == NULLHANDLE) |
cc95f4f9 DW |
358 | { |
359 | m_hPS = ::WinGetPS(HWND_DESKTOP); | |
6670f564 | 360 | m_bInternalPS = true; |
cc95f4f9 DW |
361 | } |
362 | else | |
363 | m_hPS = (HPS)hPS; | |
a23692f0 DW |
364 | |
365 | m_nFontId = 0; | |
8ecff181 | 366 | m_bTemporary = false; |
a23692f0 DW |
367 | m_pFM = (PFONTMETRICS)NULL; |
368 | m_nNumFonts = 0; | |
369 | } // end of wxFontRefData::Init | |
cc95f4f9 | 370 | |
0e320a79 | 371 | wxFontRefData::~wxFontRefData() |
cc95f4f9 DW |
372 | { |
373 | Free(); | |
374 | } | |
375 | ||
6670f564 | 376 | bool wxFontRefData::Alloc( wxFont* pFont ) |
cc95f4f9 DW |
377 | { |
378 | wxString sFaceName; | |
828621c2 | 379 | long flId = m_hFont; |
e1146627 | 380 | long lRc; |
d697657f DW |
381 | ERRORID vError; |
382 | wxString sError; | |
cc95f4f9 DW |
383 | |
384 | if (!m_bNativeFontInfoOk) | |
385 | { | |
386 | wxFillLogFont( &m_vNativeFontInfo.fa | |
387 | ,&m_vNativeFontInfo.fn | |
54ffa107 | 388 | ,&m_hPS |
828621c2 | 389 | ,&m_bInternalPS |
cc95f4f9 DW |
390 | ,&flId |
391 | ,sFaceName | |
392 | ,pFont | |
393 | ); | |
6670f564 | 394 | m_bNativeFontInfoOk = true; |
cc95f4f9 | 395 | } |
07df68c8 DW |
396 | else |
397 | { | |
398 | if (flId == 0L) | |
399 | flId = 1L; | |
400 | else | |
401 | flId++; | |
402 | if (flId > 254) | |
403 | flId = 1L; | |
404 | } | |
e1146627 DW |
405 | if((lRc = ::GpiCreateLogFont( m_hPS |
406 | ,NULL | |
407 | ,flId | |
408 | ,&m_vNativeFontInfo.fa | |
409 | )) != GPI_ERROR) | |
410 | { | |
828621c2 DW |
411 | m_hFont = (WXHFONT)flId; |
412 | m_nFontId = flId; | |
e1146627 | 413 | } |
cc95f4f9 DW |
414 | if (!m_hFont) |
415 | { | |
d697657f DW |
416 | vError = ::WinGetLastError(vHabmain); |
417 | sError = wxPMErrorToStr(vError); | |
2173b18f | 418 | wxLogLastError(wxT("CreateFont")); |
cc95f4f9 DW |
419 | } |
420 | ||
e1146627 | 421 | ::GpiSetCharSet(m_hPS, flId); // sets font for presentation space |
cc95f4f9 DW |
422 | ::GpiQueryFontMetrics(m_hPS, sizeof(FONTMETRICS), &m_vNativeFontInfo.fm); |
423 | ||
424 | // | |
425 | // Set refData members with the results | |
426 | // | |
cc95f4f9 DW |
427 | memcpy(&m_vFattrs, &m_vNativeFontInfo.fa, sizeof(m_vFattrs)); |
428 | memcpy(&m_vFname, &m_vNativeFontInfo.fn, sizeof(m_vFname)); | |
2c1e8f2e DW |
429 | // |
430 | // Going to leave the point size alone. Mostly we use outline fonts | |
431 | // that can be set to any point size inside of Presentation Parameters, | |
432 | // regardless of whether or not the actual font is registered in the system. | |
433 | // The GpiCreateLogFont will do enough by selecting the right family, | |
434 | // and face name. | |
435 | // | |
07df68c8 | 436 | if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Times New Roman") == 0) |
0951e426 | 437 | m_nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 438 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Times New Roman MT 30") == 0) |
0951e426 | 439 | m_nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 440 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "@Times New Roman MT 30") == 0) |
0951e426 | 441 | m_nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 442 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Tms Rmn") == 0) |
0951e426 | 443 | m_nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 444 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "WarpSans") == 0) |
0951e426 | 445 | m_nFamily = wxFONTFAMILY_DECORATIVE; |
a4353f07 | 446 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Helvetica") == 0) |
0951e426 | 447 | m_nFamily = wxFONTFAMILY_SWISS; |
07df68c8 | 448 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Helv") == 0) |
0951e426 | 449 | m_nFamily = wxFONTFAMILY_SWISS; |
07df68c8 | 450 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Script") == 0) |
0951e426 | 451 | m_nFamily = wxFONTFAMILY_SCRIPT; |
07df68c8 | 452 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Courier New") == 0) |
0951e426 | 453 | m_nFamily = wxFONTFAMILY_TELETYPE; |
07df68c8 | 454 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Courier") == 0) |
0951e426 | 455 | m_nFamily = wxFONTFAMILY_TELETYPE; |
07df68c8 | 456 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "System Monospaced") == 0) |
0951e426 | 457 | m_nFamily = wxFONTFAMILY_TELETYPE; |
07df68c8 | 458 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "System VIO") == 0) |
0951e426 | 459 | m_nFamily = wxFONTFAMILY_MODERN; |
07df68c8 | 460 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "System Proportional") == 0) |
0951e426 | 461 | m_nFamily = wxFONTFAMILY_MODERN; |
07df68c8 | 462 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Arial") == 0) |
0951e426 | 463 | m_nFamily = wxFONTFAMILY_SWISS; |
1b75810c | 464 | else if (strcmp(m_vNativeFontInfo.fm.szFamilyname, "Swiss") == 0) |
0951e426 | 465 | m_nFamily = wxFONTFAMILY_SWISS; |
cc95f4f9 | 466 | else |
0951e426 | 467 | m_nFamily = wxFONTFAMILY_SWISS; |
cc95f4f9 DW |
468 | |
469 | if (m_vNativeFontInfo.fa.fsSelection & FATTR_SEL_ITALIC) | |
470 | m_nStyle = wxFONTSTYLE_ITALIC; | |
471 | else | |
472 | m_nStyle = wxFONTSTYLE_NORMAL; | |
473 | switch(m_vNativeFontInfo.fn.usWeightClass) | |
474 | { | |
475 | case FWEIGHT_DONT_CARE: | |
476 | m_nWeight = wxFONTWEIGHT_NORMAL; | |
477 | break; | |
478 | ||
479 | case FWEIGHT_NORMAL: | |
480 | m_nWeight = wxFONTWEIGHT_NORMAL; | |
481 | break; | |
482 | ||
483 | case FWEIGHT_LIGHT: | |
484 | m_nWeight = wxFONTWEIGHT_LIGHT; | |
485 | break; | |
486 | ||
487 | case FWEIGHT_BOLD: | |
488 | m_nWeight = wxFONTWEIGHT_BOLD; | |
489 | break; | |
490 | ||
491 | case FWEIGHT_ULTRA_BOLD: | |
492 | m_nWeight = wxFONTWEIGHT_MAX; | |
493 | break; | |
494 | ||
495 | default: | |
496 | m_nWeight = wxFONTWEIGHT_NORMAL; | |
497 | } | |
498 | m_bUnderlined = ((m_vNativeFontInfo.fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0); | |
0fba44b4 | 499 | m_sFaceName = (wxChar*)m_vNativeFontInfo.fa.szFacename; |
cc95f4f9 | 500 | m_vEncoding = wxGetFontEncFromCharSet(m_vNativeFontInfo.fa.usCodePage); |
828621c2 DW |
501 | |
502 | // | |
503 | // We don't actuall keep the font around if using a temporary PS | |
504 | // | |
505 | if (m_bInternalPS) | |
506 | { | |
507 | if(m_hFont) | |
508 | ::GpiDeleteSetId( m_hPS | |
509 | ,flId | |
510 | ); | |
511 | ||
512 | ::WinReleasePS(m_hPS); | |
513 | } | |
514 | else | |
515 | // | |
516 | // Select the font into the Presentation space | |
517 | // | |
518 | ::GpiSetCharSet(m_hPS, flId); // sets font for presentation space | |
6670f564 | 519 | return true; |
cc95f4f9 DW |
520 | } // end of wxFontRefData::Alloc |
521 | ||
522 | void wxFontRefData::Free() | |
0e320a79 | 523 | { |
e99762c0 DW |
524 | if (m_pFM) |
525 | delete [] m_pFM; | |
526 | m_pFM = (PFONTMETRICS)NULL; | |
cc95f4f9 DW |
527 | |
528 | if ( m_hFont ) | |
529 | { | |
cc95f4f9 DW |
530 | ::GpiDeleteSetId(m_hPS, 1L); /* delete the logical font */ |
531 | m_nFontId = 0; | |
532 | m_hFont = 0; | |
533 | } | |
534 | if (m_bInternalPS) | |
535 | ::WinReleasePS(m_hPS); | |
536 | m_hPS = NULLHANDLE; | |
537 | } // end of wxFontRefData::Free | |
0e320a79 | 538 | |
21802234 | 539 | // ---------------------------------------------------------------------------- |
cc95f4f9 | 540 | // wxNativeFontInfo |
21802234 | 541 | // ---------------------------------------------------------------------------- |
0e320a79 | 542 | |
cc95f4f9 DW |
543 | void wxNativeFontInfo::Init() |
544 | { | |
545 | memset(&fa, '\0', sizeof(FATTRS)); | |
546 | } // end of wxNativeFontInfo::Init | |
547 | ||
548 | int wxNativeFontInfo::GetPointSize() const | |
549 | { | |
550 | return fm.lEmHeight; | |
551 | } // end of wxNativeFontInfo::GetPointSize | |
552 | ||
553 | wxFontStyle wxNativeFontInfo::GetStyle() const | |
554 | { | |
555 | return fa.fsSelection & FATTR_SEL_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL; | |
556 | } // end of wxNativeFontInfo::GetStyle | |
557 | ||
558 | wxFontWeight wxNativeFontInfo::GetWeight() const | |
559 | { | |
560 | switch(fn.usWeightClass) | |
19193a2c | 561 | { |
cc95f4f9 DW |
562 | case FWEIGHT_DONT_CARE: |
563 | return wxFONTWEIGHT_NORMAL; | |
564 | ||
565 | case FWEIGHT_NORMAL: | |
566 | return wxFONTWEIGHT_NORMAL; | |
19193a2c | 567 | |
cc95f4f9 DW |
568 | case FWEIGHT_LIGHT: |
569 | return wxFONTWEIGHT_LIGHT; | |
570 | ||
571 | case FWEIGHT_BOLD: | |
572 | return wxFONTWEIGHT_BOLD; | |
573 | ||
574 | case FWEIGHT_ULTRA_BOLD: | |
575 | return wxFONTWEIGHT_MAX; | |
19193a2c | 576 | } |
cc95f4f9 DW |
577 | return wxFONTWEIGHT_NORMAL; |
578 | } // end of wxNativeFontInfo::GetWeight | |
19193a2c | 579 | |
cc95f4f9 DW |
580 | bool wxNativeFontInfo::GetUnderlined() const |
581 | { | |
582 | return ((fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0); | |
583 | } // end of wxNativeFontInfo::GetUnderlined | |
584 | ||
585 | wxString wxNativeFontInfo::GetFaceName() const | |
586 | { | |
0fba44b4 | 587 | return (wxChar*)fm.szFacename; |
cc95f4f9 DW |
588 | } // end of wxNativeFontInfo::GetFaceName |
589 | ||
590 | wxFontFamily wxNativeFontInfo::GetFamily() const | |
591 | { | |
592 | int nFamily; | |
593 | ||
594 | // | |
595 | // Extract family from facename | |
596 | // | |
07df68c8 | 597 | if (strcmp(fm.szFamilyname, "Times New Roman") == 0) |
0951e426 | 598 | nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 599 | else if (strcmp(fm.szFamilyname, "Times New Roman MT 30") == 0) |
0951e426 | 600 | nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 601 | else if (strcmp(fm.szFamilyname, "@Times New Roman MT 30") == 0) |
0951e426 | 602 | nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 603 | else if (strcmp(fm.szFamilyname, "Tms Rmn") == 0) |
0951e426 | 604 | nFamily = wxFONTFAMILY_ROMAN; |
07df68c8 | 605 | else if (strcmp(fm.szFamilyname, "WarpSans") == 0) |
0951e426 | 606 | nFamily = wxFONTFAMILY_DECORATIVE; |
a4353f07 | 607 | else if (strcmp(fm.szFamilyname, "Helvetica") == 0) |
0951e426 | 608 | nFamily = wxFONTFAMILY_SWISS; |
07df68c8 | 609 | else if (strcmp(fm.szFamilyname, "Helv") == 0) |
0951e426 | 610 | nFamily = wxFONTFAMILY_SWISS; |
07df68c8 | 611 | else if (strcmp(fm.szFamilyname, "Script") == 0) |
0951e426 | 612 | nFamily = wxFONTFAMILY_SCRIPT; |
07df68c8 | 613 | else if (strcmp(fm.szFamilyname, "Courier New") == 0) |
0951e426 | 614 | nFamily = wxFONTFAMILY_TELETYPE; |
07df68c8 | 615 | else if (strcmp(fm.szFamilyname, "Courier") == 0) |
0951e426 | 616 | nFamily = wxFONTFAMILY_TELETYPE; |
07df68c8 | 617 | else if (strcmp(fm.szFamilyname, "System Monospaced") == 0) |
0951e426 | 618 | nFamily = wxFONTFAMILY_TELETYPE; |
07df68c8 | 619 | else if (strcmp(fm.szFamilyname, "System VIO") == 0) |
0951e426 | 620 | nFamily = wxFONTFAMILY_MODERN; |
07df68c8 | 621 | else if (strcmp(fm.szFamilyname, "System Proportional") == 0) |
0951e426 | 622 | nFamily = wxFONTFAMILY_MODERN; |
07df68c8 | 623 | else if (strcmp(fm.szFamilyname, "Arial") == 0) |
0951e426 | 624 | nFamily = wxFONTFAMILY_SWISS; |
1b75810c | 625 | else if (strcmp(fm.szFamilyname, "Swiss") == 0) |
0951e426 | 626 | nFamily = wxFONTFAMILY_SWISS; |
cc95f4f9 | 627 | else |
0951e426 | 628 | nFamily = wxFONTFAMILY_SWISS; |
cc95f4f9 DW |
629 | return (wxFontFamily)nFamily; |
630 | } // end of wxNativeFontInfo::GetFamily | |
631 | ||
632 | wxFontEncoding wxNativeFontInfo::GetEncoding() const | |
633 | { | |
634 | return wxGetFontEncFromCharSet(fa.usCodePage); | |
635 | } // end of wxNativeFontInfo::GetEncoding | |
636 | ||
637 | void wxNativeFontInfo::SetPointSize( | |
638 | int nPointsize | |
639 | ) | |
640 | { | |
641 | fm.lEmHeight = (LONG)nPointsize; | |
642 | } // end of wxNativeFontInfo::SetPointSize | |
643 | ||
644 | void wxNativeFontInfo::SetStyle( | |
645 | wxFontStyle eStyle | |
646 | ) | |
647 | { | |
648 | switch (eStyle) | |
649 | { | |
650 | default: | |
9a83f860 | 651 | wxFAIL_MSG( wxT("unknown font style") ); |
cc95f4f9 DW |
652 | // fall through |
653 | ||
654 | case wxFONTSTYLE_NORMAL: | |
655 | break; | |
656 | ||
657 | case wxFONTSTYLE_ITALIC: | |
658 | case wxFONTSTYLE_SLANT: | |
659 | fa.fsSelection |= FATTR_SEL_ITALIC; | |
660 | break; | |
661 | } | |
662 | } // end of wxNativeFontInfo::SetStyle | |
663 | ||
664 | void wxNativeFontInfo::SetWeight( | |
665 | wxFontWeight eWeight | |
666 | ) | |
667 | { | |
668 | switch (eWeight) | |
669 | { | |
670 | default: | |
9a83f860 | 671 | wxFAIL_MSG( wxT("unknown font weight") ); |
cc95f4f9 DW |
672 | // fall through |
673 | ||
674 | case wxFONTWEIGHT_NORMAL: | |
675 | fn.usWeightClass = FWEIGHT_NORMAL; | |
676 | break; | |
677 | ||
678 | case wxFONTWEIGHT_LIGHT: | |
679 | fn.usWeightClass = FWEIGHT_LIGHT; | |
680 | break; | |
681 | ||
682 | case wxFONTWEIGHT_BOLD: | |
683 | fn.usWeightClass = FWEIGHT_BOLD; | |
684 | break; | |
685 | } | |
686 | } // end of wxNativeFontInfo::SetWeight | |
687 | ||
688 | void wxNativeFontInfo::SetUnderlined( | |
689 | bool bUnderlined | |
690 | ) | |
691 | { | |
692 | if(bUnderlined) | |
693 | fa.fsSelection |= FATTR_SEL_UNDERSCORE; | |
694 | } // end of wxNativeFontInfo::SetUnderlined | |
695 | ||
85ab460e | 696 | bool wxNativeFontInfo::SetFaceName( |
fbfb8bcc | 697 | const wxString& sFacename |
cc95f4f9 DW |
698 | ) |
699 | { | |
e408bf52 | 700 | wxStrlcpy((wxChar*)fa.szFacename, sFacename, WXSIZEOF(fa.szFacename)); |
85ab460e | 701 | return true; |
cc95f4f9 DW |
702 | } // end of wxNativeFontInfo::SetFaceName |
703 | ||
704 | void wxNativeFontInfo::SetFamily( | |
705 | wxFontFamily eFamily | |
706 | ) | |
707 | { | |
708 | wxString sFacename; | |
709 | ||
710 | switch (eFamily) | |
711 | { | |
0951e426 | 712 | case wxFONTFAMILY_SCRIPT: |
1b75810c | 713 | sFacename = wxT("Tms Rmn"); |
cc95f4f9 DW |
714 | break; |
715 | ||
0951e426 | 716 | case wxFONTFAMILY_DECORATIVE: |
07df68c8 | 717 | sFacename = wxT("WarpSans"); |
cc95f4f9 DW |
718 | break; |
719 | ||
0951e426 | 720 | case wxFONTFAMILY_ROMAN: |
1b75810c | 721 | sFacename = wxT("Tms Rmn"); |
cc95f4f9 DW |
722 | break; |
723 | ||
0951e426 | 724 | case wxFONTFAMILY_TELETYPE: |
1b75810c | 725 | sFacename = wxT("Courier") ; |
07df68c8 DW |
726 | break; |
727 | ||
0951e426 | 728 | case wxFONTFAMILY_MODERN: |
1b75810c | 729 | sFacename = wxT("System VIO") ; |
cc95f4f9 DW |
730 | break; |
731 | ||
0951e426 | 732 | case wxFONTFAMILY_SWISS: |
07df68c8 | 733 | sFacename = wxT("Helv") ; |
cc95f4f9 DW |
734 | break; |
735 | ||
0951e426 | 736 | case wxFONTFAMILY_DEFAULT: |
cc95f4f9 | 737 | default: |
a23692f0 | 738 | sFacename = wxT("System VIO") ; |
cc95f4f9 DW |
739 | } |
740 | ||
0fba44b4 | 741 | if (!wxStrlen((wxChar*)fa.szFacename) ) |
cc95f4f9 DW |
742 | { |
743 | SetFaceName(sFacename); | |
744 | } | |
745 | } // end of wxNativeFontInfo::SetFamily | |
746 | ||
6670f564 | 747 | void wxNativeFontInfo::SetEncoding( wxFontEncoding eEncoding ) |
cc95f4f9 DW |
748 | { |
749 | wxNativeEncodingInfo vInfo; | |
750 | ||
751 | if ( !wxGetNativeFontEncoding( eEncoding | |
752 | ,&vInfo | |
753 | )) | |
754 | { | |
142b3bc2 | 755 | if (wxFontMapper::Get()->GetAltForEncoding( eEncoding |
cc95f4f9 DW |
756 | ,&vInfo |
757 | )) | |
758 | { | |
759 | if (!vInfo.facename.empty()) | |
760 | { | |
761 | // | |
762 | // If we have this encoding only in some particular facename, use | |
763 | // the facename - it is better to show the correct characters in a | |
764 | // wrong facename than unreadable text in a correct one | |
765 | // | |
766 | SetFaceName(vInfo.facename); | |
767 | } | |
768 | } | |
769 | else | |
cc95f4f9 DW |
770 | { |
771 | // unsupported encoding, replace with the default | |
772 | vInfo.charset = 850; | |
773 | } | |
774 | } | |
6670f564 | 775 | fa.usCodePage = (USHORT)vInfo.charset; |
cc95f4f9 DW |
776 | } // end of wxNativeFontInfo::SetFaceName |
777 | ||
6670f564 | 778 | bool wxNativeFontInfo::FromString( const wxString& rsStr ) |
cc95f4f9 DW |
779 | { |
780 | long lVal; | |
781 | ||
9a83f860 | 782 | wxStringTokenizer vTokenizer(rsStr, wxT(";")); |
cc95f4f9 DW |
783 | |
784 | // | |
785 | // First the version | |
786 | // | |
787 | wxString sToken = vTokenizer.GetNextToken(); | |
788 | ||
9a83f860 | 789 | if (sToken != wxT('0')) |
8ecff181 | 790 | return false; |
cc95f4f9 DW |
791 | |
792 | sToken = vTokenizer.GetNextToken(); | |
793 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 794 | return false; |
cc95f4f9 DW |
795 | fm.lEmHeight = lVal; |
796 | ||
797 | sToken = vTokenizer.GetNextToken(); | |
798 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 799 | return false; |
cc95f4f9 DW |
800 | fa.lAveCharWidth = lVal; |
801 | ||
802 | sToken = vTokenizer.GetNextToken(); | |
803 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 804 | return false; |
cc95f4f9 DW |
805 | fa.fsSelection = (USHORT)lVal; |
806 | ||
807 | sToken = vTokenizer.GetNextToken(); | |
808 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 809 | return false; |
cc95f4f9 DW |
810 | fa.fsType = (USHORT)lVal; |
811 | ||
812 | sToken = vTokenizer.GetNextToken(); | |
813 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 814 | return false; |
cc95f4f9 DW |
815 | fa.fsFontUse = (USHORT)lVal; |
816 | ||
817 | sToken = vTokenizer.GetNextToken(); | |
818 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 819 | return false; |
cc95f4f9 DW |
820 | fa.idRegistry = (USHORT)lVal; |
821 | ||
822 | sToken = vTokenizer.GetNextToken(); | |
823 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 824 | return false; |
cc95f4f9 DW |
825 | fa.usCodePage = (USHORT)lVal; |
826 | ||
827 | sToken = vTokenizer.GetNextToken(); | |
828 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 829 | return false; |
cc95f4f9 DW |
830 | fa.lMatch = lVal; |
831 | ||
832 | sToken = vTokenizer.GetNextToken(); | |
833 | if (!sToken.ToLong(&lVal)) | |
8ecff181 | 834 | return false; |
cc95f4f9 DW |
835 | fn.usWeightClass = (USHORT)lVal; |
836 | ||
837 | sToken = vTokenizer.GetNextToken(); | |
838 | if(!sToken) | |
8ecff181 | 839 | return false; |
0fba44b4 | 840 | wxStrcpy((wxChar*)fa.szFacename, sToken.c_str()); |
6670f564 | 841 | return true; |
cc95f4f9 DW |
842 | } // end of wxNativeFontInfo::FromString |
843 | ||
844 | wxString wxNativeFontInfo::ToString() const | |
845 | { | |
846 | wxString sStr; | |
847 | ||
9a83f860 | 848 | sStr.Printf(wxT("%d;%ld;%ld;%ld;%d;%d;%d;%d;%d;%ld;%d;%s"), |
cc95f4f9 DW |
849 | 0, // version, in case we want to change the format later |
850 | fm.lEmHeight, | |
851 | fa.lAveCharWidth, | |
852 | fa.lMaxBaselineExt, | |
853 | fa.fsSelection, | |
854 | fa.fsType, | |
855 | fa.fsFontUse, | |
856 | fa.idRegistry, | |
857 | fa.usCodePage, | |
858 | fa.lMatch, | |
859 | fn.usWeightClass, | |
fb2c90ca | 860 | (char *)fa.szFacename); |
cc95f4f9 DW |
861 | return sStr; |
862 | } // end of wxNativeFontInfo::ToString | |
863 | ||
864 | // ---------------------------------------------------------------------------- | |
865 | // wxFont | |
866 | // ---------------------------------------------------------------------------- | |
19193a2c | 867 | |
6670f564 WS |
868 | bool wxFont::Create( const wxNativeFontInfo& rInfo, |
869 | WXHFONT hFont ) | |
cc95f4f9 DW |
870 | { |
871 | UnRef(); | |
872 | m_refData = new wxFontRefData( rInfo | |
873 | ,hFont | |
874 | ); | |
875 | RealizeResource(); | |
6670f564 | 876 | return true; |
cc95f4f9 DW |
877 | } // end of wxFont::Create |
878 | ||
879 | wxFont::wxFont( | |
880 | const wxString& rsFontdesc | |
881 | ) | |
882 | { | |
883 | wxNativeFontInfo vInfo; | |
884 | ||
885 | if (vInfo.FromString(rsFontdesc)) | |
886 | (void)Create(vInfo); | |
887 | } // end of wxFont::wxFont | |
0e320a79 | 888 | |
e99762c0 DW |
889 | // ---------------------------------------------------------------------------- |
890 | // Constructor for a font. Note that the real construction is done | |
891 | // in wxDC::SetFont, when information is available about scaling etc. | |
892 | // ---------------------------------------------------------------------------- | |
6670f564 | 893 | bool wxFont::Create( int nPointSize, |
0c14b6c3 FM |
894 | wxFontFamily nFamily, |
895 | wxFontStyle nStyle, | |
896 | wxFontWeight nWeight, | |
6670f564 WS |
897 | bool bUnderlined, |
898 | const wxString& rsFaceName, | |
899 | wxFontEncoding vEncoding ) | |
0e320a79 DW |
900 | { |
901 | UnRef(); | |
cc95f4f9 DW |
902 | |
903 | // | |
904 | // wxDEFAULT is a valid value for the font size too so we must treat it | |
905 | // specially here (otherwise the size would be 70 == wxDEFAULT value) | |
906 | // | |
907 | if (nPointSize == wxDEFAULT) | |
908 | { | |
909 | nPointSize = wxNORMAL_FONT->GetPointSize(); | |
910 | } | |
e99762c0 DW |
911 | m_refData = new wxFontRefData( nPointSize |
912 | ,nFamily | |
913 | ,nStyle | |
914 | ,nWeight | |
915 | ,bUnderlined | |
916 | ,rsFaceName | |
917 | ,vEncoding | |
918 | ); | |
0e320a79 | 919 | RealizeResource(); |
6670f564 | 920 | return true; |
e99762c0 | 921 | } // end of wxFont::Create |
0e320a79 DW |
922 | |
923 | wxFont::~wxFont() | |
924 | { | |
e99762c0 | 925 | } // end of wxFont::~wxFont |
0e320a79 | 926 | |
21802234 DW |
927 | // ---------------------------------------------------------------------------- |
928 | // real implementation | |
f6bcfd97 BP |
929 | // Boris' Kovalenko comments: |
930 | // Because OS/2 fonts are associated with PS we can not create the font | |
931 | // here, but we may check that font definition is true | |
21802234 DW |
932 | // ---------------------------------------------------------------------------- |
933 | ||
4b3f61d1 SN |
934 | wxGDIRefData *wxFont::CreateGDIRefData() const |
935 | { | |
936 | return new wxFontRefData(); | |
937 | } | |
938 | ||
939 | wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const | |
940 | { | |
5c33522f | 941 | return new wxFontRefData(*static_cast<const wxFontRefData *>(data)); |
4b3f61d1 SN |
942 | } |
943 | ||
0e320a79 DW |
944 | bool wxFont::RealizeResource() |
945 | { | |
21802234 DW |
946 | if ( GetResourceHandle() ) |
947 | { | |
6670f564 | 948 | return true; |
21802234 | 949 | } |
cc95f4f9 | 950 | return M_FONTDATA->Alloc(this); |
e99762c0 | 951 | } // end of wxFont::RealizeResource |
21802234 | 952 | |
6670f564 | 953 | bool wxFont::FreeResource( bool WXUNUSED(bForce) ) |
21802234 | 954 | { |
e99762c0 | 955 | if (GetResourceHandle()) |
21802234 | 956 | { |
cc95f4f9 | 957 | M_FONTDATA->Free(); |
6670f564 | 958 | return true; |
21802234 | 959 | } |
6670f564 | 960 | return false; |
e99762c0 | 961 | } // end of wxFont::FreeResource |
0e320a79 | 962 | |
17b1d76b | 963 | WXHANDLE wxFont::GetResourceHandle() const |
5fd2b2c6 DW |
964 | { |
965 | return GetHFONT(); | |
e99762c0 | 966 | } // end of wxFont::GetResourceHandle |
21802234 | 967 | |
cc95f4f9 DW |
968 | WXHFONT wxFont::GetHFONT() const |
969 | { | |
970 | return M_FONTDATA ? M_FONTDATA->GetHFONT() : 0; | |
971 | } // end of wxFont::GetHFONT | |
972 | ||
21802234 DW |
973 | bool wxFont::IsFree() const |
974 | { | |
cc95f4f9 | 975 | return M_FONTDATA && (M_FONTDATA->GetHFONT() == 0); |
e99762c0 | 976 | } // end of wxFont::IsFree |
21802234 | 977 | |
21802234 DW |
978 | // ---------------------------------------------------------------------------- |
979 | // change font attribute: we recreate font when doing it | |
980 | // ---------------------------------------------------------------------------- | |
981 | ||
e99762c0 DW |
982 | void wxFont::SetPointSize( |
983 | int nPointSize | |
984 | ) | |
0e320a79 | 985 | { |
4b3f61d1 | 986 | AllocExclusive(); |
0e320a79 | 987 | |
cc95f4f9 | 988 | M_FONTDATA->SetPointSize(nPointSize); |
0e320a79 DW |
989 | |
990 | RealizeResource(); | |
e99762c0 | 991 | } // end of wxFont::SetPointSize |
0e320a79 | 992 | |
e99762c0 | 993 | void wxFont::SetFamily( |
98ecc3aa | 994 | wxFontFamily nFamily |
e99762c0 | 995 | ) |
0e320a79 | 996 | { |
4b3f61d1 | 997 | AllocExclusive(); |
0e320a79 | 998 | |
cc95f4f9 | 999 | M_FONTDATA->SetFamily(nFamily); |
0e320a79 DW |
1000 | |
1001 | RealizeResource(); | |
e99762c0 | 1002 | } // end of wxFont::SetFamily |
0e320a79 | 1003 | |
e99762c0 | 1004 | void wxFont::SetStyle( |
98ecc3aa | 1005 | wxFontStyle nStyle |
e99762c0 | 1006 | ) |
0e320a79 | 1007 | { |
4b3f61d1 | 1008 | AllocExclusive(); |
0e320a79 | 1009 | |
cc95f4f9 | 1010 | M_FONTDATA->SetStyle(nStyle); |
0e320a79 DW |
1011 | |
1012 | RealizeResource(); | |
e99762c0 | 1013 | } // end of wxFont::SetStyle |
0e320a79 | 1014 | |
e99762c0 | 1015 | void wxFont::SetWeight( |
98ecc3aa | 1016 | wxFontWeight nWeight |
e99762c0 | 1017 | ) |
0e320a79 | 1018 | { |
4b3f61d1 | 1019 | AllocExclusive(); |
0e320a79 | 1020 | |
cc95f4f9 | 1021 | M_FONTDATA->SetWeight(nWeight); |
0e320a79 DW |
1022 | |
1023 | RealizeResource(); | |
e99762c0 | 1024 | } // end of wxFont::SetWeight |
0e320a79 | 1025 | |
85ab460e | 1026 | bool wxFont::SetFaceName( |
e99762c0 DW |
1027 | const wxString& rsFaceName |
1028 | ) | |
0e320a79 | 1029 | { |
4b3f61d1 | 1030 | AllocExclusive(); |
0e320a79 | 1031 | |
85ab460e | 1032 | bool refdataok = M_FONTDATA->SetFaceName(rsFaceName); |
0e320a79 DW |
1033 | |
1034 | RealizeResource(); | |
85ab460e VZ |
1035 | |
1036 | return refdataok && wxFontBase::SetFaceName(rsFaceName); | |
e99762c0 | 1037 | } // end of wxFont::SetFaceName |
0e320a79 | 1038 | |
e99762c0 DW |
1039 | void wxFont::SetUnderlined( |
1040 | bool bUnderlined | |
1041 | ) | |
0e320a79 | 1042 | { |
4b3f61d1 | 1043 | AllocExclusive(); |
0e320a79 | 1044 | |
cc95f4f9 | 1045 | M_FONTDATA->SetUnderlined(bUnderlined); |
0e320a79 DW |
1046 | |
1047 | RealizeResource(); | |
e99762c0 | 1048 | } // end of wxFont::SetUnderlined |
0e320a79 | 1049 | |
e99762c0 DW |
1050 | void wxFont::SetEncoding( |
1051 | wxFontEncoding vEncoding | |
1052 | ) | |
0e320a79 | 1053 | { |
4b3f61d1 | 1054 | AllocExclusive(); |
21802234 | 1055 | |
cc95f4f9 | 1056 | M_FONTDATA->SetEncoding(vEncoding); |
21802234 DW |
1057 | |
1058 | RealizeResource(); | |
e99762c0 DW |
1059 | } // end of wxFont::SetEncoding |
1060 | ||
9045ad9d | 1061 | void wxFont::DoSetNativeFontInfo( |
cc95f4f9 | 1062 | const wxNativeFontInfo& rInfo |
e99762c0 DW |
1063 | ) |
1064 | { | |
4b3f61d1 | 1065 | AllocExclusive(); |
e99762c0 | 1066 | |
cc95f4f9 | 1067 | FreeResource(); |
e99762c0 | 1068 | |
cc95f4f9 | 1069 | *M_FONTDATA = wxFontRefData(rInfo); |
e99762c0 | 1070 | |
cc95f4f9 DW |
1071 | RealizeResource(); |
1072 | } | |
0e320a79 | 1073 | |
21802234 DW |
1074 | // ---------------------------------------------------------------------------- |
1075 | // accessors | |
1076 | // ---------------------------------------------------------------------------- | |
1077 | ||
1078 | int wxFont::GetPointSize() const | |
0e320a79 | 1079 | { |
cc95f4f9 | 1080 | wxCHECK_MSG( Ok(), 0, wxT("invalid font") ); |
7e99520b | 1081 | |
cc95f4f9 | 1082 | return M_FONTDATA->GetPointSize(); |
e99762c0 | 1083 | } // end of wxFont::GetPointSize |
0e320a79 | 1084 | |
0c14b6c3 | 1085 | wxFontFamily wxFont::GetFamily() const |
0e320a79 | 1086 | { |
0c14b6c3 | 1087 | wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") ); |
21802234 | 1088 | |
cc95f4f9 DW |
1089 | return M_FONTDATA->GetFamily(); |
1090 | } // end of wxFont::GetFamily | |
21802234 | 1091 | |
0c14b6c3 | 1092 | wxFontStyle wxFont::GetStyle() const |
21802234 | 1093 | { |
0c14b6c3 | 1094 | wxCHECK_MSG( Ok(), wxFONTSTYLE_MAX, wxT("invalid font") ); |
cc95f4f9 DW |
1095 | |
1096 | return M_FONTDATA->GetStyle(); | |
e99762c0 | 1097 | } // end of wxFont::GetStyle |
21802234 | 1098 | |
0c14b6c3 | 1099 | wxFontWeight wxFont::GetWeight() const |
21802234 | 1100 | { |
0c14b6c3 | 1101 | wxCHECK_MSG( Ok(), wxFONTWEIGHT_MAX, wxT("invalid font") ); |
cc95f4f9 DW |
1102 | |
1103 | return M_FONTDATA->GetWeight(); | |
21802234 DW |
1104 | } |
1105 | ||
1106 | bool wxFont::GetUnderlined() const | |
1107 | { | |
8ecff181 | 1108 | wxCHECK_MSG( Ok(), false, wxT("invalid font") ); |
cc95f4f9 DW |
1109 | |
1110 | return M_FONTDATA->GetUnderlined(); | |
e99762c0 | 1111 | } // end of wxFont::GetUnderlined |
21802234 DW |
1112 | |
1113 | wxString wxFont::GetFaceName() const | |
1114 | { | |
521bf4ff | 1115 | wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") ); |
e99762c0 | 1116 | |
cc95f4f9 | 1117 | return M_FONTDATA->GetFaceName(); |
e99762c0 | 1118 | } // end of wxFont::GetFaceName |
21802234 DW |
1119 | |
1120 | wxFontEncoding wxFont::GetEncoding() const | |
1121 | { | |
cc95f4f9 | 1122 | wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); |
e99762c0 | 1123 | |
cc95f4f9 DW |
1124 | return M_FONTDATA->GetEncoding(); |
1125 | } // end of wxFont::GetEncoding | |
0e320a79 | 1126 | |
3bf5a59b | 1127 | const wxNativeFontInfo* wxFont::GetNativeFontInfo() const |
cc95f4f9 | 1128 | { |
3bf5a59b VZ |
1129 | return M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo()) |
1130 | : NULL; | |
cc95f4f9 DW |
1131 | } // end of wxFont::GetNativeFontInfo |
1132 | ||
1133 | // | |
1134 | // Internal use only method to set the FONTMETRICS array | |
1135 | // | |
48a1108e | 1136 | void wxFont::SetFM( PFONTMETRICS pFM, int nNumFonts ) |
cc95f4f9 DW |
1137 | { |
1138 | M_FONTDATA->SetFM(pFM); | |
1139 | M_FONTDATA->SetNumFonts(nNumFonts); | |
1140 | } // end of wxFont::SetFM | |
e99762c0 DW |
1141 | |
1142 | ||
48a1108e | 1143 | void wxFont::SetPS( HPS hPS ) |
d0a6b279 | 1144 | { |
4b3f61d1 | 1145 | AllocExclusive(); |
d0a6b279 DW |
1146 | |
1147 | M_FONTDATA->SetPS(hPS); | |
1148 | ||
1149 | RealizeResource(); | |
47df2b8c | 1150 | } // end of wxFont::SetPS |