From: Kevin Ollivier Date: Sat, 31 Oct 2009 23:00:04 +0000 (+0000) Subject: NSFont -> wxFont conversion. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f7946addb258a973e9da5601cf96712ed4f5c5c8?ds=sidebyside NSFont -> wxFont conversion. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/font.h b/include/wx/osx/font.h index 625a079c0b..bcd86e775a 100644 --- a/include/wx/osx/font.h +++ b/include/wx/osx/font.h @@ -37,6 +37,10 @@ public: // ctors and such wxFont() { } +#if wxOSX_USE_COCOA + wxFont(WX_NSFont nsfont); +#endif + #if FUTURE_WXWIN_COMPATIBILITY_3_0 wxFont(int size, int family, @@ -153,6 +157,7 @@ public: WX_NSFont OSXGetNSFont() const; static WX_NSFont OSXCreateNSFont(wxOSXSystemFont font, wxNativeFontInfo* info); static WX_NSFont OSXCreateNSFont(const wxNativeFontInfo* info); + static void SetNativeInfoFromNSFont(WX_NSFont nsfont, wxNativeFontInfo* info); #endif #if wxOSX_USE_IPHONE diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 08e0a23bc0..7604f0f277 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -102,6 +102,40 @@ void* wxMacCocoaRetain( void* obj ) // ---------------------------------------------------------------------------- #if wxOSX_USE_COCOA +wxFont::wxFont(WX_NSFont nsfont) +{ + [nsfont retain]; + wxNativeFontInfo info; + SetNativeInfoFromNSFont(nsfont, &info); + Create(info); +} + +void wxFont::SetNativeInfoFromNSFont(WX_NSFont nsfont, wxNativeFontInfo* info) +{ + NSFontDescriptor*desc = [[nsfont fontDescriptor] retain]; + if ( info->m_faceName.empty()) + { + wxFontStyle fontstyle = wxFONTSTYLE_NORMAL; + wxFontWeight fontweight = wxFONTWEIGHT_NORMAL; + bool underlined = false; + + int size = (int) ([desc pointSize]+0.5); + NSFontSymbolicTraits traits = [desc symbolicTraits]; + + if ( traits & NSFontBoldTrait ) + fontweight = wxFONTWEIGHT_BOLD ; + else + fontweight = wxFONTWEIGHT_NORMAL ; + if ( traits & NSFontItalicTrait ) + fontstyle = wxFONTSTYLE_ITALIC ; + + wxCFStringRef fontname( [desc postscriptName] ); + info->Init(size,wxFONTFAMILY_DEFAULT,fontstyle,fontweight,underlined, + fontname.AsString(), wxFONTENCODING_DEFAULT); + + } + info->m_nsFontDescriptor = desc; +} WX_NSFont wxFont::OSXCreateNSFont(wxOSXSystemFont font, wxNativeFontInfo* info) { @@ -138,29 +172,7 @@ WX_NSFont wxFont::OSXCreateNSFont(wxOSXSystemFont font, wxNativeFontInfo* info) break; } [nsfont retain]; - NSFontDescriptor*desc = [[nsfont fontDescriptor] retain]; - if ( info->m_faceName.empty()) - { - wxFontStyle fontstyle = wxFONTSTYLE_NORMAL; - wxFontWeight fontweight = wxFONTWEIGHT_NORMAL; - bool underlined = false; - - int size = (int) ([desc pointSize]+0.5); - NSFontSymbolicTraits traits = [desc symbolicTraits]; - - if ( traits & NSFontBoldTrait ) - fontweight = wxFONTWEIGHT_BOLD ; - else - fontweight = wxFONTWEIGHT_NORMAL ; - if ( traits & NSFontItalicTrait ) - fontstyle = wxFONTSTYLE_ITALIC ; - - wxCFStringRef fontname( [desc postscriptName] ); - info->Init(size,wxFONTFAMILY_DEFAULT,fontstyle,fontweight,underlined, - fontname.AsString(), wxFONTENCODING_DEFAULT); - - } - info->m_nsFontDescriptor = desc; + SetNativeInfoFromNSFont(nsfont, info); return nsfont; }