Fix NSFont bridging crash with Asian input methods on 10.11
There's a bug in OS X 10.11 where a toll-free bridged font may have an
attributed of private class __NSCFCharacterSet that unlike
NSCharacterSet doesn't conform to NSSecureCoding. This poses a problem
when such font is used in user-editable content, because some Asian
input methods then crash in 10.11 when editing the string. As a
workaround for this bug, don't use toll-free bridging, but re-create
NSFont from the descriptor instead on buggy OS X versions.
Fixes regression introduced in a77066d530
(#507).
This commit is contained in:
parent
af16d8ba5c
commit
926d486f54
@ -680,35 +680,6 @@ CGFontRef wxFont::OSXGetCGFont() const
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if wxOSX_USE_COCOA
|
||||
|
||||
NSFont* wxFont::OSXGetNSFont() const
|
||||
{
|
||||
wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
|
||||
|
||||
// cast away constness otherwise lazy font resolution is not possible
|
||||
const_cast<wxFont *>(this)->RealizeResource();
|
||||
|
||||
return const_cast<NSFont*>(reinterpret_cast<const NSFont*>(OSXGetCTFont()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if wxOSX_USE_IPHONE
|
||||
|
||||
UIFont* wxFont::OSXGetUIFont() const
|
||||
{
|
||||
wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
|
||||
|
||||
// cast away constness otherwise lazy font resolution is not possible
|
||||
const_cast<wxFont *>(this)->RealizeResource();
|
||||
|
||||
return const_cast<UIFont*>(reinterpret_cast<const UIFont*>(OSXGetCTFont()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const wxNativeFontInfo * wxFont::GetNativeFontInfo() const
|
||||
{
|
||||
wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
|
||||
|
@ -140,6 +140,48 @@ void wxFont::SetNativeInfoFromNSFont(WX_NSFont theFont, wxNativeFontInfo* info)
|
||||
}
|
||||
}
|
||||
|
||||
NSFont* wxFont::OSXGetNSFont() const
|
||||
{
|
||||
wxCHECK_MSG( m_refData != NULL , 0, wxT("invalid font") );
|
||||
|
||||
// cast away constness otherwise lazy font resolution is not possible
|
||||
const_cast<wxFont *>(this)->RealizeResource();
|
||||
|
||||
NSFont *font = const_cast<NSFont*>(reinterpret_cast<const NSFont*>(OSXGetCTFont()));
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
|
||||
// There's a bug in OS X 10.11 (but not present in 10.10 or 10.12) where a
|
||||
// toll-free bridged font may have an attributed of private class __NSCFCharacterSet
|
||||
// that unlike NSCharacterSet doesn't conform to NSSecureCoding. This poses
|
||||
// a problem when such font is used in user-editable content, because some
|
||||
// Asian input methods then crash in 10.11 when editing the string.
|
||||
// As a workaround for this bug, don't use toll-free bridging, but
|
||||
// re-create NSFont from the descriptor instead on buggy OS X versions.
|
||||
int osMajor, osMinor;
|
||||
wxGetOsVersion(&osMajor, &osMinor, NULL);
|
||||
if (osMajor == 10 && osMinor == 11)
|
||||
{
|
||||
return [NSFont fontWithDescriptor:[font fontDescriptor] size:[font pointSize]];
|
||||
}
|
||||
#endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if wxOSX_USE_IPHONE
|
||||
|
||||
UIFont* wxFont::OSXGetUIFont() const
|
||||
{
|
||||
wxCHECK_MSG( m_refData != NULL , 0, wxT("invalid font") );
|
||||
|
||||
// cast away constness otherwise lazy font resolution is not possible
|
||||
const_cast<wxFont *>(this)->RealizeResource();
|
||||
|
||||
return const_cast<UIFont*>(reinterpret_cast<const UIFont*>(OSXGetCTFont()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user