- if( m_faceName == "" )
- {
- switch( m_family )
- {
- case wxDEFAULT :
- m_macFontNum = ::GetAppFont() ;
- break ;
- case wxDECORATIVE :
- ::GetFNum( "\pTimes" , &m_macFontNum) ;
- break ;
- case wxROMAN :
- ::GetFNum( "\pTimes" , &m_macFontNum) ;
- break ;
- case wxSCRIPT :
- ::GetFNum( "\pTimes" , &m_macFontNum) ;
- break ;
- case wxSWISS :
- ::GetFNum( "\pGeneva" , &m_macFontNum) ;
- break ;
- case wxMODERN :
- ::GetFNum( "\pMonaco" , &m_macFontNum) ;
- break ;
- }
- Str255 name ;
- GetFontName( m_macFontNum , name ) ;
- CopyPascalStringToC( name , (char*) name ) ;
- m_faceName = (char*) name ;
- }
- else
- {
- if ( m_faceName == "systemfont" )
- m_macFontNum = ::GetSysFont() ;
- else if ( m_faceName == "applicationfont" )
- m_macFontNum = ::GetAppFont() ;
- else
- {
- Str255 fontname ;
- wxMacStringToPascal( m_faceName , fontname ) ;
- ::GetFNum( fontname, &m_macFontNum);
- }
- }
-
- 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 ;
-
- //TODO:if we supply the style as an additional parameter we must make a testing
- //sequence in order to degrade gracefully while trying to maintain most of the style
- //information, meanwhile we just take the normal font and apply the features after
- OSStatus status = ::ATSUFONDtoFontID(m_macFontNum, normal /*qdStyle*/, (UInt32*)&m_macATSUFontID);
- /*
- status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
- kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
- */
- wxASSERT_MSG( status == noErr , "couldn't retrieve font identifier" ) ;
+
+#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 )
+ {
+ wxCFStringRef 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 ;
+ }
+ }
+
+
+ CTFontSymbolicTraits traits = 0;
+
+ if (m_weight == wxBOLD)
+ traits |= kCTFontBoldTrait;
+ if (m_style == wxITALIC || m_style == wxSLANT)
+ traits |= kCTFontItalicTrait;
+
+// use font descriptor caching
+#if 1
+ wxString lookupname = wxString::Format( "%s_%ld", m_faceName.c_str(), traits );
+
+ static std::map< std::wstring , wxCFRef< CTFontDescriptorRef > > fontdescriptorcache ;
+
+ m_ctFontDescriptor = fontdescriptorcache[ std::wstring(lookupname.wc_str()) ];
+ if ( !m_ctFontDescriptor )
+ {
+ wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
+ m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) );
+ fontdescriptorcache[ std::wstring(lookupname.wc_str()) ] = m_ctFontDescriptor;
+ }
+#else
+ wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
+ m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) );
+#endif
+
+// use font caching
+#if 1
+ wxString lookupnameWithSize = wxString::Format( "%s_%ld_%ld", m_faceName.c_str(), traits, m_pointSize );
+
+ static std::map< std::wstring , wxCFRef< CTFontRef > > fontcache ;
+ m_ctFont = fontcache[ std::wstring(lookupnameWithSize.wc_str()) ];
+ if ( !m_ctFont )
+ {
+ m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) );
+ fontcache[ std::wstring(lookupnameWithSize.wc_str()) ] = m_ctFont;
+ }
+#else
+ m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) );
+#endif
+ }
+#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
+ {
+ wxCFStringRef 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;
+ }
+#endif