- delete[] buf ;
-}
-
-void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
-{
- wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC"));
- wxMacPortSetter helper(this) ;
-
- long xx = XLOG2DEVMAC(x);
- long yy = YLOG2DEVMAC(y);
-
- MacInstallFont() ;
- if ( 0 )
- {
- m_macFormerAliasState = IsAntiAliasedTextEnabled(&m_macFormerAliasSize);
- SetAntiAliasedTextEnabled(true, 8);
- m_macAliasWasEnabled = true ;
- }
-
- FontInfo fi ;
- ::GetFontInfo( &fi ) ;
-
- yy += fi.ascent ;
- ::MoveTo( xx , yy );
- if ( m_backgroundMode == wxTRANSPARENT )
- {
- ::TextMode( srcOr) ;
- }
- else
- {
- ::TextMode( srcCopy ) ;
- }
-
- const char *text = NULL ;
- int length = 0 ;
- wxString macText ;
-
- if ( wxApp::s_macDefaultEncodingIsPC )
- {
- macText = wxMacMakeMacStringFromPC( strtext ) ;
- text = macText ;
- length = macText.Length() ;
- }
- else
- {
- text = strtext ;
- length = strtext.Length() ;
- }
-
- int laststop = 0 ;
- int i = 0 ;
- int line = 0 ;
-
- while( i < length )
- {
- if( text[i] == 13 || text[i] == 10)
- {
- ::DrawText( text , laststop , i - laststop ) ;
- line++ ;
- ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
- laststop = i+1 ;
- }
- i++ ;
- }
-
- ::DrawText( text , laststop , i - laststop ) ;
- ::TextMode( srcOr ) ;
-}
-
-bool wxDC::CanGetTextExtent() const
-{
- wxCHECK_MSG(Ok(), false, wxT("Invalid DC"));
-
- return true ;
-}
-
-void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height,
- wxCoord *descent, wxCoord *externalLeading ,
- wxFont *theFont ) const
-{
- wxCHECK_RET(Ok(), wxT("Invalid DC"));
- wxMacPortSetter helper(this) ;
-
- wxFont formerFont = m_font ;
-
- if ( theFont )
- {
- wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ;
-
- if ( font )
- {
- ::TextFont( font->m_macFontNum ) ;
- ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ;
- ::TextFace( font->m_macFontStyle ) ;
- }
- }
- else
- {
- MacInstallFont() ;
- }
-
- FontInfo fi ;
- ::GetFontInfo( &fi ) ;
-
- if ( height )
- *height = YDEV2LOGREL( fi.descent + fi.ascent ) ;
- if ( descent )
- *descent =YDEV2LOGREL( fi.descent );
- if ( externalLeading )
- *externalLeading = YDEV2LOGREL( fi.leading ) ;
-
- const char *text = NULL ;
- int length = 0 ;
- wxString macText ;
- if ( wxApp::s_macDefaultEncodingIsPC )
- {
- macText = wxMacMakeMacStringFromPC( string ) ;
- text = macText ;
- length = macText.Length() ;
- }
- else
- {
- text = string ;
- length = string.Length() ;
- }
-
- int laststop = 0 ;
- int i = 0 ;
- int curwidth = 0 ;
- if ( width )
- {
- *width = 0 ;
-
- while( i < length )
- {
- if( text[i] == 13 || text[i] == 10)
- {
- if ( height )
- *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ;
- curwidth = ::TextWidth( text , laststop , i - laststop ) ;
- if ( curwidth > *width )
- *width = XDEV2LOGREL( curwidth ) ;
- laststop = i+1 ;
- }
- i++ ;
- }
-
- curwidth = ::TextWidth( text , laststop , i - laststop ) ;
- if ( curwidth > *width )
- *width = XDEV2LOGREL( curwidth ) ;
- }
-
- if ( theFont )
- {
- m_macFontInstalled = false ;
- }
-}
-
-wxCoord wxDC::GetCharWidth(void) const
-{
- wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
-
- wxMacPortSetter helper(this) ;
-
- MacInstallFont() ;
-
- int width = ::TextWidth( "n" , 0 , 1 ) ;
-
- return YDEV2LOGREL(width) ;
-}
-
-wxCoord wxDC::GetCharHeight(void) const
-{
- wxCHECK_MSG(Ok(), 1, wxT("Invalid DC"));
-
- wxMacPortSetter helper(this) ;
-
- MacInstallFont() ;
-
- FontInfo fi ;
- ::GetFontInfo( &fi ) ;
-
- return YDEV2LOGREL( fi.descent + fi.ascent );
-}
-
-void wxDC::Clear(void)
-{
- wxCHECK_RET(Ok(), wxT("Invalid DC"));
- wxMacPortSetter helper(this) ;
- Rect rect = { -32000 , -32000 , 32000 , 32000 } ;
-
- if (m_backgroundBrush.GetStyle() != wxTRANSPARENT)
- {
- ::PenNormal() ;
- //MacInstallBrush() ;
+}
+
+void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
+{
+ DoDrawRotatedText( strtext , x , y , 0) ;
+}
+
+bool wxDC::CanGetTextExtent() const
+{
+ wxCHECK_MSG(Ok(), false, wxT("wxDC::CanGetTextExtent - invalid DC"));
+
+ return true ;
+}
+
+
+void wxDC::DoGetTextExtent( const wxString &str, wxCoord *width, wxCoord *height,
+ wxCoord *descent, wxCoord *externalLeading ,
+ wxFont *theFont ) const
+{
+ wxCHECK_RET(Ok(), wxT("wxDC::DoGetTextExtent - invalid DC"));
+
+ wxMacFastPortSetter helper(this) ;
+ wxFont formerFont = m_font ;
+ if ( theFont )
+ {
+ // work around the constness
+ *((wxFont*)(&m_font)) = *theFont ;
+ }
+
+ MacInstallFont() ;
+
+ OSStatus status = noErr ;
+ ATSUTextLayout atsuLayout ;
+
+ wxMacUniCharBuffer unibuf( str ) ;
+ UniCharCount chars = unibuf.GetChars() ;
+
+ status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
+ &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
+
+ wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
+
+ status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
+ wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
+
+ ATSLineLayoutOptions layoutOptions = kATSLineNoLayoutOptions ;
+
+ if (m_font.GetNoAntiAliasing())
+ {
+ layoutOptions |= kATSLineNoAntiAliasing ;
+ }
+
+ ATSUAttributeTag atsuTags[] =
+ {
+ kATSULineLayoutOptionsTag ,
+ } ;
+
+ ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+ {
+ sizeof( ATSLineLayoutOptions ) ,
+ } ;
+
+ ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+ {
+ &layoutOptions ,
+ } ;
+
+ status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
+ atsuTags, atsuSizes, atsuValues ) ;
+
+ ATSUTextMeasurement textBefore, textAfter ;
+ ATSUTextMeasurement textAscent, textDescent ;
+
+ status = ::ATSUGetUnjustifiedBounds( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
+ &textBefore , &textAfter, &textAscent , &textDescent );
+
+ if ( height )
+ *height = YDEV2LOGREL( FixedToInt(textAscent + textDescent) ) ;
+ if ( descent )
+ *descent =YDEV2LOGREL( FixedToInt(textDescent) );
+ if ( externalLeading )
+ *externalLeading = 0 ;
+ if ( width )
+ *width = XDEV2LOGREL( FixedToInt(textAfter - textBefore) ) ;
+
+ ::ATSUDisposeTextLayout(atsuLayout);
+
+
+ if ( theFont )
+ {
+ // work around the constness
+ *((wxFont*)(&m_font)) = formerFont ;
+ m_macFontInstalled = false ;
+ }
+}
+
+bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
+{
+ wxCHECK_MSG(Ok(), false, wxT("wxDC::DoGetPartialTextExtents - invalid DC"));
+
+ widths.Empty();
+ widths.Add(0, text.length());
+
+ if (text.length() == 0)
+ return false;
+
+ wxMacFastPortSetter helper(this) ;
+ MacInstallFont() ;
+
+ OSStatus status = noErr ;
+ ATSUTextLayout atsuLayout ;
+
+ wxMacUniCharBuffer unibuf( text ) ;
+ UniCharCount chars = unibuf.GetChars() ;
+
+ status = ::ATSUCreateTextLayoutWithTextPtr( unibuf.GetBuffer() , 0 , chars , chars , 1 ,
+ &chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
+
+ wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the text") );
+
+ status = ::ATSUSetTransientFontMatching( atsuLayout , true ) ;
+ wxASSERT_MSG( status == noErr , wxT("couldn't setup transient font matching") );
+
+ ATSLineLayoutOptions layoutOptions = kATSLineNoLayoutOptions ;
+
+ if (m_font.GetNoAntiAliasing())
+ {
+ layoutOptions |= kATSLineNoAntiAliasing ;
+ }
+
+ ATSUAttributeTag atsuTags[] =
+ {
+ kATSULineLayoutOptionsTag ,
+ } ;
+
+ ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+ {
+ sizeof( ATSLineLayoutOptions ) ,
+ } ;
+
+ ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+ {
+ &layoutOptions ,
+ } ;
+
+ status = ::ATSUSetLayoutControls(atsuLayout , sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
+ atsuTags, atsuSizes, atsuValues ) ;
+
+ 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 false;
+
+ widths[pos] = XDEV2LOGREL(FixedToInt( glyphBounds.upperRight.x - glyphBounds.upperLeft.x ));
+ }
+
+ ::ATSUDisposeTextLayout(atsuLayout);
+
+ return true;
+}
+
+wxCoord wxDC::GetCharWidth(void) const
+{
+ wxCoord width = 0 ;
+ DoGetTextExtent( wxT("g"), &width , NULL , NULL , NULL , NULL ) ;
+ return width ;
+}
+
+wxCoord wxDC::GetCharHeight(void) const
+{
+ wxCoord height ;
+ DoGetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL ) ;
+ return height ;
+}
+
+void wxDC::Clear(void)
+{
+ wxCHECK_RET(Ok(), wxT("wxDC::Clear - invalid DC"));
+
+ wxMacFastPortSetter helper(this) ;
+ Rect rect = { -31000 , -31000 , 31000 , 31000 } ;
+
+ if ( m_backgroundBrush.Ok() && m_backgroundBrush.GetStyle() != wxTRANSPARENT)
+ {
+ ::PenNormal() ;