From 9445de1e4f04424a97904c1610c8d117726ef8d8 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 20 Mar 2009 20:23:28 +0000 Subject: [PATCH] make sure we always have a CGFontRef git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59661 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/carbon/font.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index c3426f807b..6f69cb358c 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -173,6 +173,7 @@ public: #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT ATSUStyle m_macATSUStyle ; #endif + wxCFRef m_cgFont; #if wxOSX_USE_COCOA WX_NSFont m_nsFont; #endif @@ -196,6 +197,7 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) #if wxOSX_USE_CORE_TEXT m_ctFont = data.m_ctFont; #endif + m_cgFont = data.m_cgFont; #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT if ( data.m_macATSUStyle != NULL ) { @@ -248,6 +250,7 @@ void wxFontRefData::Free() #if wxOSX_USE_CORE_TEXT m_ctFont.reset(); #endif + m_cgFont.reset(); #if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT if ( m_macATSUStyle ) { @@ -414,6 +417,7 @@ void wxFontRefData::MacFindFont() { m_ctFont.reset( CTFontCreateWithFontDescriptor( m_info.m_ctFontDescriptor, 0/*m_pointSize */, NULL ) ); } + m_cgFont.reset(CTFontCopyGraphicsFont(m_ctFont, NULL)); } #endif @@ -471,7 +475,11 @@ void wxFontRefData::MacFindFont() atsuTags, atsuSizes, atsuValues); wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); - return; + if ( m_cgFont.get() == NULL ) + { + ATSFontRef fontRef = FMGetATSFontRefFromFont(m_info.m_atsuFontID); + m_cgFont.reset( CGFontCreateWithPlatformFont( &fontRef ) ); + } } #endif #if wxOSX_USE_COCOA @@ -780,6 +788,21 @@ CTFontRef wxFont::GetCTFont() const #endif +#if wxOSX_USE_COCOA_OR_CARBON + +CGFontRef wxFont::GetCGFont() const +{ + wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); + + // cast away constness otherwise lazy font resolution is not possible + const_cast(this)->RealizeResource(); + + return (M_FONTDATA->m_cgFont); +} + +#endif + + #if wxOSX_USE_COCOA NSFont* wxFont::GetNSFont() const -- 2.47.2