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.
 
 
 

37 lines
1.0 KiB

using System;
using System.Globalization;
using Avalonia.Media;
using Avalonia.Media.TextFormatting.Unicode;
using Avalonia.Platform;
using Avalonia.Utilities;
namespace Avalonia.UnitTests
{
public class MockTextShaperImpl : ITextShaperImpl
{
public GlyphRun ShapeText(ReadOnlySlice<char> text, Typeface typeface, double fontRenderingEmSize, CultureInfo culture)
{
var glyphTypeface = typeface.GlyphTypeface;
var glyphIndices = new ushort[text.Length];
var glyphCount = 0;
for (var i = 0; i < text.Length;)
{
var index = i;
var codepoint = Codepoint.ReadAt(text, i, out var count);
i += count;
var glyph = glyphTypeface.GetGlyph(codepoint);
glyphIndices[index] = glyph;
glyphCount++;
}
return new GlyphRun(glyphTypeface, fontRenderingEmSize,
new ReadOnlySlice<ushort>(glyphIndices.AsMemory(0, glyphCount)), characters: text);
}
}
}