X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9445de1e4f04424a97904c1610c8d117726ef8d8..9914bfbb77f48baf869b63aff58feb2b145ff4d3:/src/osx/carbon/font.cpp diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 6f69cb358c..f8c6f5f347 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -28,11 +28,6 @@ #include "wx/osx/private.h" -#if wxOSX_USE_ATSU_TEXT && !wxOSX_USE_CARBON -// include themeing support -#include -#endif - #include #include @@ -50,14 +45,14 @@ public: } wxFontRefData(const wxFontRefData& data); - + wxFontRefData( const wxNativeFontInfo& info ) : m_info(info) { Init(); } wxFontRefData(wxOSXSystemFont font, int size); - + #if wxOSX_USE_CORE_TEXT wxFontRefData( wxUint32 coreTextFontType ); wxFontRefData( CTFontRef font ); @@ -66,10 +61,6 @@ public: virtual ~wxFontRefData(); - void SetNoAntiAliasing( bool no = true ) { m_noAA = no; } - - bool GetNoAntiAliasing() const { return m_noAA; } - void SetPointSize( int size ) { if( GetPointSize() != size ) @@ -159,18 +150,17 @@ protected: #if wxOSX_USE_CORE_TEXT // void Init( CTFontRef font ); #endif - bool m_noAA; // No anti-aliasing public: bool m_fontValid; #if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT - // for true themeing support we must store the correct font + // for true theming support we must store the correct font // information here, as this speeds up and optimizes rendering ThemeFontID m_macThemeFontID ; #endif #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; @@ -189,7 +179,6 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) { Init(); m_info = data.m_info; - m_noAA = data.m_noAA; m_fontValid = data.m_fontValid; #if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT m_macThemeFontID = data.m_macThemeFontID; @@ -198,7 +187,7 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) m_ctFont = data.m_ctFont; #endif m_cgFont = data.m_cgFont; -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT if ( data.m_macATSUStyle != NULL ) { ATSUCreateStyle(&m_macATSUStyle) ; @@ -209,9 +198,9 @@ 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 - + } // ============================================================================ @@ -224,11 +213,10 @@ wxFontRefData::wxFontRefData(const wxFontRefData& data) void wxFontRefData::Init() { - m_noAA = false; #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 @@ -251,7 +239,10 @@ void wxFontRefData::Free() m_ctFont.reset(); #endif m_cgFont.reset(); -#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT +#if wxOSX_USE_CARBON + m_macThemeFontID = kThemeCurrentPortFont ; +#endif if ( m_macATSUStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); @@ -279,11 +270,11 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) { wxASSERT( font != wxOSX_SYSTEM_FONT_NONE ); Init(); - + #if wxOSX_USE_CORE_TEXT if ( UMAGetSystemVersion() >= 0x1050 ) { - CTFontUIFontType uifont; + CTFontUIFontType uifont = kCTFontSystemFontType; switch( font ) { case wxOSX_SYSTEM_FONT_NORMAL: @@ -323,7 +314,7 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) { #if !wxOSX_USE_CARBON // not needed outside - ThemeFontID m_macThemeFontID; + ThemeFontID m_macThemeFontID = kThemeSystemFont; #endif switch( font ) { @@ -343,7 +334,7 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) m_macThemeFontID = kThemeMiniSystemFont; break; case wxOSX_SYSTEM_FONT_MINI_BOLD: - // bold not available under themeing + // bold not available under theming m_macThemeFontID = kThemeMiniSystemFont; break; case wxOSX_SYSTEM_FONT_LABELS: @@ -353,14 +344,14 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) m_macThemeFontID = kThemeViewsFont; break; default: - break; + break; } if ( m_info.m_faceName.empty() ) { Style style ; FMFontSize fontSize; Str255 qdFontName ; - + GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &fontSize, &style ); if ( size != 0 ) fontSize = size; @@ -368,7 +359,7 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) wxFontStyle fontstyle = wxFONTSTYLE_NORMAL; wxFontWeight fontweight = wxFONTWEIGHT_NORMAL; bool underlined = false; - + if ( style & bold ) fontweight = wxFONTWEIGHT_BOLD ; else @@ -377,17 +368,17 @@ wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size) fontstyle = wxFONTSTYLE_ITALIC ; if ( style & underline ) underlined = true ; - - m_info.Init(size,wxFONTFAMILY_DEFAULT,fontstyle,fontweight,underlined, + + m_info.Init(fontSize,wxFONTFAMILY_DEFAULT,fontstyle,fontweight,underlined, wxMacMakeStringFromPascal( qdFontName ), wxFONTENCODING_DEFAULT); } } #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 } @@ -395,9 +386,11 @@ void wxFontRefData::MacFindFont() { if ( m_fontValid ) return; - + + wxCHECK_RET( m_info.m_pointSize > 0, wxT("Point size should not be zero.") ); + m_info.EnsureValid(); - + #if wxOSX_USE_CORE_TEXT if ( UMAGetSystemVersion() >= 0x1050 ) { @@ -439,7 +432,7 @@ void wxFontRefData::MacFindFont() kATSUQDCondensedTag , kATSUQDExtendedTag , }; - ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + ByteCount atsuSizes[WXSIZEOF(atsuTags)] = { sizeof( ATSUFontID ) , sizeof( Fixed ) , @@ -457,7 +450,7 @@ void wxFontRefData::MacFindFont() Fixed atsuSize = IntToFixed( m_info.m_pointSize ); ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; FMFontStyle addQDStyle = m_info.m_atsuAdditionalQDStyles; - ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + ATSUAttributeValuePtr atsuValues[WXSIZEOF(atsuTags)] = { &m_info.m_atsuFontID , &atsuSize , @@ -471,10 +464,11 @@ void wxFontRefData::MacFindFont() status = ::ATSUSetAttributes( (ATSUStyle)m_macATSUStyle, - sizeof(atsuTags) / sizeof(ATSUAttributeTag) , + WXSIZEOF(atsuTags), atsuTags, atsuSizes, atsuValues); - wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); + wxASSERT_MSG( status == noErr , wxString::Format(wxT("couldn't modify ATSU style. Status was %d"), (int) status).c_str() ); + if ( m_cgFont.get() == NULL ) { ATSFontRef fontRef = FMGetATSFontRefFromFont(m_info.m_atsuFontID); @@ -483,10 +477,10 @@ void wxFontRefData::MacFindFont() } #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; } @@ -498,10 +492,10 @@ void wxFontRefData::MacFindFont() bool wxFont::Create(const wxNativeFontInfo& info) { UnRef(); - + m_refData = new wxFontRefData( info ); RealizeResource(); - + return true; } @@ -521,7 +515,7 @@ bool wxFont::Create(int pointSize, wxFontEncoding encoding) { UnRef(); - + wxString faceName = faceNameParam; if ( faceName.empty() ) @@ -531,7 +525,7 @@ bool wxFont::Create(int pointSize, case wxFONTFAMILY_DEFAULT : faceName = wxT("Lucida Grande"); break; - + case wxFONTFAMILY_SCRIPT : case wxFONTFAMILY_ROMAN : case wxFONTFAMILY_DECORATIVE : @@ -552,9 +546,9 @@ bool wxFont::Create(int pointSize, break ; } } - + wxNativeFontInfo info; - + info.Init(pointSize, family, style, weight, underlined, faceName, encoding); @@ -566,9 +560,9 @@ bool wxFont::Create(int pointSize, bool wxFont::CreateSystemFont(wxOSXSystemFont font) { UnRef(); - + m_refData = new wxFontRefData( font, 0 ); - + return true; } @@ -576,6 +570,14 @@ wxFont::~wxFont() { } +void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info) +{ + UnRef(); + + m_refData = new wxFontRefData( info); +} + + bool wxFont::RealizeResource() { M_FONTDATA->MacFindFont(); @@ -647,13 +649,6 @@ void wxFont::SetUnderlined(bool underlined) M_FONTDATA->SetUnderlined( underlined ); } -void wxFont::SetNoAntiAliasing( bool no ) -{ - AllocExclusive(); - - M_FONTDATA->SetNoAntiAliasing( no ); -} - // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- @@ -724,13 +719,6 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->GetEncoding() ; } -bool wxFont::GetNoAntiAliasing() const -{ - wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") ); - - return M_FONTDATA->GetNoAntiAliasing(); -} - #if wxOSX_USE_ATSU_TEXT && wxOSX_USE_CARBON short wxFont::MacGetFontNum() const @@ -739,7 +727,7 @@ short wxFont::MacGetFontNum() const // cast away constness otherwise lazy font resolution is not possible const_cast(this)->RealizeResource(); - + return M_FONTDATA->m_info.m_qdFontFamily; } @@ -749,7 +737,7 @@ wxByte wxFont::MacGetFontStyle() const // cast away constness otherwise lazy font resolution is not possible const_cast(this)->RealizeResource(); - + return M_FONTDATA->m_info.m_qdFontStyle; } @@ -762,27 +750,50 @@ 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") ); // cast away constness otherwise lazy font resolution is not possible const_cast(this)->RealizeResource(); - + return M_FONTDATA->m_macATSUStyle; } + +#if WXWIN_COMPATIBILITY_2_8 +wxUint32 wxFont::MacGetATSUFontID() 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_info.m_atsuFontID; +} + +wxUint32 wxFont::MacGetATSUAdditionalQDStyles() 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_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") ); // cast away constness otherwise lazy font resolution is not possible const_cast(this)->RealizeResource(); - + return (CTFontRef)(M_FONTDATA->m_ctFont); } @@ -790,13 +801,13 @@ CTFontRef wxFont::GetCTFont() const #if wxOSX_USE_COCOA_OR_CARBON -CGFontRef wxFont::GetCGFont() const +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); } @@ -805,13 +816,13 @@ CGFontRef wxFont::GetCGFont() const #if wxOSX_USE_COCOA -NSFont* wxFont::GetNSFont() const +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 (M_FONTDATA->m_nsFont); } @@ -824,7 +835,7 @@ const wxNativeFontInfo * wxFont::GetNativeFontInfo() const // cast away constness otherwise lazy font resolution is not possible const_cast(this)->RealizeResource(); - + // M_FONTDATA->m_info.InitFromFont(*this); return &(M_FONTDATA->m_info); @@ -843,11 +854,11 @@ static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, CTFontDescriptorRef descriptor = NULL; CFMutableDictionaryRef attributes; - assert(iFamilyName != NULL); + wxASSERT(iFamilyName != NULL); // Create a mutable dictionary to hold our attributes. attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - check(attributes != NULL); + wxASSERT(attributes != NULL); if (attributes != NULL) { // Add a family name to our attributes. @@ -861,13 +872,13 @@ static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, // Create the traits dictionary. symTraits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &iTraits); - check(symTraits != NULL); + wxASSERT(symTraits != NULL); if (symTraits != NULL) { // Create a dictionary to hold our traits values. traits = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - check(traits != NULL); + wxASSERT(traits != NULL); if (traits != NULL) { // Add the symbolic traits value to the traits dictionary. @@ -882,7 +893,7 @@ static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, } // Create the font descriptor with our attributes descriptor = CTFontDescriptorCreateWithAttributes(attributes); - check(descriptor != NULL); + wxASSERT(descriptor != NULL); CFRelease(attributes); } @@ -908,9 +919,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; @@ -918,7 +926,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; } @@ -927,7 +935,7 @@ void wxNativeFontInfo::Init(CTFontDescriptorRef descr) { Init(); m_ctFontDescriptor = wxCFRetain(descr); - + wxCFRef< CFNumberRef > sizevalue( (CFNumberRef) CTFontDescriptorCopyAttribute( m_ctFontDescriptor, kCTFontSizeAttribute ) ); float fsize; if ( CFNumberGetValue( sizevalue , kCFNumberFloatType , &fsize ) ) @@ -944,7 +952,7 @@ void wxNativeFontInfo::Init(CTFontDescriptorRef descr) } wxCFStringRef familyName( (CFStringRef) CTFontDescriptorCopyAttribute(m_ctFontDescriptor, kCTFontFamilyNameAttribute)); - m_faceName = familyName.AsString(); + m_faceName = familyName.AsString(); } #endif @@ -952,7 +960,7 @@ void wxNativeFontInfo::EnsureValid() { if ( m_descriptorValid ) return; - + #if wxOSX_USE_CORE_TEXT if ( m_ctFontDescriptor == NULL && UMAGetSystemVersion() >= 0x1050 ) { @@ -1027,14 +1035,17 @@ void wxNativeFontInfo::EnsureValid() // ATSUFontID and FMFont are equivalent FMFontStyle intrinsicStyle = 0 ; OSStatus status = FMGetFontFromFontFamilyInstance( m_qdFontFamily , m_qdFontStyle , (FMFont*)&m_atsuFontID , &intrinsicStyle); - wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); + if ( status != noErr ) + { + wxFAIL_MSG( wxT("couldn't get an ATSUFont from font family") ); + } m_atsuAdditionalQDStyles = m_qdFontStyle & (~intrinsicStyle ); m_atsuFontValid = true; } #endif #if wxOSX_USE_COCOA if ( m_nsFontDescriptor == NULL ) - ValidateNSFontDescriptor(); + OSXValidateNSFontDescriptor(); #endif #if wxOSX_USE_IPHONE // TODO @@ -1059,9 +1070,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; @@ -1088,6 +1096,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; } @@ -1106,10 +1116,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; } @@ -1118,7 +1124,7 @@ bool wxNativeFontInfo::FromString(const wxString& s) { long l; - wxStringTokenizer tokenizer(s, _T(";")); + wxStringTokenizer tokenizer(s, wxT(";")); wxString token = tokenizer.GetNextToken(); // @@ -1169,7 +1175,7 @@ wxString wxNativeFontInfo::ToString() const { wxString s; - s.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"), + s.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"), 0, // version m_pointSize, m_family, @@ -1276,6 +1282,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 +}