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