]>
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 | |
b3c1d21c | 27 | #include "wx/mac/uma.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 | { | |
3bf5a59b VZ |
39 | public: |
40 | wxFontRefData() | |
3bf5a59b | 41 | { |
c07e1e2c SC |
42 | Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, |
43 | false, wxT("applicationfont"), wxFONTENCODING_DEFAULT); | |
3bf5a59b VZ |
44 | } |
45 | ||
46 | wxFontRefData(const wxFontRefData& data) | |
3bf5a59b VZ |
47 | { |
48 | Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, | |
49 | data.m_underlined, data.m_faceName, data.m_encoding); | |
50 | } | |
51 | ||
52 | wxFontRefData(int size, | |
53 | int family, | |
54 | int style, | |
55 | int weight, | |
56 | bool underlined, | |
57 | const wxString& faceName, | |
58 | wxFontEncoding encoding) | |
3bf5a59b VZ |
59 | { |
60 | Init(size, family, style, weight, underlined, faceName, encoding); | |
61 | } | |
8f884a0d | 62 | |
8b534a7b SC |
63 | #if wxMAC_USE_CORE_TEXT |
64 | wxFontRefData( wxUint32 coreTextFontType ); | |
65 | wxFontRefData( CTFontRef font ); | |
66 | wxFontRefData( CTFontDescriptorRef fontdescriptor, int size ); | |
67 | #endif | |
3bf5a59b VZ |
68 | |
69 | virtual ~wxFontRefData(); | |
6eaa4426 | 70 | |
8b534a7b | 71 | void SetNoAntiAliasing( bool no = true ) { m_noAA = no; } |
6eaa4426 | 72 | |
8b534a7b | 73 | bool GetNoAntiAliasing() const { return m_noAA; } |
6eaa4426 | 74 | |
8f884a0d | 75 | void SetPointSize( int size ) |
8b534a7b SC |
76 | { |
77 | m_pointSize = size; | |
78 | MacInvalidateNativeFont(); | |
79 | } | |
8f884a0d | 80 | |
8b534a7b | 81 | int GetPointSize() const { return m_pointSize; } |
8f884a0d VZ |
82 | |
83 | void SetFamily( int family ) | |
8b534a7b SC |
84 | { |
85 | m_family = family; | |
86 | MacInvalidateNativeFont(); | |
87 | } | |
8f884a0d VZ |
88 | |
89 | ||
8b534a7b | 90 | int GetFamily() const { return m_family; } |
8f884a0d VZ |
91 | |
92 | void SetStyle( int style ) | |
8b534a7b SC |
93 | { |
94 | m_style = style; | |
95 | MacInvalidateNativeFont(); | |
96 | } | |
8f884a0d VZ |
97 | |
98 | ||
8b534a7b | 99 | int GetStyle() const { return m_style; } |
8f884a0d VZ |
100 | |
101 | void SetWeight( int weight ) | |
8b534a7b SC |
102 | { |
103 | m_weight = weight; | |
104 | MacInvalidateNativeFont(); | |
105 | } | |
8f884a0d VZ |
106 | |
107 | ||
8b534a7b | 108 | int GetWeight() const { return m_weight; } |
8f884a0d VZ |
109 | |
110 | void SetUnderlined( bool u ) | |
8b534a7b SC |
111 | { |
112 | m_underlined = u; | |
113 | MacInvalidateNativeFont(); | |
114 | } | |
8f884a0d | 115 | |
8b534a7b | 116 | bool GetUnderlined() const { return m_underlined; } |
8f884a0d VZ |
117 | |
118 | void SetFaceName( const wxString& facename ) | |
8b534a7b SC |
119 | { |
120 | m_faceName = facename; | |
121 | MacInvalidateNativeFont(); | |
122 | } | |
8f884a0d | 123 | |
8b534a7b | 124 | const wxString& GetFaceName() const { return m_faceName; } |
8f884a0d VZ |
125 | |
126 | void SetEncoding( wxFontEncoding encoding ) | |
8b534a7b SC |
127 | { |
128 | m_encoding = encoding; | |
129 | MacInvalidateNativeFont(); | |
8f884a0d VZ |
130 | } |
131 | ||
132 | wxFontEncoding GetEncoding() const { return m_encoding; } | |
133 | ||
8b534a7b | 134 | void MacInvalidateNativeFont(); |
8f884a0d | 135 | |
2a0155df | 136 | void MacFindFont(); |
8f884a0d | 137 | |
3bf5a59b VZ |
138 | protected: |
139 | // common part of all ctors | |
140 | void Init(int size, | |
141 | int family, | |
142 | int style, | |
143 | int weight, | |
144 | bool underlined, | |
145 | const wxString& faceName, | |
146 | wxFontEncoding encoding); | |
147 | ||
8b534a7b SC |
148 | #if wxMAC_USE_CORE_TEXT |
149 | void Init( CTFontRef font ); | |
8f884a0d | 150 | #endif |
3bf5a59b | 151 | // font characterstics |
e369bddb GD |
152 | int m_pointSize; |
153 | int m_family; | |
154 | int m_style; | |
155 | int m_weight; | |
156 | bool m_underlined; | |
157 | wxString m_faceName; | |
158 | wxFontEncoding m_encoding; | |
3bf5a59b | 159 | bool m_noAA; // No anti-aliasing |
6eaa4426 | 160 | |
3bf5a59b | 161 | public: |
c07e1e2c | 162 | #if wxMAC_USE_ATSU_TEXT |
2a0155df SC |
163 | FMFontFamily m_macFontFamily; |
164 | FMFontSize m_macFontSize; | |
165 | FMFontStyle m_macFontStyle; | |
6eaa4426 | 166 | |
facd6764 | 167 | // ATSU Font Information |
6eaa4426 | 168 | |
3103e8a9 | 169 | // this is split into an ATSU font id that may |
facd6764 SC |
170 | // contain some styles (special bold fonts etc) and |
171 | // these are the additional qd styles that are not | |
172 | // included in the ATSU font id | |
173 | ATSUFontID m_macATSUFontID; | |
2a0155df | 174 | FMFontStyle m_macATSUAdditionalQDStyles ; |
6eaa4426 | 175 | |
facd6764 SC |
176 | // for true themeing support we must store the correct font |
177 | // information here, as this speeds up and optimizes rendering | |
178 | ThemeFontID m_macThemeFontID ; | |
c07e1e2c SC |
179 | #endif |
180 | #if wxMAC_USE_CORE_TEXT | |
181 | wxCFRef<CTFontRef> m_ctFont; | |
8b534a7b | 182 | wxCFRef<CTFontDescriptorRef> m_ctFontDescriptor; |
f34105c6 SC |
183 | #endif |
184 | #if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT | |
185 | ATSUStyle m_macATSUStyle ; | |
6239ee05 | 186 | #endif |
6eaa4426 | 187 | wxNativeFontInfo m_info; |
3bf5a59b | 188 | }; |
6eaa4426 | 189 | |
68c95704 | 190 | #define M_FONTDATA ((wxFontRefData*)m_refData) |
873fd4af | 191 | |
6eaa4426 | 192 | |
e7549107 SC |
193 | // ============================================================================ |
194 | // implementation | |
195 | // ============================================================================ | |
196 | ||
197 | // ---------------------------------------------------------------------------- | |
198 | // wxFontRefData | |
199 | // ---------------------------------------------------------------------------- | |
200 | ||
201 | void wxFontRefData::Init(int pointSize, | |
6eaa4426 DS |
202 | int family, |
203 | int style, | |
204 | int weight, | |
205 | bool underlined, | |
206 | const wxString& faceName, | |
207 | wxFontEncoding encoding) | |
e9576ca5 | 208 | { |
e7549107 SC |
209 | m_style = style; |
210 | m_pointSize = pointSize; | |
211 | m_family = family; | |
212 | m_style = style; | |
213 | m_weight = weight; | |
214 | m_underlined = underlined; | |
215 | m_faceName = faceName; | |
216 | m_encoding = encoding; | |
c07e1e2c | 217 | m_noAA = false; |
c07e1e2c | 218 | #if wxMAC_USE_ATSU_TEXT |
2a0155df | 219 | m_macFontFamily = 0 ; |
d84afea9 GD |
220 | m_macFontSize = 0; |
221 | m_macFontStyle = 0; | |
facd6764 SC |
222 | m_macATSUFontID = 0; |
223 | m_macATSUAdditionalQDStyles = 0 ; | |
facd6764 | 224 | m_macThemeFontID = kThemeCurrentPortFont ; |
f34105c6 SC |
225 | #endif |
226 | #if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT | |
6239ee05 | 227 | m_macATSUStyle = NULL ; |
c07e1e2c | 228 | #endif |
e9576ca5 SC |
229 | } |
230 | ||
231 | wxFontRefData::~wxFontRefData() | |
232 | { | |
f34105c6 | 233 | #if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT |
3e527073 SC |
234 | if ( m_macATSUStyle ) |
235 | { | |
236 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
237 | m_macATSUStyle = NULL ; | |
238 | } | |
9f4e08ae | 239 | #endif |
e9576ca5 SC |
240 | } |
241 | ||
8b534a7b SC |
242 | void wxFontRefData::MacInvalidateNativeFont() |
243 | { | |
244 | #if wxMAC_USE_CORE_TEXT | |
245 | m_ctFont.reset(); | |
246 | m_ctFontDescriptor.reset(); | |
247 | #endif | |
f34105c6 | 248 | #if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT |
8b534a7b SC |
249 | if ( m_macATSUStyle ) |
250 | { | |
251 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
252 | m_macATSUStyle = NULL ; | |
253 | } | |
254 | #endif | |
255 | } | |
256 | ||
c07e1e2c | 257 | #if wxMAC_USE_CORE_TEXT |
6239ee05 | 258 | |
8f884a0d | 259 | /* from Core Text Manual Common Operations */ |
c07e1e2c | 260 | |
8b534a7b | 261 | static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, CTFontSymbolicTraits iTraits ) |
c07e1e2c SC |
262 | { |
263 | CTFontDescriptorRef descriptor = NULL; | |
264 | CFMutableDictionaryRef attributes; | |
8f884a0d | 265 | |
c07e1e2c SC |
266 | assert(iFamilyName != NULL); |
267 | // Create a mutable dictionary to hold our attributes. | |
268 | attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
269 | &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); | |
270 | check(attributes != NULL); | |
8f884a0d VZ |
271 | |
272 | if (attributes != NULL) { | |
c07e1e2c SC |
273 | // Add a family name to our attributes. |
274 | CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, iFamilyName); | |
8f884a0d VZ |
275 | |
276 | ||
c07e1e2c SC |
277 | if ( iTraits ) { |
278 | CFMutableDictionaryRef traits; | |
279 | CFNumberRef symTraits; | |
280 | ||
281 | // Create the traits dictionary. | |
282 | symTraits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, | |
283 | &iTraits); | |
284 | check(symTraits != NULL); | |
8f884a0d | 285 | |
c07e1e2c SC |
286 | if (symTraits != NULL) { |
287 | // Create a dictionary to hold our traits values. | |
288 | traits = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
289 | &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); | |
290 | check(traits != NULL); | |
8f884a0d | 291 | |
c07e1e2c SC |
292 | if (traits != NULL) { |
293 | // Add the symbolic traits value to the traits dictionary. | |
294 | CFDictionaryAddValue(traits, kCTFontSymbolicTrait, symTraits); | |
8f884a0d | 295 | |
c07e1e2c SC |
296 | // Add the traits attribute to our attributes. |
297 | CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits); | |
298 | CFRelease(traits); | |
299 | } | |
300 | CFRelease(symTraits); | |
6239ee05 SC |
301 | } |
302 | } | |
c07e1e2c SC |
303 | // Create the font descriptor with our attributes and input size. |
304 | descriptor = CTFontDescriptorCreateWithAttributes(attributes); | |
305 | check(descriptor != NULL); | |
8f884a0d | 306 | |
c07e1e2c | 307 | CFRelease(attributes); |
6239ee05 | 308 | } |
c07e1e2c | 309 | // Return our font descriptor. |
8b534a7b SC |
310 | return descriptor ; |
311 | } | |
312 | ||
313 | wxFontRefData::wxFontRefData( wxUint32 coreTextFontType ) | |
314 | { | |
315 | CTFontRef font = CTFontCreateUIFontForLanguage( coreTextFontType, 0.0, NULL ) ; | |
316 | if ( CTFontGetSize(m_ctFont) == 0 ) | |
317 | { | |
318 | CFRelease(font); | |
319 | font = CTFontCreateUIFontForLanguage( coreTextFontType, 12.0, NULL ); | |
320 | } | |
321 | Init( font ); | |
322 | } | |
323 | ||
324 | wxFontRefData::wxFontRefData( CTFontRef font ) | |
325 | { | |
326 | Init( font ); | |
327 | } | |
328 | ||
329 | wxFontRefData::wxFontRefData( CTFontDescriptorRef fontdescriptor, int size ) | |
330 | { | |
331 | if ( size == 0 ) | |
332 | { | |
333 | wxCFRef< CFNumberRef > value( (CFNumberRef) CTFontDescriptorCopyAttribute( fontdescriptor, kCTFontSizeAttribute ) ); | |
8f884a0d | 334 | |
8b534a7b SC |
335 | float fsize; |
336 | if ( CFNumberGetValue( value , kCFNumberFloatType , &fsize ) ) | |
337 | { | |
338 | size = (int) fsize + 0.5 ; | |
339 | } | |
340 | } | |
341 | Init( CTFontCreateWithFontDescriptor(fontdescriptor, size,NULL) ); | |
342 | } | |
343 | ||
344 | void wxFontRefData::Init( CTFontRef font ) | |
345 | { | |
346 | Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, | |
347 | false, wxT("applicationfont"), wxFONTENCODING_DEFAULT); | |
348 | ||
349 | m_ctFont.reset( font ); | |
c07e1e2c | 350 | } |
6239ee05 | 351 | |
1bd568fa | 352 | #endif |
6239ee05 | 353 | |
c07e1e2c SC |
354 | void wxFontRefData::MacFindFont() |
355 | { | |
6239ee05 | 356 | |
c07e1e2c | 357 | #if wxMAC_USE_CORE_TEXT |
b3c1d21c | 358 | if ( UMAGetSystemVersion() >= 0x1050 ) |
e40298d5 | 359 | { |
8b534a7b | 360 | if ( m_faceName.empty() && m_family == wxDEFAULT ) |
c07e1e2c | 361 | { |
8b534a7b | 362 | m_ctFont.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType, 0.0, NULL )); |
c07e1e2c | 363 | } |
8f884a0d | 364 | |
dbe4a80c | 365 | if ( m_ctFont ) |
8f884a0d | 366 | { |
dbe4a80c | 367 | wxCFStringRef name( CTFontCopyFamilyName( m_ctFont ) ); |
c07e1e2c | 368 | m_faceName = name.AsString(); |
c07e1e2c | 369 | m_pointSize = CTFontGetSize(m_ctFont) ; |
8b534a7b SC |
370 | CTFontSymbolicTraits traits = CTFontGetSymbolicTraits( m_ctFont ); |
371 | if ( traits & kCTFontItalicTrait ) | |
372 | m_style = wxITALIC; | |
373 | if ( traits & kCTFontBoldTrait ) | |
374 | m_weight = wxBOLD ; | |
375 | if ( !m_ctFontDescriptor.get() ) | |
376 | m_ctFontDescriptor.reset( CTFontCopyFontDescriptor( m_ctFont ) ); | |
c07e1e2c SC |
377 | } |
378 | else | |
379 | { | |
380 | if ( m_faceName.empty() ) | |
2a0155df SC |
381 | { |
382 | switch ( m_family ) | |
383 | { | |
384 | case wxSCRIPT : | |
385 | case wxROMAN : | |
386 | case wxDECORATIVE : | |
387 | m_faceName = wxT("Times"); | |
388 | break ; | |
8f884a0d | 389 | |
2a0155df SC |
390 | case wxSWISS : |
391 | m_faceName = wxT("Lucida Grande"); | |
392 | break ; | |
8f884a0d | 393 | |
2a0155df | 394 | case wxMODERN : |
d9485f89 | 395 | case wxTELETYPE: |
2a0155df SC |
396 | m_faceName = wxT("Monaco"); |
397 | break ; | |
8f884a0d | 398 | |
2a0155df SC |
399 | default: |
400 | m_faceName = wxT("Times"); | |
401 | break ; | |
402 | } | |
facd6764 | 403 | } |
c07e1e2c | 404 | |
dbe4a80c | 405 | wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() ); |
c07e1e2c | 406 | CTFontSymbolicTraits traits = 0; |
8f884a0d | 407 | |
c07e1e2c SC |
408 | if (m_weight == wxBOLD) |
409 | traits |= kCTFontBoldTrait; | |
410 | if (m_style == wxITALIC || m_style == wxSLANT) | |
411 | traits |= kCTFontItalicTrait; | |
8f884a0d | 412 | |
8b534a7b SC |
413 | m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) ); |
414 | ||
415 | m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) ); | |
facd6764 | 416 | } |
f34105c6 SC |
417 | #if wxMAC_USE_ATSU_TEXT == 0 |
418 | OSStatus status = noErr; | |
419 | CTFontDescriptorRef desc = m_ctFontDescriptor ; | |
420 | ATSFontRef atsfont = CTFontGetPlatformFont( m_ctFont, &desc ); | |
421 | FMFont fmfont = FMGetFontFromATSFontRef( atsfont ); | |
422 | ATSUAttributeTag atsuTags[] = | |
423 | { | |
424 | kATSUFontTag , | |
425 | kATSUSizeTag , | |
426 | kATSUVerticalCharacterTag, | |
427 | kATSUQDBoldfaceTag , | |
428 | kATSUQDItalicTag , | |
429 | kATSUQDUnderlineTag , | |
430 | }; | |
431 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
432 | { | |
433 | sizeof( ATSUFontID ) , | |
434 | sizeof( Fixed ) , | |
435 | sizeof( ATSUVerticalCharacterType), | |
436 | sizeof( Boolean ) , | |
437 | sizeof( Boolean ) , | |
438 | sizeof( Boolean ) , | |
439 | }; | |
440 | Boolean kTrue = true ; | |
441 | Boolean kFalse = false ; | |
8f884a0d | 442 | |
f34105c6 SC |
443 | Fixed atsuSize = IntToFixed( m_pointSize ); |
444 | ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; | |
445 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
446 | { | |
447 | &fmfont , | |
448 | &atsuSize , | |
449 | &kHorizontal, | |
450 | (m_weight == wxBOLD) ? &kTrue : &kFalse , | |
451 | (m_style == wxITALIC || m_style == wxSLANT) ? &kTrue : &kFalse , | |
452 | (m_underlined) ? &kTrue : &kFalse , | |
453 | }; | |
8f884a0d | 454 | |
f34105c6 SC |
455 | if ( m_macATSUStyle ) |
456 | { | |
457 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
458 | m_macATSUStyle = NULL ; | |
459 | } | |
460 | status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); | |
461 | wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); | |
462 | status = ::ATSUSetAttributes( | |
463 | (ATSUStyle)m_macATSUStyle, | |
464 | sizeof(atsuTags) / sizeof(ATSUAttributeTag) , | |
465 | atsuTags, atsuSizes, atsuValues); | |
466 | #endif | |
c07e1e2c SC |
467 | } |
468 | #endif | |
469 | #if wxMAC_USE_ATSU_TEXT | |
470 | { | |
9f4e08ae | 471 | OSStatus status = noErr; |
c07e1e2c SC |
472 | Str255 qdFontName ; |
473 | if ( m_macThemeFontID != kThemeCurrentPortFont ) | |
e40298d5 | 474 | { |
c07e1e2c SC |
475 | Style style ; |
476 | GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &m_macFontSize, &style ); | |
477 | if ( m_macFontSize == 0 ) | |
478 | m_macFontSize = 12; | |
479 | m_macFontStyle = style ; | |
480 | m_faceName = wxMacMakeStringFromPascal( qdFontName ); | |
481 | if ( m_macFontStyle & bold ) | |
482 | m_weight = wxBOLD ; | |
facd6764 | 483 | else |
c07e1e2c SC |
484 | m_weight = wxNORMAL ; |
485 | if ( m_macFontStyle & italic ) | |
486 | m_style = wxITALIC ; | |
487 | if ( m_macFontStyle & underline ) | |
488 | m_underlined = true ; | |
489 | m_pointSize = m_macFontSize ; | |
490 | m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); | |
491 | } | |
492 | else | |
493 | { | |
494 | if ( m_faceName.empty() ) | |
facd6764 | 495 | { |
c07e1e2c | 496 | if ( m_family == wxDEFAULT ) |
dedf5d9f | 497 | { |
dedf5d9f | 498 | m_macFontFamily = GetAppFont(); |
c07e1e2c SC |
499 | FMGetFontFamilyName(m_macFontFamily,qdFontName); |
500 | m_faceName = wxMacMakeStringFromPascal( qdFontName ); | |
501 | } | |
502 | else | |
503 | { | |
504 | switch ( m_family ) | |
505 | { | |
506 | case wxSCRIPT : | |
507 | case wxROMAN : | |
508 | case wxDECORATIVE : | |
509 | m_faceName = wxT("Times"); | |
510 | break ; | |
8f884a0d | 511 | |
c07e1e2c SC |
512 | case wxSWISS : |
513 | m_faceName = wxT("Lucida Grande"); | |
514 | break ; | |
8f884a0d | 515 | |
c07e1e2c SC |
516 | case wxMODERN : |
517 | case wxTELETYPE: | |
518 | m_faceName = wxT("Monaco"); | |
519 | break ; | |
8f884a0d | 520 | |
c07e1e2c SC |
521 | default: |
522 | m_faceName = wxT("Times"); | |
523 | break ; | |
524 | } | |
525 | wxMacStringToPascal( m_faceName , qdFontName ); | |
526 | m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); | |
527 | if ( m_macFontFamily == kInvalidFontFamily ) | |
528 | { | |
529 | wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() ); | |
530 | m_macFontFamily = GetAppFont(); | |
531 | } | |
dedf5d9f | 532 | } |
c07e1e2c SC |
533 | } |
534 | else | |
535 | { | |
536 | if ( m_faceName == wxT("systemfont") ) | |
537 | m_macFontFamily = GetSysFont(); | |
538 | else if ( m_faceName == wxT("applicationfont") ) | |
539 | m_macFontFamily = GetAppFont(); | |
dedf5d9f | 540 | else |
c07e1e2c | 541 | { |
dbe4a80c | 542 | wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() ); |
c07e1e2c SC |
543 | ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault ); |
544 | if ( atsfamily == (ATSFontFamilyRef) -1 ) | |
545 | { | |
546 | wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName ); | |
547 | m_macFontFamily = GetAppFont(); | |
548 | } | |
549 | else | |
550 | m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); | |
551 | } | |
facd6764 | 552 | } |
8f884a0d | 553 | |
c07e1e2c SC |
554 | m_macFontStyle = 0; |
555 | if (m_weight == wxBOLD) | |
556 | m_macFontStyle |= bold; | |
557 | if (m_style == wxITALIC || m_style == wxSLANT) | |
558 | m_macFontStyle |= italic; | |
559 | if (m_underlined) | |
560 | m_macFontStyle |= underline; | |
561 | m_macFontSize = m_pointSize ; | |
e40298d5 | 562 | } |
8f884a0d | 563 | |
c07e1e2c | 564 | // we try to get as much styles as possible into ATSU |
8f884a0d VZ |
565 | |
566 | ||
c07e1e2c SC |
567 | // ATSUFontID and FMFont are equivalent |
568 | FMFontStyle intrinsicStyle = 0 ; | |
569 | status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle); | |
570 | wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); | |
571 | m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle ); | |
8f884a0d | 572 | |
c07e1e2c SC |
573 | if ( m_macATSUStyle ) |
574 | { | |
575 | ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); | |
576 | m_macATSUStyle = NULL ; | |
577 | } | |
8f884a0d | 578 | |
c07e1e2c SC |
579 | status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); |
580 | wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); | |
8f884a0d | 581 | |
c07e1e2c SC |
582 | ATSUAttributeTag atsuTags[] = |
583 | { | |
584 | kATSUFontTag , | |
585 | kATSUSizeTag , | |
586 | kATSUVerticalCharacterTag, | |
587 | kATSUQDBoldfaceTag , | |
588 | kATSUQDItalicTag , | |
589 | kATSUQDUnderlineTag , | |
590 | kATSUQDCondensedTag , | |
591 | kATSUQDExtendedTag , | |
592 | }; | |
593 | ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
594 | { | |
595 | sizeof( ATSUFontID ) , | |
596 | sizeof( Fixed ) , | |
597 | sizeof( ATSUVerticalCharacterType), | |
598 | sizeof( Boolean ) , | |
599 | sizeof( Boolean ) , | |
600 | sizeof( Boolean ) , | |
601 | sizeof( Boolean ) , | |
602 | sizeof( Boolean ) , | |
603 | }; | |
8f884a0d | 604 | |
c07e1e2c SC |
605 | Boolean kTrue = true ; |
606 | Boolean kFalse = false ; | |
8f884a0d | 607 | |
c07e1e2c SC |
608 | Fixed atsuSize = IntToFixed( m_macFontSize ); |
609 | ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; | |
610 | ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = | |
611 | { | |
3e527073 SC |
612 | &m_macATSUFontID , |
613 | &atsuSize , | |
614 | &kHorizontal, | |
615 | (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse , | |
616 | (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse , | |
617 | (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse , | |
618 | (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse , | |
619 | (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse , | |
c07e1e2c | 620 | }; |
8f884a0d | 621 | |
c07e1e2c SC |
622 | status = ::ATSUSetAttributes( |
623 | (ATSUStyle)m_macATSUStyle, | |
624 | sizeof(atsuTags) / sizeof(ATSUAttributeTag) , | |
625 | atsuTags, atsuSizes, atsuValues); | |
8f884a0d | 626 | |
c07e1e2c SC |
627 | wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); |
628 | return; | |
629 | } | |
6239ee05 | 630 | #endif |
519cb848 SC |
631 | } |
632 | ||
e7549107 SC |
633 | // ---------------------------------------------------------------------------- |
634 | // wxFont | |
635 | // ---------------------------------------------------------------------------- | |
e9576ca5 | 636 | |
5b781a67 SC |
637 | bool wxFont::Create(const wxNativeFontInfo& info) |
638 | { | |
6eaa4426 DS |
639 | return Create( |
640 | info.pointSize, info.family, info.style, info.weight, | |
641 | info.underlined, info.faceName, info.encoding ); | |
5b781a67 SC |
642 | } |
643 | ||
3b7e6277 GD |
644 | wxFont::wxFont(const wxString& fontdesc) |
645 | { | |
646 | wxNativeFontInfo info; | |
647 | if ( info.FromString(fontdesc) ) | |
648 | (void)Create(info); | |
649 | } | |
650 | ||
e7549107 | 651 | bool wxFont::Create(int pointSize, |
6eaa4426 DS |
652 | int family, |
653 | int style, | |
654 | int weight, | |
655 | bool underlined, | |
656 | const wxString& faceName, | |
657 | wxFontEncoding encoding) | |
e9576ca5 SC |
658 | { |
659 | UnRef(); | |
6eaa4426 DS |
660 | |
661 | m_refData = new wxFontRefData( | |
662 | pointSize, family, style, weight, | |
663 | underlined, faceName, encoding); | |
e9576ca5 SC |
664 | |
665 | RealizeResource(); | |
666 | ||
6eaa4426 | 667 | return true; |
e9576ca5 SC |
668 | } |
669 | ||
c07e1e2c | 670 | #if wxMAC_USE_CORE_TEXT |
6239ee05 | 671 | |
8b534a7b | 672 | bool wxFont::MacCreateFromUIFont(wxUint32 ctFontType ) |
6239ee05 SC |
673 | { |
674 | UnRef(); | |
675 | ||
8b534a7b | 676 | m_refData = new wxFontRefData(ctFontType); |
6239ee05 SC |
677 | RealizeResource(); |
678 | ||
679 | return true; | |
680 | } | |
681 | ||
8b534a7b SC |
682 | bool wxFont::MacCreateFromCTFontDescriptor( const void * ctFontDescriptor , int size ) |
683 | { | |
684 | UnRef(); | |
8f884a0d | 685 | |
8b534a7b SC |
686 | m_refData = new wxFontRefData((CTFontDescriptorRef)ctFontDescriptor, size);; |
687 | RealizeResource(); | |
8f884a0d | 688 | |
8b534a7b SC |
689 | return true; |
690 | } | |
691 | ||
692 | ||
6239ee05 SC |
693 | #endif |
694 | ||
8b534a7b | 695 | bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID) |
facd6764 | 696 | { |
c07e1e2c | 697 | #if wxMAC_USE_CORE_TEXT |
b3c1d21c | 698 | if ( UMAGetSystemVersion() >= 0x1050) |
c07e1e2c | 699 | { |
8b534a7b | 700 | return MacCreateFromUIFont(HIThemeGetUIFontType(themeFontID)); |
c07e1e2c SC |
701 | } |
702 | #endif | |
9f4e08ae | 703 | #if wxMAC_USE_ATSU_TEXT |
c07e1e2c SC |
704 | { |
705 | UnRef(); | |
6eaa4426 | 706 | |
c07e1e2c SC |
707 | m_refData = new wxFontRefData( |
708 | 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, | |
709 | false, wxEmptyString, wxFONTENCODING_DEFAULT ); | |
facd6764 | 710 | |
c07e1e2c SC |
711 | M_FONTDATA->m_macThemeFontID = themeFontID ; |
712 | RealizeResource(); | |
9f4e08ae | 713 | return true; |
c07e1e2c | 714 | } |
6239ee05 | 715 | #endif |
9f4e08ae | 716 | return false; |
facd6764 SC |
717 | } |
718 | ||
e9576ca5 SC |
719 | wxFont::~wxFont() |
720 | { | |
e9576ca5 SC |
721 | } |
722 | ||
723 | bool wxFont::RealizeResource() | |
724 | { | |
2a0155df | 725 | M_FONTDATA->MacFindFont(); |
6eaa4426 DS |
726 | |
727 | return true; | |
e9576ca5 SC |
728 | } |
729 | ||
51abe921 SC |
730 | void wxFont::SetEncoding(wxFontEncoding encoding) |
731 | { | |
83dcd781 | 732 | Unshare(); |
51abe921 | 733 | |
8b534a7b | 734 | M_FONTDATA->SetEncoding( encoding ); |
51abe921 SC |
735 | |
736 | RealizeResource(); | |
737 | } | |
738 | ||
83dcd781 | 739 | void wxFont::Unshare() |
e9576ca5 | 740 | { |
83dcd781 PC |
741 | // Don't change shared data |
742 | if (!m_refData) | |
743 | { | |
744 | m_refData = new wxFontRefData(); | |
745 | } | |
746 | else | |
747 | { | |
748 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
749 | UnRef(); | |
750 | m_refData = ref; | |
751 | } | |
e9576ca5 SC |
752 | } |
753 | ||
8f884a0d VZ |
754 | wxGDIRefData *wxFont::CreateGDIRefData() const |
755 | { | |
756 | return new wxFontRefData; | |
757 | } | |
758 | ||
759 | wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const | |
760 | { | |
761 | return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data)); | |
762 | } | |
763 | ||
e9576ca5 SC |
764 | void wxFont::SetPointSize(int pointSize) |
765 | { | |
8b534a7b | 766 | if ( M_FONTDATA->GetPointSize() == pointSize ) |
c07e1e2c | 767 | return; |
8f884a0d | 768 | |
83dcd781 | 769 | Unshare(); |
e9576ca5 | 770 | |
8b534a7b | 771 | M_FONTDATA->SetPointSize( pointSize ); |
e9576ca5 SC |
772 | |
773 | RealizeResource(); | |
774 | } | |
775 | ||
776 | void wxFont::SetFamily(int family) | |
777 | { | |
83dcd781 | 778 | Unshare(); |
e9576ca5 | 779 | |
8b534a7b | 780 | M_FONTDATA->SetFamily( family ); |
e9576ca5 SC |
781 | |
782 | RealizeResource(); | |
783 | } | |
784 | ||
785 | void wxFont::SetStyle(int style) | |
786 | { | |
83dcd781 | 787 | Unshare(); |
e9576ca5 | 788 | |
8b534a7b | 789 | M_FONTDATA->SetStyle( style ); |
e9576ca5 SC |
790 | |
791 | RealizeResource(); | |
792 | } | |
793 | ||
794 | void wxFont::SetWeight(int weight) | |
795 | { | |
83dcd781 | 796 | Unshare(); |
e9576ca5 | 797 | |
8b534a7b | 798 | M_FONTDATA->SetWeight( weight ); |
e9576ca5 SC |
799 | |
800 | RealizeResource(); | |
801 | } | |
802 | ||
85ab460e | 803 | bool wxFont::SetFaceName(const wxString& faceName) |
e9576ca5 | 804 | { |
83dcd781 | 805 | Unshare(); |
e9576ca5 | 806 | |
8b534a7b | 807 | M_FONTDATA->SetFaceName( faceName ); |
e9576ca5 SC |
808 | |
809 | RealizeResource(); | |
85ab460e VZ |
810 | |
811 | return wxFontBase::SetFaceName(faceName); | |
e9576ca5 SC |
812 | } |
813 | ||
814 | void wxFont::SetUnderlined(bool underlined) | |
815 | { | |
83dcd781 | 816 | Unshare(); |
e9576ca5 | 817 | |
8b534a7b | 818 | M_FONTDATA->SetUnderlined( underlined ); |
e9576ca5 SC |
819 | |
820 | RealizeResource(); | |
821 | } | |
822 | ||
ac17f9b1 SC |
823 | void wxFont::SetNoAntiAliasing( bool no ) |
824 | { | |
83dcd781 | 825 | Unshare(); |
ac17f9b1 SC |
826 | |
827 | M_FONTDATA->SetNoAntiAliasing( no ); | |
828 | ||
829 | RealizeResource(); | |
830 | } | |
831 | ||
e7549107 SC |
832 | // ---------------------------------------------------------------------------- |
833 | // accessors | |
834 | // ---------------------------------------------------------------------------- | |
835 | ||
fcb35beb VZ |
836 | // TODO: insert checks everywhere for M_FONTDATA == NULL! |
837 | ||
e7549107 | 838 | int wxFont::GetPointSize() const |
e9576ca5 | 839 | { |
77eddfb7 | 840 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 841 | |
8b534a7b | 842 | return M_FONTDATA->GetPointSize(); |
e9576ca5 SC |
843 | } |
844 | ||
ccd67a6a KO |
845 | wxSize wxFont::GetPixelSize() const |
846 | { | |
847 | #if wxUSE_GRAPHICS_CONTEXT | |
848 | // TODO: consider caching the value | |
849 | wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef) NULL); | |
40503c98 | 850 | dc->SetFont(*(wxFont *)this,*wxBLACK); |
ccd67a6a | 851 | wxDouble width, height = 0; |
8a438f46 | 852 | dc->GetTextExtent( wxT("g"), &width, &height, NULL, NULL); |
6239ee05 | 853 | delete dc; |
8a438f46 | 854 | return wxSize((int)width, (int)height); |
ccd67a6a | 855 | #else |
5d465013 | 856 | return wxFontBase::GetPixelSize(); |
ccd67a6a KO |
857 | #endif |
858 | } | |
859 | ||
e7549107 | 860 | int wxFont::GetFamily() const |
e9576ca5 | 861 | { |
77eddfb7 | 862 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 863 | |
8b534a7b | 864 | return M_FONTDATA->GetFamily(); |
e9576ca5 SC |
865 | } |
866 | ||
e7549107 | 867 | int wxFont::GetStyle() const |
e9576ca5 | 868 | { |
77eddfb7 | 869 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 870 | |
8b534a7b | 871 | return M_FONTDATA->GetStyle() ; |
e7549107 SC |
872 | } |
873 | ||
874 | int wxFont::GetWeight() const | |
875 | { | |
77eddfb7 | 876 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 877 | |
8b534a7b | 878 | return M_FONTDATA->GetWeight(); |
e7549107 SC |
879 | } |
880 | ||
881 | bool wxFont::GetUnderlined() const | |
882 | { | |
77eddfb7 | 883 | wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") ); |
6eaa4426 | 884 | |
8b534a7b | 885 | return M_FONTDATA->GetUnderlined(); |
e7549107 SC |
886 | } |
887 | ||
888 | wxString wxFont::GetFaceName() const | |
889 | { | |
facd6764 | 890 | wxCHECK_MSG( M_FONTDATA != NULL , wxEmptyString , wxT("invalid font") ); |
6eaa4426 | 891 | |
8b534a7b | 892 | return M_FONTDATA->GetFaceName() ; |
e7549107 SC |
893 | } |
894 | ||
895 | wxFontEncoding wxFont::GetEncoding() const | |
896 | { | |
facd6764 | 897 | wxCHECK_MSG( M_FONTDATA != NULL , wxFONTENCODING_DEFAULT , wxT("invalid font") ); |
6eaa4426 | 898 | |
8b534a7b | 899 | return M_FONTDATA->GetEncoding() ; |
e9576ca5 SC |
900 | } |
901 | ||
5ac2e80c | 902 | bool wxFont::GetNoAntiAliasing() const |
ac17f9b1 | 903 | { |
77eddfb7 | 904 | wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") ); |
6eaa4426 | 905 | |
8b534a7b | 906 | return M_FONTDATA->GetNoAntiAliasing(); |
ac17f9b1 SC |
907 | } |
908 | ||
c07e1e2c | 909 | #if wxMAC_USE_ATSU_TEXT |
6239ee05 | 910 | |
facd6764 | 911 | short wxFont::MacGetFontNum() const |
fcb35beb | 912 | { |
77eddfb7 | 913 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 914 | |
2a0155df | 915 | return M_FONTDATA->m_macFontFamily; |
fcb35beb VZ |
916 | } |
917 | ||
facd6764 | 918 | short wxFont::MacGetFontSize() const |
fcb35beb | 919 | { |
77eddfb7 | 920 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 921 | |
fcb35beb VZ |
922 | return M_FONTDATA->m_macFontSize; |
923 | } | |
924 | ||
facd6764 | 925 | wxByte wxFont::MacGetFontStyle() const |
fcb35beb | 926 | { |
77eddfb7 | 927 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 928 | |
fcb35beb VZ |
929 | return M_FONTDATA->m_macFontStyle; |
930 | } | |
931 | ||
facd6764 | 932 | wxUint32 wxFont::MacGetATSUFontID() const |
fcb35beb | 933 | { |
77eddfb7 | 934 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 935 | |
fcb35beb VZ |
936 | return M_FONTDATA->m_macATSUFontID; |
937 | } | |
938 | ||
facd6764 SC |
939 | wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const |
940 | { | |
77eddfb7 | 941 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 942 | |
facd6764 SC |
943 | return M_FONTDATA->m_macATSUAdditionalQDStyles; |
944 | } | |
945 | ||
6eaa4426 | 946 | wxUint16 wxFont::MacGetThemeFontID() const |
facd6764 | 947 | { |
77eddfb7 | 948 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6eaa4426 | 949 | |
facd6764 SC |
950 | return M_FONTDATA->m_macThemeFontID; |
951 | } | |
c07e1e2c | 952 | #endif |
6239ee05 | 953 | |
f34105c6 SC |
954 | #if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT |
955 | void * wxFont::MacGetATSUStyle() const | |
956 | { | |
957 | wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); | |
8f884a0d | 958 | |
f34105c6 SC |
959 | return M_FONTDATA->m_macATSUStyle; |
960 | } | |
961 | #endif | |
962 | ||
c07e1e2c | 963 | #if wxMAC_USE_CORE_TEXT |
6239ee05 | 964 | |
c07e1e2c | 965 | const void * wxFont::MacGetCTFont() const |
6239ee05 | 966 | { |
c07e1e2c | 967 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); |
6239ee05 | 968 | |
c07e1e2c | 969 | return (CTFontRef)(M_FONTDATA->m_ctFont); |
6239ee05 SC |
970 | } |
971 | ||
8b534a7b SC |
972 | const void * wxFont::MacGetCTFontDescriptor() const |
973 | { | |
974 | wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); | |
8f884a0d | 975 | |
8b534a7b SC |
976 | return (CTFontDescriptorRef)(M_FONTDATA->m_ctFontDescriptor); |
977 | } | |
978 | ||
6239ee05 | 979 | #endif |
facd6764 | 980 | |
6eaa4426 | 981 | const wxNativeFontInfo * wxFont::GetNativeFontInfo() const |
3bf5a59b | 982 | { |
facd6764 | 983 | wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); |
3bf5a59b VZ |
984 | wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); |
985 | ||
986 | M_FONTDATA->m_info.InitFromFont(*this); | |
987 | ||
988 | return &(M_FONTDATA->m_info); | |
989 | } |