Jump to content

Recommended Posts

All I actually want is to draw text that is orientated 90 degrees to the horizontally, ie vertical. No fancy paths to follow, just a straight line. I can currently do it by rotating the image first by 90 degress, writing the text horizontally, then rotate the image back -90 degrees.

Share this post


Link to post
6 hours ago, hsauro said:

All I actually want is to draw text that is orientated 90 degrees to the horizontally, ie vertical. No fancy paths to follow, just a straight line. I can currently do it by rotating the image first by 90 degress, writing the text horizontally, then rotate the image back -90 degrees.

The correct way is to rotate only the drawing you are doing, in this case the text. For this you must rotate by ISkCanvas:

 

uses
  System.Math, System.Math.Vectors, Skia;

procedure TForm1.SkPaintBox1Draw(ASender: TObject; const ACanvas: ISkCanvas;
  const ADest: TRectF; const AOpacity: Single);
var
  LDest: TPointF;
begin
  LDest := PointF(150, 50);
  ACanvas.Clear(TAlphaColors.Null);
  ACanvas.Save;
  try
    ACanvas.DrawSimpleText('Skia4Delphi 1', LDest.X, LDest.Y, TSkFont.Create, TSkPaint.Create);
    ACanvas.Rotate(90);
    LDest := LDest * TMatrix.CreateRotation(DegToRad(-90));
    ACanvas.DrawSimpleText('Skia4Delphi 2', LDest.X, LDest.Y, TSkFont.Create, TSkPaint.Create);
  finally
    ACanvas.Restore;
  end;
end;

Results:

image.thumb.png.6bd71aa91988e970c3bc37fc0cd058c1.png

 

Note: I made the adjustment of LDest with TMatrix.CreateRotation because when rotating the canvas, its X and Y of DrawSimpleText are also rotated.

Edited by vfbb

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×