MockTextShaperImpl.cs 997 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Globalization;
  2. using Avalonia.Media;
  3. using Avalonia.Media.TextFormatting;
  4. using Avalonia.Media.TextFormatting.Unicode;
  5. using Avalonia.Platform;
  6. using Avalonia.Utilities;
  7. namespace Avalonia.UnitTests
  8. {
  9. public class MockTextShaperImpl : ITextShaperImpl
  10. {
  11. public ShapedBuffer ShapeText(ReadOnlySlice<char> text, GlyphTypeface typeface, double fontRenderingEmSize,
  12. CultureInfo culture, sbyte bidiLevel)
  13. {
  14. var shapedBuffer = new ShapedBuffer(text, text.Length, typeface, fontRenderingEmSize, bidiLevel);
  15. for (var i = 0; i < shapedBuffer.Length;)
  16. {
  17. var glyphCluster = i + text.Start;
  18. var codepoint = Codepoint.ReadAt(text, i, out var count);
  19. var glyphIndex = typeface.GetGlyph(codepoint);
  20. shapedBuffer[i] = new GlyphInfo(glyphIndex, glyphCluster, 10);
  21. i += count;
  22. }
  23. return shapedBuffer;
  24. }
  25. }
  26. }