diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 63e3a44adb..601020702b 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -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(this)->RealizeResource(); - - return const_cast(reinterpret_cast(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(this)->RealizeResource(); - - return const_cast(reinterpret_cast(OSXGetCTFont())); -} - -#endif - const wxNativeFontInfo * wxFont::GetNativeFontInfo() const { wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 57996e27f9..4c8b13dbbe 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -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(this)->RealizeResource(); + + NSFont *font = const_cast(reinterpret_cast(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(this)->RealizeResource(); + + return const_cast(reinterpret_cast(OSXGetCTFont())); +} + #endif // ----------------------------------------------------------------------------