Skip to content

Commit

Permalink
Make sure glyphInfos usage is always in within bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillibald committed Jun 26, 2024
1 parent f90afbb commit 8241014
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Avalonia.Base/Media/GlyphRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ public CharacterHit FindNearestCharacterHit(int index, out double width)
}
}

nextCluster = _glyphInfos[currentIndex].GlyphCluster;
if (_glyphInfos.Count > 0 && currentIndex <= _glyphInfos.Count)
{
nextCluster = _glyphInfos[currentIndex].GlyphCluster;
}
}

var clusterLength = Math.Max(0, nextCluster - cluster);
Expand Down Expand Up @@ -639,7 +642,7 @@ private GlyphRunMetrics CreateGlyphRunMetrics()
{
int firstCluster, lastCluster;

if (Characters.IsEmpty)
if (Characters.IsEmpty || _glyphInfos.Count == 0)
{
firstCluster = 0;
lastCluster = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,25 @@ public void Should_HitTestTextPosition_EndOfLine_RTL()
}
}

[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()
{
Expand Down

0 comments on commit 8241014

Please sign in to comment.