Browse Source

Rewrite TextBounds test

pull/7946/head
Benedikt Stebner 4 years ago
parent
commit
0cdbd53bc3
  1. 19
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

19
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs

@ -665,14 +665,17 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
var text = "0123".AsMemory();
var shaperOption = new TextShaperOptions(Typeface.Default.GlyphTypeface, 10, 0, CultureInfo.CurrentCulture);
var shapedBuffer = TextShaper.Current.ShapeText(new ReadOnlySlice<char>(text), shaperOption);
var firstRun = new ShapedTextCharacters(shapedBuffer, defaultProperties);
var textRuns = new List<TextRun>
{
new ShapedTextCharacters(TextShaper.Current.ShapeText(new ReadOnlySlice<char>(text), shaperOption), defaultProperties),
new CustomDrawableRun(),
new ShapedTextCharacters(TextShaper.Current.ShapeText(new ReadOnlySlice<char>(text, text.Length + 1, text.Length), shaperOption), defaultProperties),
firstRun,
new CustomDrawableRun(),
new ShapedTextCharacters(TextShaper.Current.ShapeText(new ReadOnlySlice<char>(text, text.Length * 2 + 2, text.Length), shaperOption), defaultProperties),
new ShapedTextCharacters(shapedBuffer, defaultProperties),
new CustomDrawableRun(),
new ShapedTextCharacters(shapedBuffer, defaultProperties)
};
var textSource = new FixedRunsTextSource(textRuns);
@ -687,6 +690,16 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
Assert.Equal(1, textBounds.Count);
Assert.Equal(textLine.WidthIncludingTrailingWhitespace, textBounds.Sum(x => x.Rectangle.Width));
textBounds = textLine.GetTextBounds(0, firstRun.Text.Length);
Assert.Equal(1, textBounds.Count);
Assert.Equal(firstRun.Size.Width, textBounds[0].Rectangle.Width);
textBounds = textLine.GetTextBounds(0, firstRun.Text.Length + 1);
Assert.Equal(1, textBounds.Count);
Assert.Equal(firstRun.Size.Width + 14, textBounds[0].Rectangle.Width);
}
}

Loading…
Cancel
Save