-
- CTFontSymbolicTraits traits = 0;
-
- if (m_weight == wxBOLD)
- traits |= kCTFontBoldTrait;
- if (m_style == wxITALIC || m_style == wxSLANT)
- traits |= kCTFontItalicTrait;
-
-// use font descriptor caching
-#if 0
- 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 0
- 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 ( /* (CTFontGetSymbolicTraits( m_ctFont ) & 0x03) !=*/ traits )
- {
- CTFontRef font = CTFontCreateWithName( cf, m_pointSize, NULL );
- CTFontRef font2 = CTFontCreateCopyWithSymbolicTraits( font, m_pointSize, NULL, traits, 0x03 );
- CFRelease(font);
- m_ctFont.reset( font2 );
- if ( (CTFontGetSymbolicTraits( m_ctFont ) & 0x03) != traits )
- {
- wxMessageBox( wxString::Format( "expected %d but got %d traits" , traits, (CTFontGetSymbolicTraits( m_ctFont ) & 0x03) ) );
- }
- }
- }
-#if wxOSX_USE_ATSU_TEXT
- 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 wxOSX_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