]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
df91131c | 2 | // Name: src/mac/carbon/font.cpp |
e9576ca5 | 3 | // Purpose: wxFont class |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3e527073 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/font.h" |
df91131c WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/string.h" | |
de6185e2 | 18 | #include "wx/utils.h" |
987e9419 | 19 | #include "wx/intl.h" |
dd05139a | 20 | #include "wx/gdicmn.h" |
162f6b2a | 21 | #include "wx/log.h" |
df91131c WS |
22 | #endif |
23 | ||
5b781a67 | 24 | #include "wx/fontutil.h" |
ccd67a6a | 25 | #include "wx/graphics.h" |
3b7e6277 | 26 | |
76a5e5d2 | 27 | #include "wx/mac/private.h" |
6eaa4426 | 28 | |
768c6e8b | 29 | #ifndef __DARWIN__ |
7f0c3a63 | 30 | #include <ATSUnicode.h> |
768c6e8b | 31 | #endif |
76a5e5d2 | 32 | |
6eaa4426 | 33 | |
e9576ca5 | 34 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) |
e9576ca5 | 35 | |
6eaa4426 | 36 | |
3bf5a59b VZ |
37 | class WXDLLEXPORT wxFontRefData: public wxGDIRefData |
38 | { | |
868302f3 | 39 | friend class wxFont; |
6eaa4426 | 40 | |
3bf5a59b VZ |
41 | public: |
42 | wxFontRefData() | |
43 | : m_fontId(0) | |
44 | , m_pointSize(10) | |
45 | , m_family(wxDEFAULT) | |
46 | , m_style(wxNORMAL) | |
47 | , m_weight(wxNORMAL) | |
df91131c | 48 | , m_underlined(false) |
c277569a | 49 | , m_faceName(wxT("applicationfont")) |
3bf5a59b | 50 | , m_encoding(wxFONTENCODING_DEFAULT) |
6239ee05 SC |
51 | #ifdef __LP64__ |
52 | #else | |
2a0155df | 53 | , m_macFontFamily(0) |
3bf5a59b VZ |
54 | , m_macFontSize(0) |
55 | , m_macFontStyle(0) | |
e369bddb | 56 | , m_macATSUFontID(0) |
6239ee05 SC |
57 | #endif |
58 | , m_macATSUStyle(0) | |
3bf5a59b | 59 | { |
c277569a SC |
60 | Init(m_pointSize, m_family, m_style, m_weight, |
61 | m_underlined, m_faceName, m_encoding); | |
3bf5a59b VZ |
62 | } |
63 | ||
64 | wxFontRefData(const wxFontRefData& data) | |
65 | : wxGDIRefData() | |
66 | , m_fontId(data.m_fontId) | |
67 | , m_pointSize(data.m_pointSize) | |
68 | , m_family(data.m_family) | |
69 | , m_style(data.m_style) | |
70 | , m_weight(data.m_weight) | |
71 | , m_underlined(data.m_underlined) | |
72 | , m_faceName(data.m_faceName) | |
73 | , m_encoding(data.m_encoding) | |
6239ee05 SC |
74 | #ifdef __LP64__ |
75 | #else | |
2a0155df | 76 | , m_macFontFamily(data.m_macFontFamily) |
3bf5a59b VZ |
77 | , m_macFontSize(data.m_macFontSize) |
78 | , m_macFontStyle(data.m_macFontStyle) | |
e369bddb | 79 | , m_macATSUFontID(data.m_macATSUFontID) |
6239ee05 SC |
80 | #endif |
81 | , m_macATSUStyle(0) | |
3bf5a59b VZ |
82 | { |
83 | Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, | |
84 | data.m_underlined, data.m_faceName, data.m_encoding); | |
85 | } | |
86 | ||
87 | wxFontRefData(int size, | |
88 | int family, | |
89 | int style, | |
90 | int weight, | |
91 | bool underlined, | |
92 | const wxString& faceName, | |
93 | wxFontEncoding encoding) | |
94 | : m_fontId(0) | |
95 | , m_pointSize(size) | |
96 | , m_family(family) | |
97 | , m_style(style) | |
98 | , m_weight(weight) | |
99 | , m_underlined(underlined) | |
100 | , m_faceName(faceName) | |
101 | , m_encoding(encoding) | |
6239ee05 SC |
102 | #ifdef __LP64__ |
103 | #else | |
2a0155df | 104 | , m_macFontFamily(0) |
3bf5a59b VZ |
105 | , m_macFontSize(0) |
106 | , m_macFontStyle(0) | |
e369bddb | 107 | , m_macATSUFontID(0) |
6239ee05 SC |
108 | #endif |
109 | , m_macATSUStyle(0) | |
3bf5a59b VZ |
110 | { |
111 | Init(size, family, style, weight, underlined, faceName, encoding); | |
112 | } | |
113 | ||
114 | virtual ~wxFontRefData(); | |
6eaa4426 DS |
115 | |
116 | void SetNoAntiAliasing( bool no = true ) | |
117 | { m_noAA = no; } | |
118 | ||
119 | bool GetNoAntiAliasing() const | |
120 | { return m_noAA; } | |
121 | ||
2a0155df | 122 | void MacFindFont(); |
6eaa4426 | 123 | |
3bf5a59b VZ |
124 | protected: |
125 | // common part of all ctors | |
126 | void Init(int size, | |
127 | int family, | |
128 | int style, | |
129 | int weight, | |
130 | bool underlined, | |
131 | const wxString& faceName, | |
132 | wxFontEncoding encoding); | |
133 | ||
134 | // font characterstics | |
e369bddb GD |
135 | int m_fontId; |
136 | int m_pointSize; | |
137 | int m_family; | |
138 | int m_style; | |
139 | int m_weight; | |
140 | bool m_underlined; | |
141 | wxString m_faceName; | |
142 | wxFontEncoding m_encoding; | |
3bf5a59b | 143 | bool m_noAA; // No anti-aliasing |
6eaa4426 | 144 | |
3bf5a59b | 145 | public: |
6239ee05 | 146 | #ifndef __LP64__ |
2a0155df SC |
147 | FMFontFamily m_macFontFamily; |
148 | FMFontSize m_macFontSize; | |
149 | FMFontStyle m_macFontStyle; | |
6eaa4426 | 150 | |
facd6764 | 151 | // ATSU Font Information |
6eaa4426 | 152 | |
3103e8a9 | 153 | // this is split into an ATSU font id that may |
facd6764 SC |
154 | // contain some styles (special bold fonts etc) and |
155 | // these are the additional qd styles that are not | |
156 | // included in the ATSU font id | |
157 | ATSUFontID m_macATSUFontID; | |
2a0155df | 158 | FMFontStyle m_macATSUAdditionalQDStyles ; |
6eaa4426 | 159 | |
facd6764 SC |
160 | // for true themeing support we must store the correct font |
161 | // information here, as this speeds up and optimizes rendering | |
162 | ThemeFontID m_macThemeFontID ; | |
6239ee05 SC |
163 | #else |
164 | CTFontRef m_macFontRef; | |
165 | CTFontUIFontType m_macUIFontType; | |
166 | #endif | |
167 | ATSUStyle m_macATSUStyle ; | |
6eaa4426 | 168 | wxNativeFontInfo m_info; |
3bf5a59b | 169 | }; |
6eaa4426 | 170 | |
68c95704 | 171 | #define M_FONTDATA ((wxFontRefData*)m_refData) |
873fd4af | 172 | |
6eaa4426 | 173 | |
e7549107 SC |
174 | // ============================================================================ |
175 | // implementation | |
176 | // ============================================================================ | |
177 | ||
178 | // ---------------------------------------------------------------------------- | |
179 | // wxFontRefData | |
180 | // ---------------------------------------------------------------------------- | |
181 | ||
182 | void wxFontRefData::Init(int pointSize, | |
6eaa4426 DS |
183 | int family, |
184 | int style, | |
185 | int weight, | |
186 | bool underlined, | |
187 | const wxString& faceName, | |
188 | wxFontEncoding encoding) | |
e9576ca5 | 189 | { |
e7549107 SC |
190 | m_style = style; |
191 | m_pointSize = pointSize; | |
192 | m_family = family; | |
193 | m_style = style; | |
194 | m_weight = weight; | |
195 | m_underlined = underlined; | |
196 | m_faceName = faceName; | |
197 | m_encoding = encoding; | |
6239ee05 SC |
198 | #ifdef __LP64__ |
199 | m_macUIFontType = kCTFontNoFontType; | |
200 | m_macFontRef = 0; | |
201 | #else | |
2a0155df | 202 | m_macFontFamily = 0 ; |
d84afea9 GD |
203 | m_macFontSize = 0; |
204 | m_macFontStyle = 0; | |
facd6764 SC |
205 | m_macATSUFontID = 0; |
206 | m_macATSUAdditionalQDStyles = 0 ; | |
6eaa4426 | 207 | |
facd6764 | 208 | m_macThemeFontID = kThemeCurrentPortFont ; |
6239ee05 SC |
209 | #endif |
210 | m_macATSUStyle = NULL ; | |
6eaa4426 | 211 | m_noAA = false; |
e9576ca5 SC |
212 | } |
213 | ||
214 | wxFontRefData::~wxFontRefData() | |
215 | { | |
3e527073 SC |
216 | if ( m_macATSUStyle ) |
217 | { | |
218 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
219 | m_macATSUStyle = NULL ; | |
220 | } | |
e9576ca5 SC |
221 | } |
222 | ||
519cb848 SC |
223 | void wxFontRefData::MacFindFont() |
224 | { | |
6239ee05 | 225 | OSStatus status = noErr; |
2a0155df | 226 | Str255 qdFontName ; |
6239ee05 SC |
227 | |
228 | #ifdef __LP64__ | |
229 | if ( m_faceName.empty() && m_family == wxDEFAULT ) | |
230 | { | |
231 | m_macUIFontType = kCTFontSystemFontType; | |
232 | } | |
233 | ||
234 | if ( m_macUIFontType != kCTFontNoFontType ) | |
235 | { | |
236 | m_macFontRef = CTFontCreateUIFontForLanguage( m_macUIFontType, 0.0, NULL ); | |
237 | wxMacCFStringHolder name( CTFontCopyFamilyName( m_macFontRef ) ); | |
238 | m_faceName = name.AsString(); | |
239 | } | |
240 | else | |
241 | { | |
242 | if ( m_faceName.empty() ) | |
243 | { | |
244 | switch ( m_family ) | |
245 | { | |
246 | case wxSCRIPT : | |
247 | case wxROMAN : | |
248 | case wxDECORATIVE : | |
249 | m_faceName = wxT("Times"); | |
250 | break ; | |
251 | ||
252 | case wxSWISS : | |
253 | m_faceName = wxT("Lucida Grande"); | |
254 | break ; | |
255 | ||
256 | case wxMODERN : | |
257 | case wxTELETYPE: | |
258 | m_faceName = wxT("Monaco"); | |
259 | break ; | |
260 | ||
261 | default: | |
262 | m_faceName = wxT("Times"); | |
263 | break ; | |
264 | } | |
265 | } | |
266 | ||
267 | wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); | |
268 | m_macFontRef = CTFontCreateWithName( cf, m_pointSize, NULL); | |
269 | } | |
270 | ||
271 | if ( m_macATSUStyle ) | |
272 | { | |
273 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
274 | m_macATSUStyle = NULL ; | |
275 | } | |
276 | ||
277 | status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); | |
278 | wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); | |
279 | ||
280 | ATSUAttributeTag atsuTags[] = | |
281 | { | |
282 | kATSUSizeTag , | |
283 | kATSUVerticalCharacterTag, | |
284 | kATSUQDBoldfaceTag , | |
285 | kATSUQDItalicTag , | |
286 | kATSUQDUnderlineTag , | |
287 | kATSUQDCondensedTag , | |
288 | kATSUQDExtendedTag , | |
289 | kATSUFontTag , | |
290 | }; | |
291 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
292 | { | |
293 | sizeof( Fixed ) , | |
294 | sizeof( ATSUVerticalCharacterType), | |
295 | sizeof( Boolean ) , | |
296 | sizeof( Boolean ) , | |
297 | sizeof( Boolean ) , | |
298 | sizeof( Boolean ) , | |
299 | sizeof( Boolean ) , | |
300 | sizeof( ATSUFontID ) , | |
301 | }; | |
302 | ||
303 | Boolean kTrue = true ; | |
304 | Boolean kFalse = false ; | |
305 | ||
306 | Fixed atsuSize = IntToFixed( m_pointSize ); | |
307 | short m_macATSUAdditionalQDStyles = 0; | |
308 | ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; | |
309 | ATSUFontID atsuFontID = 0; | |
310 | int attributeCount = sizeof(atsuTags) / sizeof(ATSUAttributeTag) ; | |
311 | ||
312 | // attempt to add atsu font | |
313 | status = ATSUFindFontFromName(m_faceName.c_str(), strlen(m_faceName.c_str()), kFontFamilyName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &atsuFontID); | |
314 | if ( status != noErr ) | |
315 | { | |
316 | attributeCount--; | |
317 | } | |
318 | ||
319 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
320 | { | |
321 | &atsuSize , | |
322 | &kHorizontal, | |
323 | (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse , | |
324 | (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse , | |
325 | (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse , | |
326 | (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse , | |
327 | (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse , | |
328 | &atsuFontID , | |
329 | }; | |
330 | ||
331 | status = ::ATSUSetAttributes( (ATSUStyle)m_macATSUStyle, attributeCount, atsuTags, atsuSizes, atsuValues); | |
332 | ||
333 | wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); | |
334 | #else | |
6eaa4426 | 335 | if ( m_macThemeFontID != kThemeCurrentPortFont ) |
e40298d5 | 336 | { |
2a0155df SC |
337 | Style style ; |
338 | GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &m_macFontSize, &style ); | |
339 | m_macFontStyle = style ; | |
340 | m_faceName = wxMacMakeStringFromPascal( qdFontName ); | |
facd6764 SC |
341 | if ( m_macFontStyle & bold ) |
342 | m_weight = wxBOLD ; | |
343 | else | |
344 | m_weight = wxNORMAL ; | |
345 | if ( m_macFontStyle & italic ) | |
346 | m_style = wxITALIC ; | |
347 | if ( m_macFontStyle & underline ) | |
348 | m_underlined = true ; | |
facd6764 | 349 | m_pointSize = m_macFontSize ; |
2a0155df | 350 | m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); |
e40298d5 JS |
351 | } |
352 | else | |
353 | { | |
df91131c | 354 | if ( m_faceName.empty() ) |
facd6764 | 355 | { |
2a0155df | 356 | if ( m_family == wxDEFAULT ) |
facd6764 | 357 | { |
2a0155df SC |
358 | m_macFontFamily = GetAppFont(); |
359 | FMGetFontFamilyName(m_macFontFamily,qdFontName); | |
360 | m_faceName = wxMacMakeStringFromPascal( qdFontName ); | |
361 | } | |
362 | else | |
363 | { | |
364 | switch ( m_family ) | |
365 | { | |
366 | case wxSCRIPT : | |
367 | case wxROMAN : | |
368 | case wxDECORATIVE : | |
369 | m_faceName = wxT("Times"); | |
370 | break ; | |
371 | ||
372 | case wxSWISS : | |
373 | m_faceName = wxT("Lucida Grande"); | |
374 | break ; | |
375 | ||
376 | case wxMODERN : | |
d9485f89 | 377 | case wxTELETYPE: |
2a0155df SC |
378 | m_faceName = wxT("Monaco"); |
379 | break ; | |
380 | ||
381 | default: | |
382 | m_faceName = wxT("Times"); | |
383 | break ; | |
384 | } | |
385 | wxMacStringToPascal( m_faceName , qdFontName ); | |
386 | m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); | |
dedf5d9f SC |
387 | if ( m_macFontFamily == kInvalidFontFamily ) |
388 | { | |
f08b7bec | 389 | wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() ); |
dedf5d9f SC |
390 | m_macFontFamily = GetAppFont(); |
391 | } | |
facd6764 | 392 | } |
facd6764 | 393 | } |
e40298d5 JS |
394 | else |
395 | { | |
facd6764 | 396 | if ( m_faceName == wxT("systemfont") ) |
2a0155df | 397 | m_macFontFamily = GetSysFont(); |
facd6764 | 398 | else if ( m_faceName == wxT("applicationfont") ) |
2a0155df | 399 | m_macFontFamily = GetAppFont(); |
facd6764 SC |
400 | else |
401 | { | |
2a0155df SC |
402 | wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); |
403 | ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault ); | |
6239ee05 | 404 | if ( atsfamily == (ATSFontFamilyRef) -1 ) |
dedf5d9f | 405 | { |
5d2ad2f1 | 406 | wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName ); |
dedf5d9f SC |
407 | m_macFontFamily = GetAppFont(); |
408 | } | |
409 | else | |
410 | m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); | |
facd6764 | 411 | } |
e40298d5 | 412 | } |
facd6764 SC |
413 | |
414 | m_macFontStyle = 0; | |
415 | if (m_weight == wxBOLD) | |
416 | m_macFontStyle |= bold; | |
6eaa4426 | 417 | if (m_style == wxITALIC || m_style == wxSLANT) |
facd6764 | 418 | m_macFontStyle |= italic; |
6eaa4426 | 419 | if (m_underlined) |
facd6764 SC |
420 | m_macFontStyle |= underline; |
421 | m_macFontSize = m_pointSize ; | |
e40298d5 JS |
422 | } |
423 | ||
facd6764 | 424 | // we try to get as much styles as possible into ATSU |
3e527073 | 425 | |
6eaa4426 | 426 | |
2a0155df SC |
427 | // ATSUFontID and FMFont are equivalent |
428 | FMFontStyle intrinsicStyle = 0 ; | |
429 | status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle); | |
430 | wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); | |
2a0155df | 431 | m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle ); |
de6185e2 | 432 | |
3e527073 SC |
433 | if ( m_macATSUStyle ) |
434 | { | |
435 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
436 | m_macATSUStyle = NULL ; | |
437 | } | |
6eaa4426 | 438 | |
2a0155df SC |
439 | status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); |
440 | wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); | |
6eaa4426 | 441 | |
3e527073 SC |
442 | ATSUAttributeTag atsuTags[] = |
443 | { | |
2a0155df SC |
444 | kATSUFontTag , |
445 | kATSUSizeTag , | |
446 | kATSUVerticalCharacterTag, | |
447 | kATSUQDBoldfaceTag , | |
448 | kATSUQDItalicTag , | |
449 | kATSUQDUnderlineTag , | |
450 | kATSUQDCondensedTag , | |
451 | kATSUQDExtendedTag , | |
6eaa4426 DS |
452 | }; |
453 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
3e527073 | 454 | { |
2a0155df SC |
455 | sizeof( ATSUFontID ) , |
456 | sizeof( Fixed ) , | |
457 | sizeof( ATSUVerticalCharacterType), | |
458 | sizeof( Boolean ) , | |
459 | sizeof( Boolean ) , | |
460 | sizeof( Boolean ) , | |
461 | sizeof( Boolean ) , | |
462 | sizeof( Boolean ) , | |
6eaa4426 DS |
463 | }; |
464 | ||
3e527073 SC |
465 | Boolean kTrue = true ; |
466 | Boolean kFalse = false ; | |
467 | ||
2a0155df | 468 | Fixed atsuSize = IntToFixed( m_macFontSize ); |
3e527073 | 469 | ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; |
6eaa4426 | 470 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = |
3e527073 SC |
471 | { |
472 | &m_macATSUFontID , | |
473 | &atsuSize , | |
474 | &kHorizontal, | |
475 | (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse , | |
476 | (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse , | |
477 | (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse , | |
478 | (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse , | |
479 | (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse , | |
6eaa4426 DS |
480 | }; |
481 | ||
482 | status = ::ATSUSetAttributes( | |
483 | (ATSUStyle)m_macATSUStyle, | |
484 | sizeof(atsuTags) / sizeof(ATSUAttributeTag) , | |
3e527073 SC |
485 | atsuTags, atsuSizes, atsuValues); |
486 | ||
2a0155df | 487 | wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); |
6239ee05 | 488 | #endif |
519cb848 SC |
489 | } |
490 | ||
e7549107 SC |
491 | // ---------------------------------------------------------------------------- |
492 | // wxFont | |
493 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 494 | |
5b781a67 SC |
495 | bool wxFont::Create(const wxNativeFontInfo& info) |
496 | { | |
6eaa4426 DS |
497 | return Create( |
498 | info.pointSize, info.family, info.style, info.weight, | |
499 | info.underlined, info.faceName, info.encoding ); | |
5b781a67 SC |
500 | } |
501 | ||
3b7e6277 GD |
502 | wxFont::wxFont(const wxString& fontdesc) |
503 | { | |
504 | wxNativeFontInfo info; | |
505 | if ( info.FromString(fontdesc) ) | |
506 | (void)Create(info); | |
507 | } | |
508 | ||
e7549107 | 509 | bool wxFont::Create(int pointSize, |
6eaa4426 DS |
510 | int family, |
511 | int style, | |
512 | int weight, | |
513 | bool underlined, | |
514 | const wxString& faceName, | |
515 | wxFontEncoding encoding) | |
e9576ca5 SC |
516 | { |
517 | UnRef(); | |
6eaa4426 DS |
518 | |
519 | m_refData = new wxFontRefData( | |
520 | pointSize, family, style, weight, | |
521 | underlined, faceName, encoding); | |
e9576ca5 SC |
522 | |
523 | RealizeResource(); | |
524 | ||
6eaa4426 | 525 | return true; |
e9576ca5 SC |
526 | } |
527 | ||
6239ee05 SC |
528 | #ifdef __LP64__ |
529 | ||
530 | bool wxFont::MacCreateUIFont(wxUint32 ctFontType ) | |
531 | { | |
532 | UnRef(); | |
533 | ||
534 | m_refData = new wxFontRefData( | |
535 | 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, | |
536 | false, wxEmptyString, wxFONTENCODING_DEFAULT ); | |
537 | ||
538 | M_FONTDATA->m_macUIFontType = ctFontType ; | |
539 | RealizeResource(); | |
540 | ||
541 | return true; | |
542 | } | |
543 | ||
544 | #endif | |
545 | ||
6eaa4426 | 546 | bool wxFont::MacCreateThemeFont(wxUint16 themeFontID) |
facd6764 | 547 | { |
6239ee05 SC |
548 | #ifdef __LP64__ |
549 | return MacCreateUIFont(HIThemeGetUIFontType(themeFontID)); | |
550 | #else | |
facd6764 | 551 | UnRef(); |
6eaa4426 DS |
552 | |
553 | m_refData = new wxFontRefData( | |
554 | 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, | |
555 | false, wxEmptyString, wxFONTENCODING_DEFAULT ); | |
556 | ||
facd6764 SC |
557 | M_FONTDATA->m_macThemeFontID = themeFontID ; |
558 | RealizeResource(); | |
559 | ||
6eaa4426 | 560 | return true; |
6239ee05 | 561 | #endif |
facd6764 SC |
562 | } |
563 | ||
e9576ca5 SC |
564 | wxFont::~wxFont() |
565 | { | |
e9576ca5 SC |
566 | } |
567 | ||
568 | bool wxFont::RealizeResource() | |
569 | { | |
2a0155df | 570 | M_FONTDATA->MacFindFont(); |
6eaa4426 DS |
571 | |
572 | return true; | |
e9576ca5 SC |
573 | } |
574 | ||
51abe921 SC |
575 | void wxFont::SetEncoding(wxFontEncoding encoding) |
576 | { | |
83dcd781 | 577 | Unshare(); |
51abe921 SC |
578 | |
579 | M_FONTDATA->m_encoding = encoding; | |
580 | ||
581 | RealizeResource(); | |
582 | } | |
583 | ||
83dcd781 | 584 | void wxFont::Unshare() |
e9576ca5 | 585 | { |
83dcd781 PC |
586 | // Don't change shared data |
587 | if (!m_refData) | |
588 | { | |
589 | m_refData = new wxFontRefData(); | |
590 | } | |
591 | else | |
592 | { | |
593 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
594 | UnRef(); | |
595 | m_refData = ref; | |
596 | } | |
e9576ca5 SC |
597 | } |
598 | ||
599 | void wxFont::SetPointSize(int pointSize) | |
600 | { | |
83dcd781 | 601 | Unshare(); |
e9576ca5 SC |
602 | |
603 | M_FONTDATA->m_pointSize = pointSize; | |
604 | ||
605 | RealizeResource(); | |
606 | } | |
607 | ||
608 | void wxFont::SetFamily(int family) | |
609 | { | |
83dcd781 | 610 | Unshare(); |
e9576ca5 SC |
611 | |
612 | M_FONTDATA->m_family = family; | |
613 | ||
614 | RealizeResource(); | |
615 | } | |
616 | ||
617 | void wxFont::SetStyle(int style) | |
618 | { | |
83dcd781 | 619 | Unshare(); |
e9576ca5 SC |
620 | |
621 | M_FONTDATA->m_style = style; | |
622 | ||
623 | RealizeResource(); | |
624 | } | |
625 | ||
626 | void wxFont::SetWeight(int weight) | |
627 | { | |
83dcd781 | 628 | Unshare(); |
e9576ca5 SC |
629 | |
630 | M_FONTDATA->m_weight = weight; | |
631 | ||
632 | RealizeResource(); | |
633 | } | |
634 | ||
85ab460e | 635 | bool wxFont::SetFaceName(const wxString& faceName) |
e9576ca5 | 636 | { |
83dcd781 | 637 | Unshare(); |
e9576ca5 SC |
638 | |
639 | M_FONTDATA->m_faceName = faceName; | |
640 | ||
641 | RealizeResource(); | |
85ab460e VZ |
642 | |
643 | return wxFontBase::SetFaceName(faceName); | |
e9576ca5 SC |
644 | } |
645 | ||
646 | void wxFont::SetUnderlined(bool underlined) | |
647 | { | |
83dcd781 | 648 | Unshare(); |
e9576ca5 SC |
649 | |
650 | M_FONTDATA->m_underlined = underlined; | |
651 | ||
652 | RealizeResource(); | |
653 | } | |
654 | ||
ac17f9b1 SC |
655 | void wxFont::SetNoAntiAliasing( bool no ) |
656 | { | |
83dcd781 | 657 | Unshare(); |
ac17f9b1 SC |
658 | |
659 | M_FONTDATA->SetNoAntiAliasing( no ); | |
660 | ||
661 | RealizeResource(); | |
662 | } | |
663 | ||
e7549107 SC |
664 | // ---------------------------------------------------------------------------- |
665 | // accessors | |
666 | // ---------------------------------------------------------------------------- | |
667 | ||
fcb35beb VZ |
668 | // TODO: insert checks everywhere for M_FONTDATA == NULL! |
669 | ||
e7549107 | 670 | int wxFont::GetPointSize() const |
e9576ca5 | 671 | { |
77eddfb7 | 672 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 673 | |
e7549107 | 674 | return M_FONTDATA->m_pointSize; |
e9576ca5 SC |
675 | } |
676 | ||
ccd67a6a KO |
677 | wxSize wxFont::GetPixelSize() const |
678 | { | |
679 | #if wxUSE_GRAPHICS_CONTEXT | |
680 | // TODO: consider caching the value | |
681 | wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef) NULL); | |
40503c98 | 682 | dc->SetFont(*(wxFont *)this,*wxBLACK); |
ccd67a6a | 683 | wxDouble width, height = 0; |
8a438f46 | 684 | dc->GetTextExtent( wxT("g"), &width, &height, NULL, NULL); |
6239ee05 | 685 | delete dc; |
8a438f46 | 686 | return wxSize((int)width, (int)height); |
ccd67a6a | 687 | #else |
5d465013 | 688 | return wxFontBase::GetPixelSize(); |
ccd67a6a KO |
689 | #endif |
690 | } | |
691 | ||
e7549107 | 692 | int wxFont::GetFamily() const |
e9576ca5 | 693 | { |
77eddfb7 | 694 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 695 | |
e7549107 | 696 | return M_FONTDATA->m_family; |
e9576ca5 SC |
697 | } |
698 | ||
e7549107 | 699 | int wxFont::GetStyle() const |
e9576ca5 | 700 | { |
77eddfb7 | 701 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 702 | |
e7549107 SC |
703 | return M_FONTDATA->m_style; |
704 | } | |
705 | ||
706 | int wxFont::GetWeight() const | |
707 | { | |
77eddfb7 | 708 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 709 | |
e7549107 SC |
710 | return M_FONTDATA->m_weight; |
711 | } | |
712 | ||
713 | bool wxFont::GetUnderlined() const | |
714 | { | |
77eddfb7 | 715 | wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") ); |
6eaa4426 | 716 | |
e7549107 SC |
717 | return M_FONTDATA->m_underlined; |
718 | } | |
719 | ||
720 | wxString wxFont::GetFaceName() const | |
721 | { | |
facd6764 | 722 | wxCHECK_MSG( M_FONTDATA != NULL , wxEmptyString , wxT("invalid font") ); |
6eaa4426 | 723 | |
facd6764 | 724 | return M_FONTDATA->m_faceName; |
e7549107 SC |
725 | } |
726 | ||
727 | wxFontEncoding wxFont::GetEncoding() const | |
728 | { | |
facd6764 | 729 | wxCHECK_MSG( M_FONTDATA != NULL , wxFONTENCODING_DEFAULT , wxT("invalid font") ); |
6eaa4426 | 730 | |
e7549107 | 731 | return M_FONTDATA->m_encoding; |
e9576ca5 SC |
732 | } |
733 | ||
5ac2e80c | 734 | bool wxFont::GetNoAntiAliasing() const |
ac17f9b1 | 735 | { |
77eddfb7 | 736 | wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") ); |
6eaa4426 | 737 | |
ac17f9b1 SC |
738 | return M_FONTDATA->m_noAA; |
739 | } | |
740 | ||
6239ee05 SC |
741 | #ifndef __LP64__ |
742 | ||
facd6764 | 743 | short wxFont::MacGetFontNum() const |
fcb35beb | 744 | { |
77eddfb7 | 745 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 746 | |
2a0155df | 747 | return M_FONTDATA->m_macFontFamily; |
fcb35beb VZ |
748 | } |
749 | ||
facd6764 | 750 | short wxFont::MacGetFontSize() const |
fcb35beb | 751 | { |
77eddfb7 | 752 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 753 | |
fcb35beb VZ |
754 | return M_FONTDATA->m_macFontSize; |
755 | } | |
756 | ||
facd6764 | 757 | wxByte wxFont::MacGetFontStyle() const |
fcb35beb | 758 | { |
77eddfb7 | 759 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 760 | |
fcb35beb VZ |
761 | return M_FONTDATA->m_macFontStyle; |
762 | } | |
763 | ||
facd6764 | 764 | wxUint32 wxFont::MacGetATSUFontID() const |
fcb35beb | 765 | { |
77eddfb7 | 766 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 767 | |
fcb35beb VZ |
768 | return M_FONTDATA->m_macATSUFontID; |
769 | } | |
770 | ||
6eaa4426 | 771 | void * wxFont::MacGetATSUStyle() const |
3e527073 SC |
772 | { |
773 | wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); | |
6eaa4426 | 774 | |
3e527073 SC |
775 | return M_FONTDATA->m_macATSUStyle; |
776 | } | |
777 | ||
facd6764 SC |
778 | wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const |
779 | { | |
77eddfb7 | 780 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 781 | |
facd6764 SC |
782 | return M_FONTDATA->m_macATSUAdditionalQDStyles; |
783 | } | |
784 | ||
6eaa4426 | 785 | wxUint16 wxFont::MacGetThemeFontID() const |
facd6764 | 786 | { |
77eddfb7 | 787 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 788 | |
facd6764 SC |
789 | return M_FONTDATA->m_macThemeFontID; |
790 | } | |
6239ee05 SC |
791 | #else |
792 | const void * wxFont::MacGetCTFont() const | |
793 | { | |
794 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); | |
795 | ||
796 | return M_FONTDATA->m_macFontRef; | |
797 | } | |
798 | ||
799 | // to be removed | |
800 | void * wxFont::MacGetATSUStyle() const | |
801 | { | |
802 | wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); | |
803 | ||
804 | return M_FONTDATA->m_macATSUStyle; | |
805 | } | |
806 | ||
807 | #endif | |
facd6764 | 808 | |
6eaa4426 | 809 | const wxNativeFontInfo * wxFont::GetNativeFontInfo() const |
3bf5a59b | 810 | { |
facd6764 | 811 | wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); |
3bf5a59b VZ |
812 | wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); |
813 | ||
814 | M_FONTDATA->m_info.InitFromFont(*this); | |
815 | ||
816 | return &(M_FONTDATA->m_info); | |
817 | } |