1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/font.cpp
3 // Purpose: wxFont class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/string.h"
20 #include "wx/gdicmn.h"
24 #include "wx/fontutil.h"
25 #include "wx/graphics.h"
26 #include "wx/settings.h"
28 #include "wx/osx/private.h"
30 #if wxOSX_USE_ATSU_TEXT && !wxOSX_USE_CARBON
31 // include themeing support
32 #include <Carbon/Carbon.h>
38 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
41 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
46 Init(10, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
47 false, wxT("applicationfont"), wxFONTENCODING_DEFAULT
);
50 wxFontRefData(const wxFontRefData
& data
)
52 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
53 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
56 wxFontRefData(int size
,
61 const wxString
& faceName
,
62 wxFontEncoding encoding
)
64 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
67 #if wxOSX_USE_CORE_TEXT
68 wxFontRefData( wxUint32 coreTextFontType
);
69 wxFontRefData( CTFontRef font
);
70 wxFontRefData( CTFontDescriptorRef fontdescriptor
, int size
);
73 virtual ~wxFontRefData();
75 void SetNoAntiAliasing( bool no
= true ) { m_noAA
= no
; }
77 bool GetNoAntiAliasing() const { return m_noAA
; }
79 void SetPointSize( int size
)
82 MacInvalidateNativeFont();
85 int GetPointSize() const { return m_pointSize
; }
87 void SetFamily( wxFontFamily family
)
90 MacInvalidateNativeFont();
94 wxFontFamily
GetFamily() const { return m_family
; }
96 void SetStyle( wxFontStyle style
)
99 MacInvalidateNativeFont();
103 wxFontStyle
GetStyle() const { return m_style
; }
105 void SetWeight( wxFontWeight weight
)
108 MacInvalidateNativeFont();
112 wxFontWeight
GetWeight() const { return m_weight
; }
114 void SetUnderlined( bool u
)
117 MacInvalidateNativeFont();
120 bool GetUnderlined() const { return m_underlined
; }
122 void SetFaceName( const wxString
& facename
)
124 m_faceName
= facename
;
125 MacInvalidateNativeFont();
128 const wxString
& GetFaceName() const { return m_faceName
; }
130 void SetEncoding( wxFontEncoding encoding
)
132 m_encoding
= encoding
;
133 MacInvalidateNativeFont();
136 wxFontEncoding
GetEncoding() const { return m_encoding
; }
138 void MacInvalidateNativeFont();
143 // common part of all ctors
149 const wxString
& faceName
,
150 wxFontEncoding encoding
);
152 #if wxOSX_USE_CORE_TEXT
153 void Init( CTFontRef font
);
155 // font characterstics
157 wxFontFamily m_family
;
159 wxFontWeight m_weight
;
162 wxFontEncoding m_encoding
;
163 bool m_noAA
; // No anti-aliasing
166 #if wxOSX_USE_ATSU_TEXT
167 FMFontFamily m_macFontFamily
;
168 FMFontSize m_macFontSize
;
169 FMFontStyle m_macFontStyle
;
171 // ATSU Font Information
173 // this is split into an ATSU font id that may
174 // contain some styles (special bold fonts etc) and
175 // these are the additional qd styles that are not
176 // included in the ATSU font id
177 ATSUFontID m_macATSUFontID
;
178 FMFontStyle m_macATSUAdditionalQDStyles
;
180 // for true themeing support we must store the correct font
181 // information here, as this speeds up and optimizes rendering
182 ThemeFontID m_macThemeFontID
;
184 #if wxOSX_USE_CORE_TEXT
185 wxCFRef
<CTFontRef
> m_ctFont
;
187 #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
188 ATSUStyle m_macATSUStyle
;
190 wxNativeFontInfo m_info
;
193 #define M_FONTDATA ((wxFontRefData*)m_refData)
196 // ============================================================================
198 // ============================================================================
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void wxFontRefData::Init(int pointSize
,
209 const wxString
& faceName
,
210 wxFontEncoding encoding
)
213 m_pointSize
= (pointSize
== -1) ? wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
).GetPointSize() : pointSize
;
217 m_underlined
= underlined
;
218 m_faceName
= faceName
;
219 m_encoding
= encoding
;
221 #if wxOSX_USE_ATSU_TEXT
222 m_macFontFamily
= 0 ;
226 m_macATSUAdditionalQDStyles
= 0 ;
227 m_macThemeFontID
= kThemeCurrentPortFont
;
229 #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
230 m_macATSUStyle
= NULL
;
234 wxFontRefData::~wxFontRefData()
236 #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
237 if ( m_macATSUStyle
)
239 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUStyle
);
240 m_macATSUStyle
= NULL
;
245 void wxFontRefData::MacInvalidateNativeFont()
247 #if wxOSX_USE_CORE_TEXT
250 #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
251 if ( m_macATSUStyle
)
253 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUStyle
);
254 m_macATSUStyle
= NULL
;
259 #if wxOSX_USE_CORE_TEXT
261 /* from Core Text Manual Common Operations */
263 static CTFontDescriptorRef
wxMacCreateCTFontDescriptor(CFStringRef iFamilyName
, CTFontSymbolicTraits iTraits
)
265 CTFontDescriptorRef descriptor
= NULL
;
266 CFMutableDictionaryRef attributes
;
268 assert(iFamilyName
!= NULL
);
269 // Create a mutable dictionary to hold our attributes.
270 attributes
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
271 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
272 check(attributes
!= NULL
);
274 if (attributes
!= NULL
) {
275 // Add a family name to our attributes.
276 CFDictionaryAddValue(attributes
, kCTFontFamilyNameAttribute
, iFamilyName
);
280 CFMutableDictionaryRef traits
;
281 CFNumberRef symTraits
;
283 // Create the traits dictionary.
284 symTraits
= CFNumberCreate(kCFAllocatorDefault
, kCFNumberSInt32Type
,
286 check(symTraits
!= NULL
);
288 if (symTraits
!= NULL
) {
289 // Create a dictionary to hold our traits values.
290 traits
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
291 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
292 check(traits
!= NULL
);
294 if (traits
!= NULL
) {
295 // Add the symbolic traits value to the traits dictionary.
296 CFDictionaryAddValue(traits
, kCTFontSymbolicTrait
, symTraits
);
298 // Add the traits attribute to our attributes.
299 CFDictionaryAddValue(attributes
, kCTFontTraitsAttribute
, traits
);
302 CFRelease(symTraits
);
305 // Create the font descriptor with our attributes
306 descriptor
= CTFontDescriptorCreateWithAttributes(attributes
);
307 check(descriptor
!= NULL
);
309 CFRelease(attributes
);
311 // Return our font descriptor.
315 wxFontRefData::wxFontRefData( wxUint32 coreTextFontType
)
317 CTFontRef font
= CTFontCreateUIFontForLanguage( coreTextFontType
, 0.0, NULL
) ;
318 if ( CTFontGetSize(font
) == 0 )
321 font
= CTFontCreateUIFontForLanguage( coreTextFontType
, 12.0, NULL
);
326 wxFontRefData::wxFontRefData( CTFontRef font
)
331 wxFontRefData::wxFontRefData( CTFontDescriptorRef fontdescriptor
, int size
)
335 wxCFRef
< CFNumberRef
> value( (CFNumberRef
) CTFontDescriptorCopyAttribute( fontdescriptor
, kCTFontSizeAttribute
) );
338 if ( CFNumberGetValue( value
, kCFNumberFloatType
, &fsize
) )
340 size
= (int)( fsize
+ 0.5 );
343 Init( CTFontCreateWithFontDescriptor(fontdescriptor
, size
,NULL
) );
346 void wxFontRefData::Init( CTFontRef font
)
348 Init(10, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
349 false, wxT("applicationfont"), wxFONTENCODING_DEFAULT
);
351 m_ctFont
.reset( font
);
356 void wxFontRefData::MacFindFont()
359 #if wxOSX_USE_CORE_TEXT
360 if ( UMAGetSystemVersion() >= 0x1050 )
362 if ( m_faceName
.empty() && m_family
== wxFONTFAMILY_DEFAULT
)
364 m_ctFont
.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType
, 0.0, NULL
));
369 wxCFStringRef
name( CTFontCopyFamilyName( m_ctFont
) );
370 m_faceName
= name
.AsString();
371 m_pointSize
= CTFontGetSize(m_ctFont
) ;
372 CTFontSymbolicTraits traits
= CTFontGetSymbolicTraits( m_ctFont
);
373 if ( traits
& kCTFontItalicTrait
)
374 m_style
= wxFONTSTYLE_ITALIC
;
375 if ( traits
& kCTFontBoldTrait
)
376 m_weight
= wxFONTWEIGHT_BOLD
;
380 if ( m_faceName
.empty() )
384 case wxFONTFAMILY_SCRIPT
:
385 case wxFONTFAMILY_ROMAN
:
386 case wxFONTFAMILY_DECORATIVE
:
387 m_faceName
= wxT("Times");
390 case wxFONTFAMILY_SWISS
:
391 m_faceName
= wxT("Helvetica");
394 case wxFONTFAMILY_MODERN
:
395 case wxFONTFAMILY_TELETYPE
:
396 m_faceName
= wxT("Courier");
397 if ( m_style
== wxFONTFAMILY_ITALIC
&& m_weight
== wxFONTFAMILY_NORMAL
)
399 m_style
= wxFONTFAMILY_ITALIC
;
404 m_faceName
= wxT("Times");
410 CTFontSymbolicTraits traits
= 0;
412 if (m_weight
== wxFONTWEIGHT_BOLD
)
413 traits
|= kCTFontBoldTrait
;
414 if (m_style
== wxFONTSTYLE_ITALIC
|| m_style
== wxFONTSTYLE_SLANT
)
415 traits
|= kCTFontItalicTrait
;
418 wxString lookupnameWithSize
= wxString::Format( "%s_%ld_%ld", m_faceName
.c_str(), traits
, m_pointSize
);
420 static std::map
< std::wstring
, wxCFRef
< CTFontRef
> > fontcache
;
421 m_ctFont
= fontcache
[ std::wstring(lookupnameWithSize
.wc_str()) ];
424 // QD selection algorithm is the fastest by orders of magnitude on 10.5
425 if ( m_faceName
.IsAscii() )
428 if (m_weight
== wxFONTWEIGHT_BOLD
)
430 if (m_style
== wxFONTSTYLE_ITALIC
|| m_style
== wxFONTSTYLE_SLANT
)
434 wxMacStringToPascal( m_faceName
, qdFontName
);
435 m_ctFont
.reset( CTFontCreateWithQuickdrawInstance(qdFontName
, 0 , qdstyle
, m_pointSize
) );
440 static std::map
< std::wstring
, wxCFRef
< CTFontDescriptorRef
> > fontdescriptorcache
;
441 wxString lookupname
= wxString::Format( "%s_%ld", m_faceName
.c_str(), traits
);
442 // descriptor caching
443 wxCFRef
< CTFontDescriptorRef
> descriptor
= fontdescriptorcache
[ std::wstring(lookupname
.wc_str()) ];
446 wxCFStringRef
cf( m_faceName
, wxLocale::GetSystemEncoding() );
447 descriptor
.reset( wxMacCreateCTFontDescriptor( cf
, traits
) );
448 fontdescriptorcache
[ std::wstring(lookupname
.wc_str()) ] = descriptor
;
450 m_ctFont
.reset( CTFontCreateWithFontDescriptor( descriptor
, m_pointSize
, NULL
) );
451 CTFontSymbolicTraits received
= CTFontGetSymbolicTraits( m_ctFont
) & 0x03;
452 if ( traits
!= received
)
454 // TODO further fallbacks, synthesizing bold and italic, trying direct PostScript names etc
458 fontcache
[ std::wstring(lookupnameWithSize
.wc_str()) ] = m_ctFont
;
459 #if 1 // debugging coretext font matching
460 CTFontSymbolicTraits received
= CTFontGetSymbolicTraits( m_ctFont
) & 0x03;
461 if ( received
!= traits
)
463 float angle
= CTFontGetSlantAngle( m_ctFont
);
464 CFDictionaryRef dict
= CTFontCopyTraits( m_ctFont
);
465 CFNumberRef number
= (CFNumberRef
) CFDictionaryGetValue(dict
, kCTFontWeightTrait
);
467 CFNumberGetValue( number
, kCFNumberFloatType
, &floatnumber
);
469 wxString msg
= wxString::Format( "font %s expected %d but got %d traits, %f angle \n" ,
470 m_faceName
.c_str(), traits
, received
, angle
);
471 printf( msg
.c_str() );
480 #if wxOSX_USE_ATSU_TEXT
481 OSStatus status
= noErr
;
482 ATSFontRef atsfont
= CTFontGetPlatformFont( m_ctFont
, NULL
);
483 FMFont fmfont
= FMGetFontFromATSFontRef( atsfont
);
484 ATSUAttributeTag atsuTags
[] =
488 kATSUVerticalCharacterTag
,
491 kATSUQDUnderlineTag
,
493 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
495 sizeof( ATSUFontID
) ,
497 sizeof( ATSUVerticalCharacterType
),
502 Boolean kTrue
= true ;
503 Boolean kFalse
= false ;
505 Fixed atsuSize
= IntToFixed( m_pointSize
);
506 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
507 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
512 (m_weight
== wxFONTWEIGHT_BOLD
) ? &kTrue
: &kFalse
,
513 (m_style
== wxFONTSTYLE_ITALIC
|| m_style
== wxFONTSTYLE_SLANT
) ? &kTrue
: &kFalse
,
514 (m_underlined
) ? &kTrue
: &kFalse
,
517 if ( m_macATSUStyle
)
519 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUStyle
);
520 m_macATSUStyle
= NULL
;
522 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUStyle
);
523 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
524 status
= ::ATSUSetAttributes(
525 (ATSUStyle
)m_macATSUStyle
,
526 sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
527 atsuTags
, atsuSizes
, atsuValues
);
531 #if wxOSX_USE_ATSU_TEXT
533 OSStatus status
= noErr
;
535 if ( m_macThemeFontID
!= kThemeCurrentPortFont
)
538 GetThemeFont( m_macThemeFontID
, GetApplicationScript(), qdFontName
, &m_macFontSize
, &style
);
539 if ( m_macFontSize
== 0 )
541 m_macFontStyle
= style
;
542 m_faceName
= wxMacMakeStringFromPascal( qdFontName
);
543 if ( m_macFontStyle
& bold
)
544 m_weight
= wxFONTWEIGHT_BOLD
;
546 m_weight
= wxFONTWEIGHT_NORMAL
;
547 if ( m_macFontStyle
& italic
)
548 m_style
= wxFONTSTYLE_ITALIC
;
549 if ( m_macFontStyle
& underline
)
550 m_underlined
= true ;
551 m_pointSize
= m_macFontSize
;
552 m_macFontFamily
= FMGetFontFamilyFromName( qdFontName
);
556 if ( m_faceName
.empty() )
558 if ( m_family
== wxFONTFAMILY_DEFAULT
)
560 m_macFontFamily
= GetAppFont();
561 FMGetFontFamilyName(m_macFontFamily
,qdFontName
);
562 m_faceName
= wxMacMakeStringFromPascal( qdFontName
);
568 case wxFONTFAMILY_SCRIPT
:
569 case wxFONTFAMILY_ROMAN
:
570 case wxFONTFAMILY_DECORATIVE
:
571 m_faceName
= wxT("Times");
574 case wxFONTFAMILY_SWISS
:
575 m_faceName
= wxT("Helvetica");
578 case wxFONTFAMILY_MODERN
:
579 case wxFONTFAMILY_TELETYPE
:
580 m_faceName
= wxT("Courier");
584 m_faceName
= wxT("Times");
587 wxMacStringToPascal( m_faceName
, qdFontName
);
588 m_macFontFamily
= FMGetFontFamilyFromName( qdFontName
);
589 if ( m_macFontFamily
== kInvalidFontFamily
)
591 wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName
.c_str() );
592 m_macFontFamily
= GetAppFont();
598 if ( m_faceName
== wxT("systemfont") )
599 m_macFontFamily
= GetSysFont();
600 else if ( m_faceName
== wxT("applicationfont") )
601 m_macFontFamily
= GetAppFont();
604 wxCFStringRef
cf( m_faceName
, wxLocale::GetSystemEncoding() );
605 ATSFontFamilyRef atsfamily
= ATSFontFamilyFindFromName( cf
, kATSOptionFlagsDefault
);
606 if ( atsfamily
== (ATSFontFamilyRef
) -1 )
608 wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName
);
609 m_macFontFamily
= GetAppFont();
612 m_macFontFamily
= FMGetFontFamilyFromATSFontFamilyRef( atsfamily
);
617 if (m_weight
== wxFONTWEIGHT_BOLD
)
618 m_macFontStyle
|= bold
;
619 if (m_style
== wxFONTSTYLE_ITALIC
|| m_style
== wxFONTSTYLE_SLANT
)
620 m_macFontStyle
|= italic
;
622 m_macFontStyle
|= underline
;
623 m_macFontSize
= m_pointSize
;
626 // we try to get as much styles as possible into ATSU
629 // ATSUFontID and FMFont are equivalent
630 FMFontStyle intrinsicStyle
= 0 ;
631 status
= FMGetFontFromFontFamilyInstance( m_macFontFamily
, m_macFontStyle
, &m_macATSUFontID
, &intrinsicStyle
);
632 wxASSERT_MSG( status
== noErr
, wxT("couldn't get an ATSUFont from font family") );
633 m_macATSUAdditionalQDStyles
= m_macFontStyle
& (~intrinsicStyle
);
635 if ( m_macATSUStyle
)
637 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUStyle
);
638 m_macATSUStyle
= NULL
;
641 status
= ::ATSUCreateStyle((ATSUStyle
*)&m_macATSUStyle
);
642 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
644 ATSUAttributeTag atsuTags
[] =
648 kATSUVerticalCharacterTag
,
651 kATSUQDUnderlineTag
,
652 kATSUQDCondensedTag
,
655 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
657 sizeof( ATSUFontID
) ,
659 sizeof( ATSUVerticalCharacterType
),
667 Boolean kTrue
= true ;
668 Boolean kFalse
= false ;
670 Fixed atsuSize
= IntToFixed( m_macFontSize
);
671 ATSUVerticalCharacterType kHorizontal
= kATSUStronglyHorizontal
;
672 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
677 (m_macATSUAdditionalQDStyles
& bold
) ? &kTrue
: &kFalse
,
678 (m_macATSUAdditionalQDStyles
& italic
) ? &kTrue
: &kFalse
,
679 (m_macATSUAdditionalQDStyles
& underline
) ? &kTrue
: &kFalse
,
680 (m_macATSUAdditionalQDStyles
& condense
) ? &kTrue
: &kFalse
,
681 (m_macATSUAdditionalQDStyles
& extend
) ? &kTrue
: &kFalse
,
684 status
= ::ATSUSetAttributes(
685 (ATSUStyle
)m_macATSUStyle
,
686 sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
687 atsuTags
, atsuSizes
, atsuValues
);
689 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
695 // ----------------------------------------------------------------------------
697 // ----------------------------------------------------------------------------
699 bool wxFont::Create(const wxNativeFontInfo
& info
)
702 info
.pointSize
, info
.family
, info
.style
, info
.weight
,
703 info
.underlined
, info
.faceName
, info
.encoding
);
706 wxFont::wxFont(const wxString
& fontdesc
)
708 wxNativeFontInfo info
;
709 if ( info
.FromString(fontdesc
) )
713 bool wxFont::Create(int pointSize
,
718 const wxString
& faceName
,
719 wxFontEncoding encoding
)
723 m_refData
= new wxFontRefData(
724 pointSize
, family
, style
, weight
,
725 underlined
, faceName
, encoding
);
732 #if wxOSX_USE_CORE_TEXT
734 bool wxFont::MacCreateFromUIFont(wxUint32 ctFontType
)
738 m_refData
= new wxFontRefData(ctFontType
);
744 bool wxFont::MacCreateFromCTFontDescriptor( const void * ctFontDescriptor
, int size
)
748 m_refData
= new wxFontRefData((CTFontDescriptorRef
)ctFontDescriptor
, size
);;
758 bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID
)
760 #if wxOSX_USE_CORE_TEXT
761 if ( UMAGetSystemVersion() >= 0x1050)
763 return MacCreateFromUIFont(HIThemeGetUIFontType(themeFontID
));
766 #if wxOSX_USE_ATSU_TEXT
770 m_refData
= new wxFontRefData(
771 12, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
772 false, wxEmptyString
, wxFONTENCODING_DEFAULT
);
774 M_FONTDATA
->m_macThemeFontID
= themeFontID
;
787 bool wxFont::RealizeResource()
789 M_FONTDATA
->MacFindFont();
794 void wxFont::SetEncoding(wxFontEncoding encoding
)
798 M_FONTDATA
->SetEncoding( encoding
);
803 void wxFont::Unshare()
805 // Don't change shared data
808 m_refData
= new wxFontRefData();
812 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
818 wxGDIRefData
*wxFont::CreateGDIRefData() const
820 return new wxFontRefData
;
823 wxGDIRefData
*wxFont::CloneGDIRefData(const wxGDIRefData
*data
) const
825 return new wxFontRefData(*static_cast<const wxFontRefData
*>(data
));
828 void wxFont::SetPointSize(int pointSize
)
830 if ( M_FONTDATA
->GetPointSize() == pointSize
)
835 M_FONTDATA
->SetPointSize( pointSize
);
840 void wxFont::SetFamily(wxFontFamily family
)
844 M_FONTDATA
->SetFamily( family
);
849 void wxFont::SetStyle(wxFontStyle style
)
853 M_FONTDATA
->SetStyle( style
);
858 void wxFont::SetWeight(wxFontWeight weight
)
862 M_FONTDATA
->SetWeight( weight
);
867 bool wxFont::SetFaceName(const wxString
& faceName
)
871 M_FONTDATA
->SetFaceName( faceName
);
875 return wxFontBase::SetFaceName(faceName
);
878 void wxFont::SetUnderlined(bool underlined
)
882 M_FONTDATA
->SetUnderlined( underlined
);
887 void wxFont::SetNoAntiAliasing( bool no
)
891 M_FONTDATA
->SetNoAntiAliasing( no
);
896 // ----------------------------------------------------------------------------
898 // ----------------------------------------------------------------------------
900 // TODO: insert checks everywhere for M_FONTDATA == NULL!
902 int wxFont::GetPointSize() const
904 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
906 return M_FONTDATA
->GetPointSize();
909 wxSize
wxFont::GetPixelSize() const
911 #if wxUSE_GRAPHICS_CONTEXT
912 // TODO: consider caching the value
913 wxGraphicsContext
* dc
= wxGraphicsContext::CreateFromNative((CGContextRef
) NULL
);
914 dc
->SetFont(*(wxFont
*)this,*wxBLACK
);
915 wxDouble width
, height
= 0;
916 dc
->GetTextExtent( wxT("g"), &width
, &height
, NULL
, NULL
);
918 return wxSize((int)width
, (int)height
);
920 return wxFontBase::GetPixelSize();
924 wxFontFamily
wxFont::GetFamily() const
926 wxCHECK_MSG( M_FONTDATA
!= NULL
, wxFONTFAMILY_MAX
, wxT("invalid font") );
928 return M_FONTDATA
->GetFamily();
931 wxFontStyle
wxFont::GetStyle() const
933 wxCHECK_MSG( M_FONTDATA
!= NULL
, wxFONTSTYLE_MAX
, wxT("invalid font") );
935 return M_FONTDATA
->GetStyle() ;
938 wxFontWeight
wxFont::GetWeight() const
940 wxCHECK_MSG( M_FONTDATA
!= NULL
, wxFONTWEIGHT_MAX
, wxT("invalid font") );
942 return M_FONTDATA
->GetWeight();
945 bool wxFont::GetUnderlined() const
947 wxCHECK_MSG( M_FONTDATA
!= NULL
, false, wxT("invalid font") );
949 return M_FONTDATA
->GetUnderlined();
952 wxString
wxFont::GetFaceName() const
954 wxCHECK_MSG( M_FONTDATA
!= NULL
, wxEmptyString
, wxT("invalid font") );
956 return M_FONTDATA
->GetFaceName() ;
959 wxFontEncoding
wxFont::GetEncoding() const
961 wxCHECK_MSG( M_FONTDATA
!= NULL
, wxFONTENCODING_DEFAULT
, wxT("invalid font") );
963 return M_FONTDATA
->GetEncoding() ;
966 bool wxFont::GetNoAntiAliasing() const
968 wxCHECK_MSG( M_FONTDATA
!= NULL
, false, wxT("invalid font") );
970 return M_FONTDATA
->GetNoAntiAliasing();
973 #if wxOSX_USE_ATSU_TEXT
975 short wxFont::MacGetFontNum() const
977 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
979 return M_FONTDATA
->m_macFontFamily
;
982 short wxFont::MacGetFontSize() const
984 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
986 return M_FONTDATA
->m_macFontSize
;
989 wxByte
wxFont::MacGetFontStyle() const
991 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
993 return M_FONTDATA
->m_macFontStyle
;
996 wxUint32
wxFont::MacGetATSUFontID() const
998 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
1000 return M_FONTDATA
->m_macATSUFontID
;
1003 wxUint32
wxFont::MacGetATSUAdditionalQDStyles() const
1005 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
1007 return M_FONTDATA
->m_macATSUAdditionalQDStyles
;
1010 wxUint16
wxFont::MacGetThemeFontID() const
1012 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
1014 return M_FONTDATA
->m_macThemeFontID
;
1018 #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
1019 void * wxFont::MacGetATSUStyle() const
1021 wxCHECK_MSG( M_FONTDATA
!= NULL
, NULL
, wxT("invalid font") );
1023 return M_FONTDATA
->m_macATSUStyle
;
1027 #if wxOSX_USE_CORE_TEXT
1029 const void * wxFont::MacGetCTFont() const
1031 wxCHECK_MSG( M_FONTDATA
!= NULL
, 0, wxT("invalid font") );
1033 return (CTFontRef
)(M_FONTDATA
->m_ctFont
);
1038 const wxNativeFontInfo
* wxFont::GetNativeFontInfo() const
1040 wxCHECK_MSG( M_FONTDATA
!= NULL
, NULL
, wxT("invalid font") );
1041 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
1043 M_FONTDATA
->m_info
.InitFromFont(*this);
1045 return &(M_FONTDATA
->m_info
);