NSFont -> wxFont conversion.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2009-10-31 23:00:04 +00:00
parent b478f24288
commit f7946addb2
2 changed files with 40 additions and 23 deletions

View File

@@ -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

View File

@@ -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;
}