Search code examples
c#rotationdirect2dsharpdxdirectwrite

SharpDX DirectWrite rotate text


I wondered how to rotate a text rendered with Direct2D with SharpDX.

Can not find any possiblity in

RenderTarget2D.DrawText()

or

RenderTarget2D.DrawTextLayout()


Solution

  • You could use a Transformation Matrix and more precisely - a rotation transformation via a 3x2 matrix.

    pseudo example:

    RenderTarget2D.BeginDraw;
    try
      // your regular drawings
      ....
    
      // save the current tranform
      currentTransform = RenderTarget2D.GetTransform;
    
      // set a 90 degree rotation around the (100,100);
      RenderTarget2D.SetTransform(Matrix3x2F.Rotation(90, Point2F(100,100))); 
    
      // do your rotated text drawings
      RenderTarget2D.DrawText();
    
      // restore your previous/original transform
      RenderTarget2D.SetTransform(currentTransform);
    finally
      RenderTarget2D.EndDraw;
    end;