Applying Graphic Transformations to a Text Graphic

IGraphicText supports the IMGraphic functions for graphic transformations, including scaling, rotating, and translating.

To apply a transformation to an existing IGraphicText object:

  1. Create an IGrafMatrix representing the transform.
  2. Call the IGraphicText::transformBy function to apply the transformation.

Instead of creating and applying a matrix, you can also use one of the convenience functions, rotateBy, translateBy, or scaleBy.

  1. Call the IGraphicText::draw function to draw the transformed graphic.

Some transformations, such as rotation, may cause the bounding rectangle to change slightly. Apply the transformation before computing and using the bounds.

For example, this code shows how to rotate and center a text graphic in the IGrafPort port:

// create the ITextGraphic

IText string("Hello World!");

string.addStyles(ITextTypeFaceStyle("Helvetica"));

ITextGraphic graphic(string, ITextGraphic::kSingleLine);



// apply the transformation

graphic.rotateBy(45);



// center the bounding rectangle within the bounding rectangle 
of the port

IGRect2D portBounds = port.worldBounds();

IGRect2D graph,icBounds = graphic.looseFitBounds(&port);

graph,ic.translateBy(portBounds.center() - graphicBounds.center());



// draw the graphic

graphic.draw(port);