X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a672c75fbc62a70f9fefc26c57300dc8c3812de..b18e2046af6c8eaf6e867ba18dd9410dbd7dfcf7:/src/osx/carbon/font.cpp diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index c3426f807b..2b51a315a1 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -170,9 +170,10 @@ public: #if wxOSX_USE_CORE_TEXT wxCFRef m_ctFont; #endif -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT ATSUStyle m_macATSUStyle ; #endif + wxCFRef m_cgFont; #if wxOSX_USE_COCOA WX_NSFont m_nsFont; #endif @@ -195,8 +196,9 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) #endif #if wxOSX_USE_CORE_TEXT m_ctFont = data.m_ctFont; -#endif -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT +#endif + m_cgFont = data.m_cgFont; +#if wxOSX_USE_ATSU_TEXT if ( data.m_macATSUStyle != NULL ) { ATSUCreateStyle(&m_macATSUStyle) ; @@ -207,7 +209,7 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) m_nsFont = (NSFont*) wxMacCocoaRetain(data.m_nsFont); #endif #if wxOSX_USE_IPHONE - m_uiFont = wxMacCocoaRetain(data.m_uiFont); + m_uiFont = (UIFont*) wxMacCocoaRetain(data.m_uiFont); #endif } @@ -226,7 +228,7 @@ void wxFontRefData::Init() #if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT m_macThemeFontID = kThemeCurrentPortFont ; #endif -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT m_macATSUStyle = NULL ; #endif #if wxOSX_USE_COCOA @@ -248,7 +250,8 @@ void wxFontRefData::Free() #if wxOSX_USE_CORE_TEXT m_ctFont.reset(); #endif -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT + m_cgFont.reset(); +#if wxOSX_USE_ATSU_TEXT if ( m_macATSUStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); @@ -280,7 +283,7 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) #if wxOSX_USE_CORE_TEXT if ( UMAGetSystemVersion() >= 0x1050 ) { - CTFontUIFontType uifont; + CTFontUIFontType uifont = kCTFontSystemFontType; switch( font ) { case wxOSX_SYSTEM_FONT_NORMAL: @@ -320,7 +323,7 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) { #if !wxOSX_USE_CARBON // not needed outside - ThemeFontID m_macThemeFontID; + ThemeFontID m_macThemeFontID = kThemeSystemFont; #endif switch( font ) { @@ -381,10 +384,10 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) } #endif #if wxOSX_USE_COCOA - m_nsFont = wxFont::CreateNSFont( font, &m_info ); + m_nsFont = wxFont::OSXCreateNSFont( font, &m_info ); #endif #if wxOSX_USE_IPHONE - m_uiFont = wxFont::CreateUIFont( font, &m_info ); + m_uiFont = wxFont::OSXCreateUIFont( font, &m_info ); #endif } @@ -414,6 +417,7 @@ void wxFontRefData::MacFindFont() { m_ctFont.reset( CTFontCreateWithFontDescriptor( m_info.m_ctFontDescriptor, 0/*m_pointSize */, NULL ) ); } + m_cgFont.reset(CTFontCopyGraphicsFont(m_ctFont, NULL)); } #endif @@ -471,14 +475,18 @@ void wxFontRefData::MacFindFont() atsuTags, atsuSizes, atsuValues); wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); - return; + if ( m_cgFont.get() == NULL ) + { + ATSFontRef fontRef = FMGetATSFontRefFromFont(m_info.m_atsuFontID); + m_cgFont.reset( CGFontCreateWithPlatformFont( &fontRef ) ); + } } #endif #if wxOSX_USE_COCOA - m_nsFont = wxFont::CreateNSFont( &m_info ); + m_nsFont = wxFont::OSXCreateNSFont( &m_info ); #endif #if wxOSX_USE_IPHONE - m_uiFont = wxFont::CreateUIFont( &m_info ); + m_uiFont = wxFont::OSXCreateUIFont( &m_info ); #endif m_fontValid = true; } @@ -568,6 +576,14 @@ wxFont::~wxFont() { } +void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info) +{ + UnRef(); + + m_refData = new wxFontRefData( info); +} + + bool wxFont::RealizeResource() { M_FONTDATA->MacFindFont(); @@ -754,7 +770,7 @@ wxUint16 wxFont::MacGetThemeFontID() const #endif -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT void * wxFont::MacGetATSUStyle() const { wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); @@ -764,11 +780,34 @@ void * wxFont::MacGetATSUStyle() const return M_FONTDATA->m_macATSUStyle; } + +#if WXWIN_COMPATIBILITY_2_8 +wxUint32 wxFont::MacGetATSUFontID() const +{ + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); + + // cast away constness otherwise lazy font resolution is not possible + const_cast(this)->RealizeResource(); + + return M_FONTDATA->m_info.m_atsuFontID; +} + +wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const +{ + wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); + + // cast away constness otherwise lazy font resolution is not possible + const_cast(this)->RealizeResource(); + + return M_FONTDATA->m_info.m_atsuAdditionalQDStyles; +} +#endif + #endif #if wxOSX_USE_CORE_TEXT -CTFontRef wxFont::GetCTFont() const +CTFontRef wxFont::OSXGetCTFont() const { wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); @@ -780,9 +819,24 @@ CTFontRef wxFont::GetCTFont() const #endif +#if wxOSX_USE_COCOA_OR_CARBON + +CGFontRef wxFont::OSXGetCGFont() 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 (M_FONTDATA->m_cgFont); +} + +#endif + + #if wxOSX_USE_COCOA -NSFont* wxFont::GetNSFont() const +NSFont* wxFont::OSXGetNSFont() const { wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); @@ -885,9 +939,6 @@ void wxNativeFontInfo::Init() #endif #if wxOSX_USE_COCOA m_nsFontDescriptor = NULL; -#endif -#if wxOSX_USE_IPHONE - m_uiFontDescriptor = NULL; #endif m_pointSize = 0; m_family = wxFONTFAMILY_DEFAULT; @@ -895,7 +946,7 @@ void wxNativeFontInfo::Init() m_weight = wxFONTWEIGHT_NORMAL; m_underlined = false; m_faceName.clear(); - m_encoding = wxFONTENCODING_DEFAULT; + m_encoding = wxFont::GetDefaultEncoding(); m_descriptorValid = false; } @@ -1011,7 +1062,7 @@ void wxNativeFontInfo::EnsureValid() #endif #if wxOSX_USE_COCOA if ( m_nsFontDescriptor == NULL ) - ValidateNSFontDescriptor(); + OSXValidateNSFontDescriptor(); #endif #if wxOSX_USE_IPHONE // TODO @@ -1036,9 +1087,6 @@ void wxNativeFontInfo::Init(const wxNativeFontInfo& info) #endif #if wxOSX_USE_COCOA m_nsFontDescriptor = (NSFontDescriptor*) wxMacCocoaRetain(info.m_nsFontDescriptor); -#endif -#if wxOSX_USE_IPHONE - m_uiFontDescriptor = wxMacCocoaRetain(info.m_uiFontDescriptor);; #endif m_pointSize = info.m_pointSize; m_family = info.m_family; @@ -1065,6 +1113,8 @@ void wxNativeFontInfo::Init(int size, m_weight = weight; m_underlined = underlined; m_faceName = faceName; + if ( encoding == wxFONTENCODING_DEFAULT ) + encoding = wxFont::GetDefaultEncoding(); m_encoding = encoding; } @@ -1083,10 +1133,6 @@ void wxNativeFontInfo::Free() #if wxOSX_USE_COCOA wxMacCocoaRelease(m_nsFontDescriptor); m_nsFontDescriptor = NULL; -#endif -#if wxOSX_USE_IPHONE - wxMacCocoaRelease(m_uiFontDescriptor); - m_uiFontDescriptor = NULL #endif m_descriptorValid = false; } @@ -1253,6 +1299,8 @@ void wxNativeFontInfo::SetFamily(wxFontFamily family_) void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_) { + if ( encoding_ == wxFONTENCODING_DEFAULT ) + encoding_ = wxFont::GetDefaultEncoding(); m_encoding = encoding_; // not reflected in native descriptors } \ No newline at end of file