using System;
using System.Globalization;
using Avalonia.Platform;
using Avalonia.Utilities;
namespace Avalonia.Media.TextFormatting
{
///
/// A class that is responsible for text shaping.
///
public class TextShaper
{
private readonly ITextShaperImpl _platformImpl;
public TextShaper(ITextShaperImpl platformImpl)
{
_platformImpl = platformImpl;
}
///
/// Gets the current text shaper.
///
public static TextShaper Current
{
get
{
var current = AvaloniaLocator.Current.GetService();
if (current != null)
{
return current;
}
var textShaperImpl = AvaloniaLocator.Current.GetService();
if (textShaperImpl == null)
throw new InvalidOperationException("No text shaper implementation was registered.");
current = new TextShaper(textShaperImpl);
AvaloniaLocator.CurrentMutable.Bind().ToConstant(current);
return current;
}
}
///
public ShapedBuffer ShapeText(ReadOnlySlice text, GlyphTypeface typeface, double fontRenderingEmSize,
CultureInfo? culture, sbyte bidiLevel)
{
return _platformImpl.ShapeText(text, typeface, fontRenderingEmSize, culture, bidiLevel);
}
}
}