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