Using TTextGraphic

Use TTextGraphic instead of TTextDisplay when you want to transform the text or use it interchangeably with other MGraphic derived classes.

TTextGraphic encapsulates a TTextDisplay; you can construct a TTextGraphic from a TTextDisplay, or directly from a text object. If you construct a TTextGraphic from a text object, you can also specify:

If you don't specify these values, the encapsulated text display uses the defaults as described in "Text display options and defaults" on page 69.

For example, this code shows how to create a simple text graphic and rotate it around its center, drawing it into the TGrafPort thePort:

      TStandardText theText( "Hello World" );
      TFontPointSizeStyle size = TFontPointSizeStyle( 24.0 );
      theText.AddStyles( size )
      
      TTextGraphic theTextGraphic( theText, TGPoint( 100, 100 ) );
      
      TGrafMatrix aMatrix;
      TGRect bounds = theTextGraphic.GetGeometricBounds();
      aMatrix.RotateBy( 45, bounds.GetCenter() );
      theTextGraphic.TransformBy( aMatrix );
      
      theTextGraphic.Draw( thePort );

NOTE The MGraphic inheritance requires TTextGraphic to adopt a TGrafBundle. TTextGraphic does not define any default usage for the graf bundle, so the TTextGraphic::AdoptBundle function just deletes the bundle to avoid the unnecessary overhead of storing it.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker