diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 2137281d7b..1c7e767eda 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -27,6 +27,7 @@ #include "wx/tokenzr.h" #include "wx/osx/private.h" +#include "wx/osx/private/available.h" #include #include @@ -324,10 +325,6 @@ void wxFontRefData::AllocIfNeeded() const void wxFontRefData::Alloc() { wxCHECK_RET(m_info.GetPointSize() > 0, wxT("Point size should not be zero.")); - - // make sure the font descriptor has been processed properly - // otherwise the Post Script Name may not be valid yet - m_info.RealizeResource(); // use font caching, we cache a font with a certain size and a font with just any size for faster creation wxString lookupnameNoSize = wxString::Format("%s_%d_%d", m_info.GetPostScriptName(), (int)m_info.GetStyle(), m_info.GetNumericWeight()); @@ -818,7 +815,6 @@ void wxNativeFontInfo::InitFromFontDescriptor(CTFontDescriptorRef desc) } wxCFTypeRef(CTFontDescriptorCopyAttribute(m_descriptor, kCTFontFamilyNameAttribute)).GetValue(m_familyName); - wxCFTypeRef(CTFontDescriptorCopyAttribute(m_descriptor, kCTFontNameAttribute)).GetValue(m_postScriptName); } void wxNativeFontInfo::Free() @@ -876,7 +872,6 @@ void wxNativeFontInfo::CreateCTFontDescriptor() m_descriptor = descriptor; wxCFTypeRef(CTFontDescriptorCopyAttribute(m_descriptor, kCTFontFamilyNameAttribute)).GetValue(m_familyName); - wxCFTypeRef(CTFontDescriptorCopyAttribute(m_descriptor, kCTFontNameAttribute)).GetValue(m_postScriptName); #if wxDEBUG_LEVEL >= 2 // for debugging: show all different font names @@ -1022,10 +1017,6 @@ bool wxNativeFontInfo::FromString(const wxString& s) wxString wxNativeFontInfo::ToString() const { - // make sure the font descriptor has been processed properly - // otherwise the Post Script Name may not be valid yet - RealizeResource(); - wxString s; s.Printf(wxT("%d;%s;%d;%d;%d;%d;%d;%s;%d"), @@ -1064,7 +1055,25 @@ bool wxNativeFontInfo::GetUnderlined() const wxString wxNativeFontInfo::GetPostScriptName() const { - return m_postScriptName; + // return user-set PostScript name as-is + if ( !m_postScriptName.empty() ) + return m_postScriptName; + + // if not explicitly set, obtain it from the font descriptor + wxString ps; + wxCFTypeRef(CTFontDescriptorCopyAttribute(GetCTFontDescriptor(), kCTFontNameAttribute)).GetValue(ps); + + if ( WX_IS_MACOS_AVAILABLE(10, 16) ) + { + // the PostScript names reported in macOS start with a dot for System Fonts, this has to be corrected + // otherwise round-trips are not possible, resulting in a Times Fallback, therefore we replace these with + // their official PostScript Name + wxString rest; + if ( ps.StartsWith(".SFNS", &rest) ) + return "SFPro" + rest; + } + + return ps; } wxString wxNativeFontInfo::GetFaceName() const