Reputation: 1485
I'm creating a custom control with skiasharp and xamarin forms. Something I've run into is when I try draw text in the top left corner of my canvas I have to offset the y co ord in order for the text to render within the canvas. I'd expect the x y co ord of the text to be in the same position as the x y co ord of the rect. What am I missing?
Using Skiasharp.View.Forms - v1.68.1 off nuget
Thanks!
protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
{
base.OnPaintSurface(args);
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
canvas.Save();
using var paint = new SKPaint {IsAntialias = true, Color = Color.Black.ToSKColor(), Style = SKPaintStyle.Stroke};
canvas.DrawRect(0, 0, info.Width, info.Height, paint);
canvas.DrawText("Off screen", 0, 0, paint);
canvas.DrawText("On screen", 0, 10, paint);
canvas.Restore();
}
Upvotes: 1
Views: 1718
Reputation: 14475
You could set y coordinate as SKPaint.FontSpacing
, it is the recommend line spacing.
canvas.DrawText("SKCanvasView Height and Width:", 0, paint.FontSpacing, paint);
Upvotes: 3