From 9c3bfd2e92623bc475efc2fb261169d438e76e6e Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Wed, 5 May 2021 17:04:52 +0200 Subject: [PATCH 1/2] Add failing test --- .../Media/TextFormatting/TextShaperTests.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextShaperTests.cs diff --git a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextShaperTests.cs b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextShaperTests.cs new file mode 100644 index 0000000000..62d2c54ffe --- /dev/null +++ b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextShaperTests.cs @@ -0,0 +1,43 @@ +using System; +using System.Globalization; +using Avalonia.Media; +using Avalonia.Media.TextFormatting; +using Avalonia.UnitTests; +using Xunit; + +namespace Avalonia.Skia.UnitTests.Media.TextFormatting +{ + public class TextShaperTests + { + [Fact] + public void Should_Form_Clusters_For_BreakPairs() + { + using (Start()) + { + var text = "\n\r\n".AsMemory(); + + var glyphRun = TextShaper.Current.ShapeText( + text, + Typeface.Default, + 12, + CultureInfo.CurrentCulture); + + Assert.Equal(glyphRun.Characters.Length, text.Length); + Assert.Equal(glyphRun.GlyphClusters.Length, text.Length); + Assert.Equal(0, glyphRun.GlyphClusters[0]); + Assert.Equal(1, glyphRun.GlyphClusters[1]); + Assert.Equal(1, glyphRun.GlyphClusters[2]); + } + } + + private static IDisposable Start() + { + var disposable = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface + .With(renderInterface: new PlatformRenderInterface(null), + textShaperImpl: new TextShaperImpl(), + fontManagerImpl: new CustomFontManagerImpl())); + + return disposable; + } + } +} From a301d0beeb71e59ab20ac42c48794ab04411221a Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Wed, 5 May 2021 17:05:54 +0200 Subject: [PATCH 2/2] Fix cluster builder for break pairs --- src/Skia/Avalonia.Skia/TextShaperImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Skia/Avalonia.Skia/TextShaperImpl.cs b/src/Skia/Avalonia.Skia/TextShaperImpl.cs index 31724bfee9..5cf72e2ce8 100644 --- a/src/Skia/Avalonia.Skia/TextShaperImpl.cs +++ b/src/Skia/Avalonia.Skia/TextShaperImpl.cs @@ -87,7 +87,7 @@ namespace Avalonia.Skia { var nextCodepoint = Codepoint.ReadAt(text, i + 1, out _); - if (nextCodepoint == '\r' && codepoint == '\n' || nextCodepoint == '\n' && codepoint == '\r') + if (nextCodepoint == '\n' && codepoint == '\r') { count++;