From 5921d359c83a4149680265a9358172fe7e52b33d Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 4 Nov 2019 15:08:21 +0000 Subject: [PATCH 1/3] fix hit testing skia formatted text. --- src/Skia/Avalonia.Skia/FormattedTextImpl.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs index eb7b65cdce..718d10a694 100644 --- a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs +++ b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs @@ -99,9 +99,17 @@ namespace Avalonia.Skia public TextHitTestResult HitTestPoint(Point point) { float y = (float)point.Y; - var line = _skiaLines.Find(l => l.Top <= y && (l.Top + l.Height) > y); - if (!line.Equals(default(AvaloniaFormattedTextLine))) + AvaloniaFormattedTextLine line = default; + + int i = 0; + + while(_skiaLines[i].Top < y && i < _skiaLines.Count) + { + line = _skiaLines[i++]; + } + + if (!line.Equals(default)) { var rects = GetRects(); From 075aeecebf1694d4c35c27f75a164a9280e9f784 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 4 Nov 2019 15:59:17 +0000 Subject: [PATCH 2/3] fix skia formatted text impl hit testing. --- src/Skia/Avalonia.Skia/FormattedTextImpl.cs | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs index 718d10a694..dfdbfef136 100644 --- a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs +++ b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs @@ -102,12 +102,17 @@ namespace Avalonia.Skia AvaloniaFormattedTextLine line = default; - int i = 0; - - while(_skiaLines[i].Top < y && i < _skiaLines.Count) + foreach(var currentLine in _skiaLines) { - line = _skiaLines[i++]; - } + if(currentLine.Top <= y) + { + line = currentLine; + } + else + { + break; + } + } if (!line.Equals(default)) { @@ -135,12 +140,15 @@ namespace Avalonia.Skia line.Length : (line.Length - 1); } - return new TextHitTestResult + if (y < line.Top + line.Height) { - IsInside = false, - TextPosition = line.Start + offset, - IsTrailing = Text.Length == (line.Start + offset + 1) - }; + return new TextHitTestResult + { + IsInside = false, + TextPosition = line.Start + offset, + IsTrailing = Text.Length == (line.Start + offset + 1) + }; + } } bool end = point.X > _bounds.Width || point.Y > _lines.Sum(l => l.Height); From eb1241eea36d45b000792f373952e9e58df6e321 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 4 Nov 2019 16:26:45 +0000 Subject: [PATCH 3/3] fix skia formatted text unit tests. --- src/Skia/Avalonia.Skia/FormattedTextImpl.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs index dfdbfef136..a5e56b1d7a 100644 --- a/src/Skia/Avalonia.Skia/FormattedTextImpl.cs +++ b/src/Skia/Avalonia.Skia/FormattedTextImpl.cs @@ -102,14 +102,18 @@ namespace Avalonia.Skia AvaloniaFormattedTextLine line = default; + float nextTop = 0; + foreach(var currentLine in _skiaLines) { if(currentLine.Top <= y) { line = currentLine; + nextTop = currentLine.Top + currentLine.Height; } else { + nextTop = currentLine.Top; break; } } @@ -140,7 +144,7 @@ namespace Avalonia.Skia line.Length : (line.Length - 1); } - if (y < line.Top + line.Height) + if (y < nextTop) { return new TextHitTestResult {