A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

36 lines
1.1 KiB

using System;
using Avalonia.Media.TextFormatting;
namespace Avalonia.Skia.UnitTests.Media.TextFormatting
{
internal class SingleBufferTextSource : ITextSource
{
private readonly string _text;
private readonly GenericTextRunProperties _defaultGenericPropertiesRunProperties;
private readonly bool _addEndOfParagraph;
public SingleBufferTextSource(string text, GenericTextRunProperties defaultProperties, bool addEndOfParagraph = false)
{
_text = text;
_defaultGenericPropertiesRunProperties = defaultProperties;
_addEndOfParagraph = addEndOfParagraph;
}
public TextRun GetTextRun(int textSourceIndex)
{
if (textSourceIndex >= _text.Length)
{
return _addEndOfParagraph ? new TextEndOfParagraph() : null;
}
var runText = _text.AsMemory(textSourceIndex);
if (runText.IsEmpty)
{
return _addEndOfParagraph ? new TextEndOfParagraph() : null;
}
return new TextCharacters(runText, _defaultGenericPropertiesRunProperties);
}
}
}