Browse Source

Make sure glyphInfos usage is always in within bounds (#16120)

pull/16153/head
Benedikt Stebner 2 years ago
committed by GitHub
parent
commit
eb882213be
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      src/Avalonia.Base/Media/GlyphRun.cs
  2. 19
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLayoutTests.cs

7
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;

19
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<TextRunProperties>(1, 1,
new GenericTextRunProperties(typeface, foregroundBrush: Brushes.White))
});
Assert.NotNull(textLayout);
}
}
private static IDisposable Start()
{

Loading…
Cancel
Save