diff --git a/src/Avalonia.Base/Media/GlyphRun.cs b/src/Avalonia.Base/Media/GlyphRun.cs index 350f3ec028..a81dbdb3f0 100644 --- a/src/Avalonia.Base/Media/GlyphRun.cs +++ b/src/Avalonia.Base/Media/GlyphRun.cs @@ -574,7 +574,10 @@ namespace Avalonia.Media } } - nextCluster = _glyphInfos[currentIndex].GlyphCluster; + if (_glyphInfos.Count > 0 && currentIndex <= _glyphInfos.Count) + { + nextCluster = _glyphInfos[currentIndex].GlyphCluster; + } } var clusterLength = Math.Max(0, nextCluster - cluster); @@ -639,7 +642,7 @@ namespace Avalonia.Media { int firstCluster, lastCluster; - if (Characters.IsEmpty) + if (Characters.IsEmpty || _glyphInfos.Count == 0) { firstCluster = 0; lastCluster = 0; diff --git a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs index ac444e37df..cb9b378986 100644 --- a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs +++ b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs @@ -1127,6 +1127,25 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting } } + [Win32Fact("Font only available on Windows")] + public void Should_Handle_TextStyle_With_Ligature() + { + using (Start()) + { + var text = "fi"; + + var typeface = new Typeface("Calibri"); + + var textLayout = new TextLayout(text, typeface, 12, Brushes.Black, + textStyleOverrides: new[] + { + new ValueSpan(1, 1, + new GenericTextRunProperties(typeface, foregroundBrush: Brushes.White)) + }); + + Assert.NotNull(textLayout); + } + } private static IDisposable Start() {