+ OSStatus status = noErr ;
+ ATSUTextLayout atsuLayout ;
+ UniCharCount chars = str.length() ;
+ UniChar* ubuf = NULL ;
+
+#if SIZEOF_WCHAR_T == 4
+ 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 ) ;
+#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 ) ;
+#endif
+ chars = unicharlen / 2 ;
+#else
+#if wxUSE_UNICODE
+ ubuf = (UniChar*) str.wc_str() ;
+#else
+ wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
+ chars = wxWcslen( wchar.data() ) ;
+ ubuf = (UniChar*) wchar.data() ;
+#endif
+#endif
+
+ status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) ubuf , 0 , chars , chars , 1 ,
+ &chars , (ATSUStyle*) &m_macATSUIStyle , &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 );
+ 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)] =
+ {
+ 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 ;
+/*
+ // TODO
+ if ( m_backgroundMode == wxSOLID )
+ {
+ wxGraphicPath* path = m_graphicContext->CreatePath() ;
+ path->MoveToPoint( drawX , drawY ) ;
+ path->AddLineToPoint(
+ (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent)) ,
+ (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent)) ) ;
+ path->AddLineToPoint(
+ (int) (drawX + sin(angle / RAD2DEG) * FixedToInt(ascent + descent ) + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
+ (int) (drawY + cos(angle / RAD2DEG) * FixedToInt(ascent + descent) - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
+ path->AddLineToPoint(
+ (int) (drawX + cos(angle / RAD2DEG) * FixedToInt(textAfter)) ,
+ (int) (drawY - sin(angle / RAD2DEG) * FixedToInt(textAfter)) ) ;
+
+ m_graphicContext->FillPath( path , m_textBackgroundColour ) ;
+ delete path ;
+ }
+*/
+ x += (int)(sin(angle / RAD2DEG) * FixedToInt(ascent));
+ y += (int)(cos(angle / RAD2DEG) * 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 ) ;
+#endif
+}
+
+void wxMacCGContext::GetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
+ wxCoord *descent, wxCoord *externalLeading ) const