+ wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
+ if (angle == 0.0 )
+ {
+ DrawText(str, x, y);
+ return;
+ }
+ if ( str.Length() == 0 )
+ return ;
+ wxMacPortSetter helper(this) ;
+ MacInstallFont() ;
+ wxString text ;
+ if ( wxApp::s_macDefaultEncodingIsPC )
+ {
+ text = wxMacMakeMacStringFromPC( str ) ;
+ }
+ else
+ {
+ text = str ;
+ }
+ wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
+ if ( 0 )
+ {
+ m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
+ SetAntiAliasedTextEnabled(true, SInt16(m_scaleY * font->m_macFontSize));
+ m_macAliasWasEnabled = true ;
+ }
+ OSStatus status = noErr ;
+ TECObjectRef ec;
+ status = TECCreateConverter(&ec, kTextEncodingMacRoman, kTextEncodingUnicodeDefault);
+ wxASSERT_MSG( status == noErr , "couldn't start converter" ) ;
+ ByteCount byteOutLen ;
+ ByteCount byteInLen = text.Length() ;
+ ByteCount byteBufferLen = byteInLen *2 ;
+ char* buf = new char[byteBufferLen] ;
+ status = TECConvertText(ec, (ConstTextPtr)text.c_str() , byteInLen, &byteInLen,
+ (TextPtr)buf, byteBufferLen, &byteOutLen);
+ wxASSERT_MSG( status == noErr , "couldn't convert text" ) ;
+ status = TECDisposeConverter(ec);
+ wxASSERT_MSG( status == noErr , "couldn't dispose converter" ) ;
+ ATSUTextLayout atsuLayout ;
+ UniCharCount chars = byteOutLen / 2 ;
+ status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 ,
+ &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
+ wxASSERT_MSG( status == noErr , "couldn't create the layout of the rotated text" );
+ int iAngle = int( angle );
+ int drawX = XLOG2DEVMAC(x) ;
+ int drawY = YLOG2DEVMAC(y) ;
+
+ ATSUTextMeasurement textBefore ;
+ ATSUTextMeasurement textAfter ;
+ ATSUTextMeasurement ascent ;
+ ATSUTextMeasurement descent ;
+
+
+ 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 ) ;
+ }
+ status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
+ &textBefore , &textAfter, &ascent , &descent );
+
+ drawX += sin(angle/RAD2DEG) * FixedToInt(ascent) ;
+ drawY += cos(angle/RAD2DEG) * FixedToInt(ascent) ;
+ status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
+ IntToFixed(drawX) , IntToFixed(drawY) );
+ wxASSERT_MSG( status == noErr , "couldn't draw the rotated text" );
+ Rect rect ;
+ status = ::ATSUMeasureTextImage( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
+ IntToFixed(drawX) , IntToFixed(drawY) , &rect );
+ wxASSERT_MSG( status == noErr , "couldn't measure the rotated text" );
+ OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ;
+ CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
+ CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
+ ::ATSUDisposeTextLayout(atsuLayout);
+ delete[] buf ;