From c07e1e2c855d4b8b9a138773c7ef7cd5c0b71418 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 29 Nov 2007 21:52:28 +0000 Subject: [PATCH] adding CoreText implementation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50331 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/font.cpp | 571 +++++++++++++++++------------------- src/mac/carbon/graphics.cpp | 502 +++++++++++++++++++------------ 2 files changed, 580 insertions(+), 493 deletions(-) diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index e509a7f34b..db727b6515 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -40,45 +40,12 @@ class WXDLLEXPORT wxFontRefData: public wxGDIRefData public: wxFontRefData() - : m_fontId(0) - , m_pointSize(10) - , m_family(wxDEFAULT) - , m_style(wxNORMAL) - , m_weight(wxNORMAL) - , m_underlined(false) - , m_faceName(wxT("applicationfont")) - , m_encoding(wxFONTENCODING_DEFAULT) -#ifdef __LP64__ -#else - , m_macFontFamily(0) - , m_macFontSize(0) - , m_macFontStyle(0) - , m_macATSUFontID(0) -#endif - , m_macATSUStyle(0) { - Init(m_pointSize, m_family, m_style, m_weight, - m_underlined, m_faceName, m_encoding); + Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, + false, wxT("applicationfont"), wxFONTENCODING_DEFAULT); } wxFontRefData(const wxFontRefData& data) - : wxGDIRefData() - , m_fontId(data.m_fontId) - , m_pointSize(data.m_pointSize) - , m_family(data.m_family) - , m_style(data.m_style) - , m_weight(data.m_weight) - , m_underlined(data.m_underlined) - , m_faceName(data.m_faceName) - , m_encoding(data.m_encoding) -#ifdef __LP64__ -#else - , m_macFontFamily(data.m_macFontFamily) - , m_macFontSize(data.m_macFontSize) - , m_macFontStyle(data.m_macFontStyle) - , m_macATSUFontID(data.m_macATSUFontID) -#endif - , m_macATSUStyle(0) { Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight, data.m_underlined, data.m_faceName, data.m_encoding); @@ -91,22 +58,6 @@ public: bool underlined, const wxString& faceName, wxFontEncoding encoding) - : m_fontId(0) - , m_pointSize(size) - , m_family(family) - , m_style(style) - , m_weight(weight) - , m_underlined(underlined) - , m_faceName(faceName) - , m_encoding(encoding) -#ifdef __LP64__ -#else - , m_macFontFamily(0) - , m_macFontSize(0) - , m_macFontStyle(0) - , m_macATSUFontID(0) -#endif - , m_macATSUStyle(0) { Init(size, family, style, weight, underlined, faceName, encoding); } @@ -132,7 +83,6 @@ protected: wxFontEncoding encoding); // font characterstics - int m_fontId; int m_pointSize; int m_family; int m_style; @@ -143,7 +93,7 @@ protected: bool m_noAA; // No anti-aliasing public: -#ifndef __LP64__ +#if wxMAC_USE_ATSU_TEXT FMFontFamily m_macFontFamily; FMFontSize m_macFontSize; FMFontStyle m_macFontStyle; @@ -160,11 +110,12 @@ public: // for true themeing support we must store the correct font // information here, as this speeds up and optimizes rendering ThemeFontID m_macThemeFontID ; -#else - CTFontRef m_macFontRef; + ATSUStyle m_macATSUStyle ; +#endif +#if wxMAC_USE_CORE_TEXT + wxCFRef m_ctFont; CTFontUIFontType m_macUIFontType; #endif - ATSUStyle m_macATSUStyle ; wxNativeFontInfo m_info; }; @@ -195,20 +146,19 @@ void wxFontRefData::Init(int pointSize, m_underlined = underlined; m_faceName = faceName; m_encoding = encoding; -#ifdef __LP64__ + m_noAA = false; +#ifdef wxMAC_USE_CORE_TEXT m_macUIFontType = kCTFontNoFontType; - m_macFontRef = 0; -#else +#endif +#if wxMAC_USE_ATSU_TEXT m_macFontFamily = 0 ; m_macFontSize = 0; m_macFontStyle = 0; m_macATSUFontID = 0; m_macATSUAdditionalQDStyles = 0 ; - m_macThemeFontID = kThemeCurrentPortFont ; -#endif m_macATSUStyle = NULL ; - m_noAA = false; +#endif } wxFontRefData::~wxFontRefData() @@ -220,147 +170,96 @@ wxFontRefData::~wxFontRefData() } } -void wxFontRefData::MacFindFont() -{ - OSStatus status = noErr; - Str255 qdFontName ; +#if wxMAC_USE_CORE_TEXT -#ifdef __LP64__ - if ( m_faceName.empty() && m_family == wxDEFAULT ) - { - m_macUIFontType = kCTFontSystemFontType; - } +/* code mixed together from 2 different routines from Core Text Manual Common Operations */ + +static CTFontRef wxMacCreateCTFont(CFStringRef iFamilyName, CTFontSymbolicTraits iTraits, CGFloat iSize ) +{ + CTFontDescriptorRef descriptor = NULL; + CFMutableDictionaryRef attributes; - if ( m_macUIFontType != kCTFontNoFontType ) - { - m_macFontRef = CTFontCreateUIFontForLanguage( m_macUIFontType, 0.0, NULL ); - wxMacCFStringHolder name( CTFontCopyFamilyName( m_macFontRef ) ); - m_faceName = name.AsString(); - } - else - { - if ( m_faceName.empty() ) - { - switch ( m_family ) - { - case wxSCRIPT : - case wxROMAN : - case wxDECORATIVE : - m_faceName = wxT("Times"); - break ; - - case wxSWISS : - m_faceName = wxT("Lucida Grande"); - break ; - - case wxMODERN : - case wxTELETYPE: - m_faceName = wxT("Monaco"); - break ; - - default: - m_faceName = wxT("Times"); - break ; + assert(iFamilyName != NULL); + // Create a mutable dictionary to hold our attributes. + attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, + &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + check(attributes != NULL); + + if (attributes != NULL) { + // Add a family name to our attributes. + CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, iFamilyName); + + + if ( iTraits ) { + CFMutableDictionaryRef traits; + CFNumberRef symTraits; + + // Create the traits dictionary. + symTraits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, + &iTraits); + check(symTraits != NULL); + + if (symTraits != NULL) { + // Create a dictionary to hold our traits values. + traits = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, + &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + check(traits != NULL); + + if (traits != NULL) { + // Add the symbolic traits value to the traits dictionary. + CFDictionaryAddValue(traits, kCTFontSymbolicTrait, symTraits); + + // Add the traits attribute to our attributes. + CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits); + CFRelease(traits); + } + CFRelease(symTraits); } } - - wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); - m_macFontRef = CTFontCreateWithName( cf, m_pointSize, NULL); + // Create the font descriptor with our attributes and input size. + descriptor = CTFontDescriptorCreateWithAttributes(attributes); + check(descriptor != NULL); + + CFRelease(attributes); } + // Return our font descriptor. + CTFontRef font = CTFontCreateWithFontDescriptor( descriptor, iSize, NULL); + CFRelease( descriptor ); + return font ; +} - if ( m_macATSUStyle ) - { - ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); - m_macATSUStyle = NULL ; - } - - status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); - wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); - - ATSUAttributeTag atsuTags[] = - { - kATSUSizeTag , - kATSUVerticalCharacterTag, - kATSUQDBoldfaceTag , - kATSUQDItalicTag , - kATSUQDUnderlineTag , - kATSUQDCondensedTag , - kATSUQDExtendedTag , - kATSUFontTag , - }; - ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = - { - sizeof( Fixed ) , - sizeof( ATSUVerticalCharacterType), - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( ATSUFontID ) , - }; - - Boolean kTrue = true ; - Boolean kFalse = false ; - - Fixed atsuSize = IntToFixed( m_pointSize ); - short m_macATSUAdditionalQDStyles = 0; - ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; - ATSUFontID atsuFontID = 0; - int attributeCount = sizeof(atsuTags) / sizeof(ATSUAttributeTag) ; - - // attempt to add atsu font -#if 0 - status = ATSUFindFontFromName(m_faceName.c_str(), strlen(m_faceName.c_str()), kFontFamilyName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &atsuFontID); - if ( status != noErr ) - { - attributeCount--; - } #endif - ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = - { - &atsuSize , - &kHorizontal, - (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse , - (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse , - (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse , - (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse , - (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse , - &atsuFontID , - }; - status = ::ATSUSetAttributes( (ATSUStyle)m_macATSUStyle, attributeCount, atsuTags, atsuSizes, atsuValues); +void wxFontRefData::MacFindFont() +{ + OSStatus status = noErr; - wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); -#else - if ( m_macThemeFontID != kThemeCurrentPortFont ) +#if wxMAC_USE_CORE_TEXT + if ( CTFontCreateWithName != NULL ) { - Style style ; - GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &m_macFontSize, &style ); - m_macFontStyle = style ; - m_faceName = wxMacMakeStringFromPascal( qdFontName ); - if ( m_macFontStyle & bold ) - m_weight = wxBOLD ; - else - m_weight = wxNORMAL ; - if ( m_macFontStyle & italic ) - m_style = wxITALIC ; - if ( m_macFontStyle & underline ) - m_underlined = true ; - m_pointSize = m_macFontSize ; - m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); - } - else - { - if ( m_faceName.empty() ) + if ( m_faceName.empty() && m_family == wxDEFAULT && m_macUIFontType == kCTFontNoFontType ) + { + m_macUIFontType = kCTFontSystemFontType; + } + + if ( m_macUIFontType != kCTFontNoFontType ) { - if ( m_family == wxDEFAULT ) + m_ctFont.reset(CTFontCreateUIFontForLanguage( m_macUIFontType, 0.0, NULL )); + + wxMacCFStringHolder name( CTFontCopyFamilyName( m_ctFont ) ); + m_faceName = name.AsString(); + if ( CTFontGetSize(m_ctFont) == 0 ) { - m_macFontFamily = GetAppFont(); - FMGetFontFamilyName(m_macFontFamily,qdFontName); - m_faceName = wxMacMakeStringFromPascal( qdFontName ); + m_ctFont.reset(CTFontCreateUIFontForLanguage( m_macUIFontType, 12, NULL )); } - else + + m_pointSize = CTFontGetSize(m_ctFont) ; + // reset this so that future manipulation don't fall back + m_macUIFontType = kCTFontNoFontType; + } + else + { + if ( m_faceName.empty() ) { switch ( m_family ) { @@ -369,107 +268,176 @@ void wxFontRefData::MacFindFont() case wxDECORATIVE : m_faceName = wxT("Times"); break ; - + case wxSWISS : m_faceName = wxT("Lucida Grande"); break ; - + case wxMODERN : case wxTELETYPE: m_faceName = wxT("Monaco"); break ; - + default: m_faceName = wxT("Times"); break ; } - wxMacStringToPascal( m_faceName , qdFontName ); - m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); - if ( m_macFontFamily == kInvalidFontFamily ) - { - wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() ); - m_macFontFamily = GetAppFont(); - } } + + wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); + CTFontSymbolicTraits traits = 0; + + if (m_weight == wxBOLD) + traits |= kCTFontBoldTrait; + if (m_style == wxITALIC || m_style == wxSLANT) + traits |= kCTFontItalicTrait; + + m_ctFont.reset( wxMacCreateCTFont( cf, traits, m_pointSize ) ); } - else + } +#endif +#if wxMAC_USE_ATSU_TEXT + { + Str255 qdFontName ; + if ( m_macThemeFontID != kThemeCurrentPortFont ) { - if ( m_faceName == wxT("systemfont") ) - m_macFontFamily = GetSysFont(); - else if ( m_faceName == wxT("applicationfont") ) - m_macFontFamily = GetAppFont(); + Style style ; + GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &m_macFontSize, &style ); + if ( m_macFontSize == 0 ) + m_macFontSize = 12; + m_macFontStyle = style ; + m_faceName = wxMacMakeStringFromPascal( qdFontName ); + if ( m_macFontStyle & bold ) + m_weight = wxBOLD ; else + m_weight = wxNORMAL ; + if ( m_macFontStyle & italic ) + m_style = wxITALIC ; + if ( m_macFontStyle & underline ) + m_underlined = true ; + m_pointSize = m_macFontSize ; + m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); + } + else + { + if ( m_faceName.empty() ) { - wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); - ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault ); - if ( atsfamily == (ATSFontFamilyRef) -1 ) + if ( m_family == wxDEFAULT ) { - wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName ); m_macFontFamily = GetAppFont(); + FMGetFontFamilyName(m_macFontFamily,qdFontName); + m_faceName = wxMacMakeStringFromPascal( qdFontName ); + } + else + { + switch ( m_family ) + { + case wxSCRIPT : + case wxROMAN : + case wxDECORATIVE : + m_faceName = wxT("Times"); + break ; + + case wxSWISS : + m_faceName = wxT("Lucida Grande"); + break ; + + case wxMODERN : + case wxTELETYPE: + m_faceName = wxT("Monaco"); + break ; + + default: + m_faceName = wxT("Times"); + break ; + } + wxMacStringToPascal( m_faceName , qdFontName ); + m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); + if ( m_macFontFamily == kInvalidFontFamily ) + { + wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() ); + m_macFontFamily = GetAppFont(); + } } + } + else + { + if ( m_faceName == wxT("systemfont") ) + m_macFontFamily = GetSysFont(); + else if ( m_faceName == wxT("applicationfont") ) + m_macFontFamily = GetAppFont(); else - m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); + { + wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); + ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault ); + if ( atsfamily == (ATSFontFamilyRef) -1 ) + { + wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName ); + m_macFontFamily = GetAppFont(); + } + else + m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); + } } + + m_macFontStyle = 0; + if (m_weight == wxBOLD) + m_macFontStyle |= bold; + if (m_style == wxITALIC || m_style == wxSLANT) + m_macFontStyle |= italic; + if (m_underlined) + m_macFontStyle |= underline; + m_macFontSize = m_pointSize ; } - - m_macFontStyle = 0; - if (m_weight == wxBOLD) - m_macFontStyle |= bold; - if (m_style == wxITALIC || m_style == wxSLANT) - m_macFontStyle |= italic; - if (m_underlined) - m_macFontStyle |= underline; - m_macFontSize = m_pointSize ; - } - - // we try to get as much styles as possible into ATSU - - - // ATSUFontID and FMFont are equivalent - FMFontStyle intrinsicStyle = 0 ; - status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle); - wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); - m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle ); - - if ( m_macATSUStyle ) - { - ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); - m_macATSUStyle = NULL ; - } - - status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); - wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); - - ATSUAttributeTag atsuTags[] = - { - kATSUFontTag , - kATSUSizeTag , - kATSUVerticalCharacterTag, - kATSUQDBoldfaceTag , - kATSUQDItalicTag , - kATSUQDUnderlineTag , - kATSUQDCondensedTag , - kATSUQDExtendedTag , - }; - ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = - { - sizeof( ATSUFontID ) , - sizeof( Fixed ) , - sizeof( ATSUVerticalCharacterType), - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( Boolean ) , - sizeof( Boolean ) , - }; - - Boolean kTrue = true ; - Boolean kFalse = false ; - - Fixed atsuSize = IntToFixed( m_macFontSize ); - ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; - ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = - { + + // we try to get as much styles as possible into ATSU + + + // ATSUFontID and FMFont are equivalent + FMFontStyle intrinsicStyle = 0 ; + status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle); + wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); + m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle ); + + if ( m_macATSUStyle ) + { + ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle); + m_macATSUStyle = NULL ; + } + + status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle); + wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ); + + ATSUAttributeTag atsuTags[] = + { + kATSUFontTag , + kATSUSizeTag , + kATSUVerticalCharacterTag, + kATSUQDBoldfaceTag , + kATSUQDItalicTag , + kATSUQDUnderlineTag , + kATSUQDCondensedTag , + kATSUQDExtendedTag , + }; + ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + { + sizeof( ATSUFontID ) , + sizeof( Fixed ) , + sizeof( ATSUVerticalCharacterType), + sizeof( Boolean ) , + sizeof( Boolean ) , + sizeof( Boolean ) , + sizeof( Boolean ) , + sizeof( Boolean ) , + }; + + Boolean kTrue = true ; + Boolean kFalse = false ; + + Fixed atsuSize = IntToFixed( m_macFontSize ); + ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal; + ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + { &m_macATSUFontID , &atsuSize , &kHorizontal, @@ -478,14 +446,16 @@ void wxFontRefData::MacFindFont() (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse , (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse , (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse , - }; - - status = ::ATSUSetAttributes( - (ATSUStyle)m_macATSUStyle, - sizeof(atsuTags) / sizeof(ATSUAttributeTag) , - atsuTags, atsuSizes, atsuValues); - - wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); + }; + + status = ::ATSUSetAttributes( + (ATSUStyle)m_macATSUStyle, + sizeof(atsuTags) / sizeof(ATSUAttributeTag) , + atsuTags, atsuSizes, atsuValues); + + wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); + return; + } #endif } @@ -526,7 +496,7 @@ bool wxFont::Create(int pointSize, return true; } -#ifdef __LP64__ +#if wxMAC_USE_CORE_TEXT bool wxFont::MacCreateUIFont(wxUint32 ctFontType ) { @@ -546,18 +516,23 @@ bool wxFont::MacCreateUIFont(wxUint32 ctFontType ) bool wxFont::MacCreateThemeFont(wxUint16 themeFontID) { -#ifdef __LP64__ - return MacCreateUIFont(HIThemeGetUIFontType(themeFontID)); -#else - UnRef(); - - m_refData = new wxFontRefData( - 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, - false, wxEmptyString, wxFONTENCODING_DEFAULT ); +#if wxMAC_USE_CORE_TEXT + if ( HIThemeGetUIFontType != NULL ) + { + return MacCreateUIFont(HIThemeGetUIFontType(themeFontID)); + } +#endif +#if wxMAC_USE_CORE_TEXT + { + UnRef(); - M_FONTDATA->m_macThemeFontID = themeFontID ; - RealizeResource(); + m_refData = new wxFontRefData( + 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, + false, wxEmptyString, wxFONTENCODING_DEFAULT ); + M_FONTDATA->m_macThemeFontID = themeFontID ; + RealizeResource(); + } return true; #endif } @@ -599,6 +574,9 @@ void wxFont::Unshare() void wxFont::SetPointSize(int pointSize) { + if ( M_FONTDATA->m_pointSize == pointSize ) + return; + Unshare(); M_FONTDATA->m_pointSize = pointSize; @@ -739,7 +717,7 @@ bool wxFont::GetNoAntiAliasing() const return M_FONTDATA->m_noAA; } -#ifndef __LP64__ +#if wxMAC_USE_ATSU_TEXT short wxFont::MacGetFontNum() const { @@ -789,20 +767,15 @@ wxUint16 wxFont::MacGetThemeFontID() const return M_FONTDATA->m_macThemeFontID; } -#else -const void * wxFont::MacGetCTFont() const -{ - wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); +#endif - return M_FONTDATA->m_macFontRef; -} +#if wxMAC_USE_CORE_TEXT -// to be removed -void * wxFont::MacGetATSUStyle() const +const void * wxFont::MacGetCTFont() const { - wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") ); + wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); - return M_FONTDATA->m_macATSUStyle; + return (CTFontRef)(M_FONTDATA->m_ctFont); } #endif diff --git a/src/mac/carbon/graphics.cpp b/src/mac/carbon/graphics.cpp index 6282651f3e..e4b9212d91 100644 --- a/src/mac/carbon/graphics.cpp +++ b/src/mac/carbon/graphics.cpp @@ -696,18 +696,37 @@ public: wxMacCoreGraphicsFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col ); ~wxMacCoreGraphicsFontData(); +#if wxMAC_USE_ATSU_TEXT virtual ATSUStyle GetATSUStyle() { return m_macATSUIStyle; } +#endif +#if wxMAC_USE_CORE_TEXT + CTFontRef GetCTFont() const { return m_ctFont ; } +#endif + wxColour GetColour() const { return m_colour ; } + + bool GetUnderlined() const { return m_underlined ; } private : + wxColour m_colour; + bool m_underlined; +#if wxMAC_USE_ATSU_TEXT ATSUStyle m_macATSUIStyle; +#endif +#if wxMAC_USE_CORE_TEXT + wxCFRef< CTFontRef > m_ctFont; +#endif }; wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col) : wxGraphicsObjectRefData( renderer ) { m_macATSUIStyle = NULL; + OSStatus status = noErr; + m_colour = col; + m_underlined = font.GetUnderlined(); #if wxMAC_USE_CORE_TEXT -#elif wxMAC_USE_ATSU_TEXT - OSStatus status; + m_ctFont.reset( wxCFRetain((CTFontRef) font.MacGetCTFont()) ); +#endif +#if wxMAC_USE_ATSU_TEXT status = ATSUCreateAndCopyStyle( (ATSUStyle) font.MacGetATSUStyle() , &m_macATSUIStyle ); @@ -739,20 +758,23 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere atsuTags, atsuSizes, atsuValues); wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") ); -#elif WXMAC_USE_CG_TEXT +#endif +#if WXMAC_USE_CG_TEXT #endif } wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData() { #if wxMAC_USE_CORE_TEXT -#elif wxMAC_USE_ATSU_TEXT +#endif +#if wxMAC_USE_ATSU_TEXT if ( m_macATSUIStyle ) { ::ATSUDisposeStyle((ATSUStyle)m_macATSUIStyle); m_macATSUIStyle = NULL; } -#elif WXMAC_USE_CG_TEXT +#endif +#if WXMAC_USE_CG_TEXT #endif } @@ -1720,10 +1742,39 @@ void wxMacCoreGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDoub EnsureIsValid(); #if wxMAC_USE_CORE_TEXT - // TODO core text implementation here -#elif wxMAC_USE_ATSU_TEXT - DrawText(str, x, y, 0.0); -#elif WXMAC_USE_CG_TEXT + if ( UMAGetSystemVersion() >= 0x1050 ) + { + wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); + wxMacCFStringHolder text(str, wxLocale::GetSystemEncoding() ); + CTFontRef font = fref->GetCTFont(); + CGColorRef col = fref->GetColour().GetPixel(); + CTUnderlineStyle ustyle = fref->GetUnderlined() ? kCTUnderlineStyleSingle : kCTUnderlineStyleNone ; + wxCFRef underlined( CFNumberCreate(NULL, kCFNumberSInt32Type, &ustyle) ); + CFStringRef keys[] = { kCTFontAttributeName , kCTForegroundColorAttributeName, kCTUnderlineStyleAttributeName }; + CFTypeRef values[] = { font, col, underlined }; + wxCFRef attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values, + WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) ); + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) ); + wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); + + y += CTFontGetAscent(font); + + CGContextSaveGState(m_cgContext); + CGContextTranslateCTM(m_cgContext, x, y); + CGContextScaleCTM(m_cgContext, 1, -1); + CGContextSetTextPosition(m_cgContext, 0, 0); + CTLineDraw( line, m_cgContext ); + CGContextRestoreGState(m_cgContext); + return; + } +#endif +#if wxMAC_USE_ATSU_TEXT + { + DrawText(str, x, y, 0.0); + return; + } +#endif +#if WXMAC_USE_CG_TEXT // TODO core graphics text implementation here #endif } @@ -1735,115 +1786,124 @@ void wxMacCoreGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDoub EnsureIsValid(); #if wxMAC_USE_CORE_TEXT - // default implementation takes care of rotation and calls non rotated DrawText afterwards - wxGraphicsContext::DrawText( str, x, y, angle ); -#elif wxMAC_USE_ATSU_TEXT - OSStatus status = noErr; - ATSUTextLayout atsuLayout; - UniCharCount chars = str.length(); - UniChar* ubuf = NULL; - + if ( UMAGetSystemVersion() >= 0x1050 ) + { + // default implementation takes care of rotation and calls non rotated DrawText afterwards + wxGraphicsContext::DrawText( str, x, y, angle ); + return; + } +#endif +#if wxMAC_USE_ATSU_TEXT + { + OSStatus status = noErr; + ATSUTextLayout atsuLayout; + UniCharCount chars = str.length(); + UniChar* ubuf = NULL; + #if SIZEOF_WCHAR_T == 4 - wxMBConvUTF16 converter; + wxMBConvUTF16 converter; #if wxUSE_UNICODE - size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ); - ubuf = (UniChar*) malloc( unicharlen + 2 ); - converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ); + size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ); + ubuf = (UniChar*) malloc( unicharlen + 2 ); + converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ); #else - const wxWCharBuffer wchar = str.wc_str( wxConvLocal ); - size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ); - ubuf = (UniChar*) malloc( unicharlen + 2 ); - converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ); + const wxWCharBuffer wchar = str.wc_str( wxConvLocal ); + size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ); + ubuf = (UniChar*) malloc( unicharlen + 2 ); + converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ); #endif - chars = unicharlen / 2; + chars = unicharlen / 2; #else #if wxUSE_UNICODE - ubuf = (UniChar*) str.wc_str(); + ubuf = (UniChar*) str.wc_str(); #else - wxWCharBuffer wchar = str.wc_str( wxConvLocal ); - chars = wxWcslen( wchar.data() ); - ubuf = (UniChar*) wchar.data(); + wxWCharBuffer wchar = str.wc_str( wxConvLocal ); + chars = wxWcslen( wchar.data() ); + ubuf = (UniChar*) wchar.data(); #endif #endif - - ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle()); - status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , - &chars , &style , &atsuLayout ); - - wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") ); - - status = ::ATSUSetTransientFontMatching( atsuLayout , true ); - wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") ); - - int iAngle = int( angle * RAD2DEG ); - if ( abs(iAngle) > 0 ) - { - Fixed atsuAngle = IntToFixed( iAngle ); - ATSUAttributeTag atsuTags[] = - { - kATSULineRotationTag , - }; - ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = - { - sizeof( Fixed ) , - }; - ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = - { - &atsuAngle , - }; - status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag), - atsuTags, atsuSizes, atsuValues ); - } - - { - ATSUAttributeTag atsuTags[] = - { - kATSUCGContextTag , - }; - ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + + ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle()); + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , + &chars , &style , &atsuLayout ); + + wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") ); + + status = ::ATSUSetTransientFontMatching( atsuLayout , true ); + wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") ); + + int iAngle = int( angle * RAD2DEG ); + if ( abs(iAngle) > 0 ) { - sizeof( CGContextRef ) , - }; - ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + Fixed atsuAngle = IntToFixed( iAngle ); + ATSUAttributeTag atsuTags[] = + { + kATSULineRotationTag , + }; + ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + { + sizeof( Fixed ) , + }; + ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + { + &atsuAngle , + }; + status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag), + atsuTags, atsuSizes, atsuValues ); + } + { - &m_cgContext , - }; - status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag), - atsuTags, atsuSizes, atsuValues ); - } - - ATSUTextMeasurement textBefore, textAfter; - ATSUTextMeasurement ascent, descent; - - status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, - &textBefore , &textAfter, &ascent , &descent ); - - wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); - - Rect rect; - x += (int)(sin(angle) * FixedToInt(ascent)); - y += (int)(cos(angle) * FixedToInt(ascent)); - - status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, - IntToFixed(x) , IntToFixed(y) , &rect ); - wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); - - CGContextSaveGState(m_cgContext); - CGContextTranslateCTM(m_cgContext, x, y); - CGContextScaleCTM(m_cgContext, 1, -1); - status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, - IntToFixed(0) , IntToFixed(0) ); - - wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") ); - - CGContextRestoreGState(m_cgContext); - - ::ATSUDisposeTextLayout(atsuLayout); - + ATSUAttributeTag atsuTags[] = + { + kATSUCGContextTag , + }; + ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + { + sizeof( CGContextRef ) , + }; + ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] = + { + &m_cgContext , + }; + status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags) / sizeof(ATSUAttributeTag), + atsuTags, atsuSizes, atsuValues ); + } + + ATSUTextMeasurement textBefore, textAfter; + ATSUTextMeasurement ascent, descent; + + status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, + &textBefore , &textAfter, &ascent , &descent ); + + wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); + + Rect rect; + x += (int)(sin(angle) * FixedToInt(ascent)); + y += (int)(cos(angle) * FixedToInt(ascent)); + + status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, + IntToFixed(x) , IntToFixed(y) , &rect ); + wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); + + CGContextSaveGState(m_cgContext); + CGContextTranslateCTM(m_cgContext, x, y); + CGContextScaleCTM(m_cgContext, 1, -1); + status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, + IntToFixed(0) , IntToFixed(0) ); + + wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") ); + + CGContextRestoreGState(m_cgContext); + + ::ATSUDisposeTextLayout(atsuLayout); + #if SIZEOF_WCHAR_T == 4 - free( ubuf ); + free( ubuf ); +#endif + return; + } #endif -#elif WXMAC_USE_CG_TEXT +#if WXMAC_USE_CG_TEXT // default implementation takes care of rotation and calls non rotated DrawText afterwards wxGraphicsContext::DrawText( str, x, y, angle ); #endif @@ -1867,63 +1927,94 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid return; #if wxMAC_USE_CORE_TEXT - // TODO core text implementation here -#elif wxMAC_USE_ATSU_TEXT - OSStatus status = noErr; - - ATSUTextLayout atsuLayout; - UniCharCount chars = str.length(); - UniChar* ubuf = NULL; - + if ( UMAGetSystemVersion() >= 0x1050 ) + { + wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); + CTFontRef font = fref->GetCTFont(); + + wxMacCFStringHolder text(str, wxLocale::GetSystemEncoding() ); + CFStringRef keys[] = { kCTFontAttributeName }; + CFTypeRef values[] = { font }; + wxCFRef attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values, + WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) ); + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, text, attributes) ); + wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); + + CGFloat w, a, d, l; + + w = CTLineGetTypographicBounds(line, &a, &d, &l) ; + + if ( height ) + *height = a+d+l; + if ( descent ) + *descent = d; + if ( externalLeading ) + *externalLeading = l; + if ( width ) + *width = w; + return; + } +#endif +#if wxMAC_USE_ATSU_TEXT + { + OSStatus status = noErr; + + ATSUTextLayout atsuLayout; + UniCharCount chars = str.length(); + UniChar* ubuf = NULL; + #if SIZEOF_WCHAR_T == 4 - wxMBConvUTF16 converter; + wxMBConvUTF16 converter; #if wxUSE_UNICODE - size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ); - ubuf = (UniChar*) malloc( unicharlen + 2 ); - converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ); + size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ); + ubuf = (UniChar*) malloc( unicharlen + 2 ); + converter.WC2MB( (char*) ubuf , str.wc_str(), unicharlen + 2 ); #else - const wxWCharBuffer wchar = str.wc_str( wxConvLocal ); - size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ); - ubuf = (UniChar*) malloc( unicharlen + 2 ); - converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ); + const wxWCharBuffer wchar = str.wc_str( wxConvLocal ); + size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ); + ubuf = (UniChar*) malloc( unicharlen + 2 ); + converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ); #endif - chars = unicharlen / 2; + chars = unicharlen / 2; #else #if wxUSE_UNICODE - ubuf = (UniChar*) str.wc_str(); + ubuf = (UniChar*) str.wc_str(); #else - wxWCharBuffer wchar = str.wc_str( wxConvLocal ); - chars = wxWcslen( wchar.data() ); - ubuf = (UniChar*) wchar.data(); + wxWCharBuffer wchar = str.wc_str( wxConvLocal ); + chars = wxWcslen( wchar.data() ); + ubuf = (UniChar*) wchar.data(); #endif #endif - - ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle()); - status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , - &chars , &style , &atsuLayout ); - - wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") ); - - ATSUTextMeasurement textBefore, textAfter; - ATSUTextMeasurement textAscent, textDescent; - - status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, - &textBefore , &textAfter, &textAscent , &textDescent ); - - if ( height ) - *height = FixedToInt(textAscent + textDescent); - if ( descent ) - *descent = FixedToInt(textDescent); - if ( externalLeading ) - *externalLeading = 0; - if ( width ) - *width = FixedToInt(textAfter - textBefore); - - ::ATSUDisposeTextLayout(atsuLayout); + + ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle()); + status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , + &chars , &style , &atsuLayout ); + + wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") ); + + ATSUTextMeasurement textBefore, textAfter; + ATSUTextMeasurement textAscent, textDescent; + + status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd, + &textBefore , &textAfter, &textAscent , &textDescent ); + + if ( height ) + *height = FixedToInt(textAscent + textDescent); + if ( descent ) + *descent = FixedToInt(textDescent); + if ( externalLeading ) + *externalLeading = 0; + if ( width ) + *width = FixedToInt(textAfter - textBefore); + + ::ATSUDisposeTextLayout(atsuLayout); #if SIZEOF_WCHAR_T == 4 - free( ubuf ) ; + free( ubuf ) ; #endif -#elif WXMAC_USE_CG_TEXT + return; + } +#endif +#if WXMAC_USE_CG_TEXT // TODO core graphics text implementation here #endif } @@ -1937,60 +2028,83 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr return; #if wxMAC_USE_CORE_TEXT - // TODO core text implementation here -#elif wxMAC_USE_ATSU_TEXT - ATSUTextLayout atsuLayout; - UniCharCount chars = text.length(); - UniChar* ubuf = NULL; - + { + wxMacCoreGraphicsFontData* fref = (wxMacCoreGraphicsFontData*)m_font.GetRefData(); + CTFontRef font = fref->GetCTFont(); + + wxMacCFStringHolder t(text, wxLocale::GetSystemEncoding() ); + CFStringRef keys[] = { kCTFontAttributeName }; + CFTypeRef values[] = { font }; + wxCFRef attributes( CFDictionaryCreate(kCFAllocatorDefault, (const void**) &keys, (const void**) &values, + WXSIZEOF( keys ), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) ); + wxCFRef attrtext( CFAttributedStringCreate(kCFAllocatorDefault, t, attributes) ); + wxCFRef line( CTLineCreateWithAttributedString(attrtext) ); + + int chars = text.length(); + for ( int pos = 0; pos < (int)chars; pos ++ ) + { + widths[pos] = CTLineGetOffsetForStringIndex( line, pos+1 , NULL )+0.5; + } + + return; + } +#endif +#if wxMAC_USE_ATSU_TEXT + { + ATSUTextLayout atsuLayout; + UniCharCount chars = text.length(); + UniChar* ubuf = NULL; + #if SIZEOF_WCHAR_T == 4 - wxMBConvUTF16 converter; + wxMBConvUTF16 converter; #if wxUSE_UNICODE - size_t unicharlen = converter.WC2MB( NULL , text.wc_str() , 0 ); - ubuf = (UniChar*) malloc( unicharlen + 2 ); - converter.WC2MB( (char*) ubuf , text.wc_str(), unicharlen + 2 ); + size_t unicharlen = converter.WC2MB( NULL , text.wc_str() , 0 ); + ubuf = (UniChar*) malloc( unicharlen + 2 ); + converter.WC2MB( (char*) ubuf , text.wc_str(), unicharlen + 2 ); #else - const wxWCharBuffer wchar = text.wc_str( wxConvLocal ); - size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ); - ubuf = (UniChar*) malloc( unicharlen + 2 ); - converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ); + const wxWCharBuffer wchar = text.wc_str( wxConvLocal ); + size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ); + ubuf = (UniChar*) malloc( unicharlen + 2 ); + converter.WC2MB( (char*) ubuf , wchar.data() , unicharlen + 2 ); #endif - chars = unicharlen / 2; + chars = unicharlen / 2; #else #if wxUSE_UNICODE - ubuf = (UniChar*) text.wc_str(); + ubuf = (UniChar*) text.wc_str(); #else - wxWCharBuffer wchar = text.wc_str( wxConvLocal ); - chars = wxWcslen( wchar.data() ); - ubuf = (UniChar*) wchar.data(); + wxWCharBuffer wchar = text.wc_str( wxConvLocal ); + chars = wxWcslen( wchar.data() ); + ubuf = (UniChar*) wchar.data(); #endif #endif - - ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle()); - ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , - &chars , &style , &atsuLayout ); - - for ( int pos = 0; pos < (int)chars; pos ++ ) - { - unsigned long actualNumberOfBounds = 0; - ATSTrapezoid glyphBounds; - - // We get a single bound, since the text should only require one. If it requires more, there is an issue - OSStatus result; - result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1, - kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds ); - if (result != noErr || actualNumberOfBounds != 1 ) - return; - - widths[pos] = FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ); - //unsigned char uch = s[i]; - } - - ::ATSUDisposeTextLayout(atsuLayout); + + ATSUStyle style = (((wxMacCoreGraphicsFontData*)m_font.GetRefData())->GetATSUStyle()); + ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 , + &chars , &style , &atsuLayout ); + + for ( int pos = 0; pos < (int)chars; pos ++ ) + { + unsigned long actualNumberOfBounds = 0; + ATSTrapezoid glyphBounds; + + // We get a single bound, since the text should only require one. If it requires more, there is an issue + OSStatus result; + result = ATSUGetGlyphBounds( atsuLayout, 0, 0, kATSUFromTextBeginning, pos + 1, + kATSUseDeviceOrigins, 1, &glyphBounds, &actualNumberOfBounds ); + if (result != noErr || actualNumberOfBounds != 1 ) + return; + + widths[pos] = FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ); + //unsigned char uch = s[i]; + } + + ::ATSUDisposeTextLayout(atsuLayout); #if SIZEOF_WCHAR_T == 4 - free( ubuf ) ; + free( ubuf ) ; +#endif + } #endif -#elif WXMAC_USE_CG_TEXT +#if WXMAC_USE_CG_TEXT // TODO core graphics text implementation here #endif } -- 2.45.2