+
+#if wxMAC_USE_CORE_TEXT
+ if ( UMAGetSystemVersion() >= 0x1050 )
+ {
+ if ( m_faceName.empty() && m_family == wxDEFAULT )
+ {
+ m_ctFont.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType, 0.0, NULL ));
+ }
+
+ if ( m_ctFont.get() )
+ {
+ wxMacCFStringHolder name( CTFontCopyFamilyName( m_ctFont ) );
+ m_faceName = name.AsString();
+ m_pointSize = CTFontGetSize(m_ctFont) ;
+ CTFontSymbolicTraits traits = CTFontGetSymbolicTraits( m_ctFont );
+ if ( traits & kCTFontItalicTrait )
+ m_style = wxITALIC;
+ if ( traits & kCTFontBoldTrait )
+ m_weight = wxBOLD ;
+ if ( !m_ctFontDescriptor.get() )
+ m_ctFontDescriptor.reset( CTFontCopyFontDescriptor( m_ctFont ) );
+ }
+ else
+ {
+ if ( m_faceName.empty() )
+ {
+ switch ( m_family )
+ {
+ case wxSCRIPT :
+ case wxROMAN :
+ case wxDECORATIVE :
+ m_faceName = wxT("Times");
+ break ;
+
+ case wxSWISS :
+ m_faceName = wxT("Lucida Grande");
+ break ;
+
+ case wxMODERN :
+ case wxTELETYPE:
+ m_faceName = wxT("Monaco");
+ break ;
+
+ default:
+ m_faceName = wxT("Times");
+ break ;
+ }
+ }
+
+ wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() );
+ CTFontSymbolicTraits traits = 0;
+
+ if (m_weight == wxBOLD)
+ traits |= kCTFontBoldTrait;
+ if (m_style == wxITALIC || m_style == wxSLANT)
+ traits |= kCTFontItalicTrait;
+
+ m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) );
+
+ m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) );
+ }
+#if wxMAC_USE_ATSU_TEXT == 0
+ OSStatus status = noErr;
+ CTFontDescriptorRef desc = m_ctFontDescriptor ;
+ ATSFontRef atsfont = CTFontGetPlatformFont( m_ctFont, &desc );
+ FMFont fmfont = FMGetFontFromATSFontRef( atsfont );
+ ATSUAttributeTag atsuTags[] =
+ {
+ kATSUFontTag ,
+ kATSUSizeTag ,
+ kATSUVerticalCharacterTag,
+ kATSUQDBoldfaceTag ,
+ kATSUQDItalicTag ,
+ kATSUQDUnderlineTag ,
+ };
+ ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+ {
+ sizeof( ATSUFontID ) ,
+ sizeof( Fixed ) ,
+ sizeof( ATSUVerticalCharacterType),
+ sizeof( Boolean ) ,
+ sizeof( Boolean ) ,
+ sizeof( Boolean ) ,
+ };
+ Boolean kTrue = true ;
+ Boolean kFalse = false ;
+
+ Fixed atsuSize = IntToFixed( m_pointSize );
+ ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
+ ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+ {
+ &fmfont ,
+ &atsuSize ,
+ &kHorizontal,
+ (m_weight == wxBOLD) ? &kTrue : &kFalse ,
+ (m_style == wxITALIC || m_style == wxSLANT) ? &kTrue : &kFalse ,
+ (m_underlined) ? &kTrue : &kFalse ,
+ };
+
+ if ( m_macATSUStyle )
+ {
+ ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
+ m_macATSUStyle = NULL ;
+ }
+ status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle);
+ wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") );
+ status = ::ATSUSetAttributes(
+ (ATSUStyle)m_macATSUStyle,
+ sizeof(atsuTags) / sizeof(ATSUAttributeTag) ,
+ atsuTags, atsuSizes, atsuValues);
+#endif
+ }
+#endif
+#if wxMAC_USE_ATSU_TEXT
+ {
+ OSStatus status = noErr;
+ Str255 qdFontName ;
+ if ( m_macThemeFontID != kThemeCurrentPortFont )
+ {
+ Style style ;
+ GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &m_macFontSize, &style );
+ if ( m_macFontSize == 0 )
+ m_macFontSize = 12;
+ m_macFontStyle = style ;
+ m_faceName = wxMacMakeStringFromPascal( qdFontName );
+ if ( m_macFontStyle & bold )
+ m_weight = wxBOLD ;
+ else
+ m_weight = wxNORMAL ;
+ if ( m_macFontStyle & italic )
+ m_style = wxITALIC ;
+ if ( m_macFontStyle & underline )
+ m_underlined = true ;
+ m_pointSize = m_macFontSize ;
+ m_macFontFamily = FMGetFontFamilyFromName( qdFontName );
+ }
+ else
+ {
+ if ( m_faceName.empty() )
+ {
+ if ( m_family == wxDEFAULT )
+ {
+ m_macFontFamily = GetAppFont();
+ FMGetFontFamilyName(m_macFontFamily,qdFontName);
+ m_faceName = wxMacMakeStringFromPascal( qdFontName );
+ }
+ else
+ {
+ switch ( m_family )
+ {
+ case wxSCRIPT :
+ case wxROMAN :
+ case wxDECORATIVE :
+ m_faceName = wxT("Times");
+ break ;
+
+ case wxSWISS :
+ m_faceName = wxT("Lucida Grande");
+ break ;
+
+ case wxMODERN :
+ case wxTELETYPE:
+ m_faceName = wxT("Monaco");
+ break ;
+
+ default:
+ m_faceName = wxT("Times");
+ break ;
+ }
+ wxMacStringToPascal( m_faceName , qdFontName );
+ m_macFontFamily = FMGetFontFamilyFromName( qdFontName );
+ if ( m_macFontFamily == kInvalidFontFamily )
+ {
+ wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() );
+ m_macFontFamily = GetAppFont();
+ }
+ }
+ }
+ else
+ {
+ if ( m_faceName == wxT("systemfont") )
+ m_macFontFamily = GetSysFont();
+ else if ( m_faceName == wxT("applicationfont") )
+ m_macFontFamily = GetAppFont();
+ else
+ {
+ wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() );
+ ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault );
+ if ( atsfamily == (ATSFontFamilyRef) -1 )
+ {
+ wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName );
+ m_macFontFamily = GetAppFont();
+ }
+ else
+ m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily );
+ }
+ }
+
+ m_macFontStyle = 0;
+ if (m_weight == wxBOLD)
+ m_macFontStyle |= bold;
+ if (m_style == wxITALIC || m_style == wxSLANT)
+ m_macFontStyle |= italic;
+ if (m_underlined)
+ m_macFontStyle |= underline;
+ m_macFontSize = m_pointSize ;
+ }
+
+ // we try to get as much styles as possible into ATSU
+
+
+ // ATSUFontID and FMFont are equivalent
+ FMFontStyle intrinsicStyle = 0 ;
+ status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle);
+ wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") );
+ m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle );
+
+ if ( m_macATSUStyle )
+ {
+ ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
+ m_macATSUStyle = NULL ;
+ }
+
+ status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle);
+ wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") );
+
+ ATSUAttributeTag atsuTags[] =
+ {
+ kATSUFontTag ,
+ kATSUSizeTag ,
+ kATSUVerticalCharacterTag,
+ kATSUQDBoldfaceTag ,
+ kATSUQDItalicTag ,
+ kATSUQDUnderlineTag ,
+ kATSUQDCondensedTag ,
+ kATSUQDExtendedTag ,
+ };
+ ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+ {
+ sizeof( ATSUFontID ) ,
+ sizeof( Fixed ) ,
+ sizeof( ATSUVerticalCharacterType),
+ sizeof( Boolean ) ,
+ sizeof( Boolean ) ,
+ sizeof( Boolean ) ,
+ sizeof( Boolean ) ,
+ sizeof( Boolean ) ,
+ };
+
+ Boolean kTrue = true ;
+ Boolean kFalse = false ;
+
+ Fixed atsuSize = IntToFixed( m_macFontSize );
+ ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
+ ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
+ {
+ &m_macATSUFontID ,
+ &atsuSize ,
+ &kHorizontal,
+ (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse ,
+ (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse ,
+ (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse ,
+ (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse ,
+ (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse ,
+ };
+
+ status = ::ATSUSetAttributes(
+ (ATSUStyle)m_macATSUStyle,
+ sizeof(atsuTags) / sizeof(ATSUAttributeTag) ,
+ atsuTags, atsuSizes, atsuValues);
+
+ wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") );
+ return;
+ }