From b9ff1b23c3e09acb9161116907cb37a4756e19e9 Mon Sep 17 00:00:00 2001 From: Benedikt Schroeder Date: Fri, 9 Oct 2020 18:39:09 +0200 Subject: [PATCH] Make sure we don't crash when RTL text is wrapped --- .../Media/TextFormatting/TextFormatterImpl.cs | 10 +++++++++- src/Skia/Avalonia.Skia/TextShaperImpl.cs | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs b/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs index 4a7282af27..394dae8253 100644 --- a/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs +++ b/src/Avalonia.Visuals/Media/TextFormatting/TextFormatterImpl.cs @@ -126,7 +126,15 @@ namespace Avalonia.Media.TextFormatting var lastCluster = glyphRun.GlyphClusters[glyphCount]; - count = lastCluster - firstCluster; + if (glyphRun.IsLeftToRight) + { + count = lastCluster - firstCluster; + } + else + { + count = firstCluster - lastCluster; + } + return count > 0; } diff --git a/src/Skia/Avalonia.Skia/TextShaperImpl.cs b/src/Skia/Avalonia.Skia/TextShaperImpl.cs index 61075171fe..31724bfee9 100644 --- a/src/Skia/Avalonia.Skia/TextShaperImpl.cs +++ b/src/Skia/Avalonia.Skia/TextShaperImpl.cs @@ -64,7 +64,8 @@ namespace Avalonia.Skia new ReadOnlySlice(glyphAdvances), new ReadOnlySlice(glyphOffsets), text, - new ReadOnlySlice(clusters)); + new ReadOnlySlice(clusters), + buffer.Direction == Direction.LeftToRight ? 0 : 1); } }