Skip to content

Instantly share code, notes, and snippets.

@benoitjadinon
Last active August 27, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoitjadinon/f0d62c094689aa2e4c8824afb1690f62 to your computer and use it in GitHub Desktop.
Save benoitjadinon/f0d62c094689aa2e4c8824afb1690f62 to your computer and use it in GitHub Desktop.
DrawTextCenteredVertically
/// <remarks>https://stackoverflow.com/questions/27631736/meaning-of-top-ascent-baseline-descent-bottom-and-leading-in-androids-font</remarks>
public static void DrawTextCenteredVertically(this SKCanvas canvas, string text, SKPaint paint, SKPoint point)
{
var textY = point.Y + (((-paint.FontMetrics.Ascent + paint.FontMetrics.Descent) / 2) - (paint.FontMetrics.Descent /2)); // seems to work better with descent/2
canvas.DrawText(text, point.X, textY, paint);
}
@benoitjadinon
Copy link
Author

Explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment