From 520d9d631ada2c7dbfde8b54329050c1cfc662b7 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Fri, 17 Nov 2023 05:39:46 +0100 Subject: [PATCH] Properly handle overhang with RTL FlowDirection (#13631) --- .../Media/TextFormatting/TextLineImpl.cs | 9 +++++---- .../RestrictedHeight_VerticalAlign.expected.png | Bin 529 -> 528 bytes 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs index 09042b9d60..b4534fd274 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs @@ -1299,8 +1299,6 @@ namespace Avalonia.Media.TextFormatting } } - var overhangAfter = Math.Max(0, bounds.Bottom - height); - var width = widthIncludingWhitespace; for (var i = _textRuns.Length - 1; i >= 0; i--) @@ -1327,9 +1325,10 @@ namespace Avalonia.Media.TextFormatting } } - var start = GetParagraphOffsetX(width, widthIncludingWhitespace); + //The width of overhanging pixels ath the bottom + var overhangAfter = Math.Max(0, bounds.Bottom - height); //The width of overhanging pixels at the origin - var overhangLeading = Math.Max(0, start - bounds.Left); + var overhangLeading = bounds.Left; //The width of overhanging pixels at the end var overhangTrailing = Math.Max(0, bounds.Width - widthIncludingWhitespace); var hasOverflowed = width > _paragraphWidth; @@ -1339,6 +1338,8 @@ namespace Avalonia.Media.TextFormatting height = lineHeight; } + var start = GetParagraphOffsetX(width, widthIncludingWhitespace); + return new TextLineMetrics { HasOverflowed = hasOverflowed, diff --git a/tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png b/tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png index 30e2ca86621188f40d0080454681b72b4fcf83c7..c8320cdb97c182922987f97e07a33f1c68eff45e 100644 GIT binary patch delta 486 zcmbQpGJ$1+N&Rt87srr_IdAV67R`1LVS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