From fc266209a4e3e859ad28d581b34f7149e04cf69a Mon Sep 17 00:00:00 2001 From: donandren Date: Tue, 14 Jun 2016 12:58:20 +0300 Subject: [PATCH] WIP: more precise Line Height in Skia FormattedTextImpl --- src/Skia/Avalonia.Skia/FormattedTextImpl.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs index cc296257be..a3c4cc2b66 100644 --- a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs +++ b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs @@ -14,7 +14,7 @@ namespace Avalonia.Skia public FormattedTextImpl(string text, TextWrapping wrapping = TextWrapping.NoWrap) { - _text = text; + _text = text ?? string.Empty; _wrapping = wrapping; _paint = new SKPaint(); @@ -174,8 +174,9 @@ namespace Avalonia.Skia var mBottom = metrics.Bottom; // The greatest distance below the baseline for any glyph (will be >= 0). var mLeading = metrics.Leading; // The recommended distance to add between lines of text (will be >= 0). var mDescent = metrics.Descent; + var mAscent = metrics.Ascent; // This seems like the best measure of full vertical extent - LineHeight = mBottom - mTop; + LineHeight = mDescent - mAscent; // Rendering is relative to baseline LineOffset = -metrics.Top; @@ -220,7 +221,7 @@ namespace Avalonia.Skia _skiaLines.Add(line); - curY += LineHeight - mDescent; + curY += LineHeight; // TODO: We may want to consider adding Leading to the vertical line spacing but for now // it appears to make no difference. Revisit as part of FormattedText improvements. @@ -250,7 +251,7 @@ namespace Avalonia.Skia else { var lastLine = _skiaLines[_skiaLines.Count - 1]; - _size = new Size(maxX, lastLine.Top + lastLine.Height); + _size = new Size(maxX, lastLine.Top + lastLine.Height + mBottom - mDescent); } BuildRects();