MockGlyphTypeface.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using Avalonia.Media;
  3. namespace Avalonia.UnitTests
  4. {
  5. public class MockGlyphTypeface : IGlyphTypeface
  6. {
  7. public FontMetrics Metrics => new FontMetrics
  8. {
  9. DesignEmHeight = 10,
  10. Ascent = 2,
  11. Descent = 10,
  12. IsFixedPitch = true
  13. };
  14. public int GlyphCount => 1337;
  15. public FontSimulations FontSimulations => throw new NotImplementedException();
  16. public ushort GetGlyph(uint codepoint)
  17. {
  18. return (ushort)codepoint;
  19. }
  20. public ushort[] GetGlyphs(ReadOnlySpan<uint> codepoints)
  21. {
  22. return new ushort[codepoints.Length];
  23. }
  24. public int GetGlyphAdvance(ushort glyph)
  25. {
  26. return 8;
  27. }
  28. public bool TryGetGlyph(uint codepoint, out ushort glyph)
  29. {
  30. glyph = 8;
  31. return true;
  32. }
  33. public int[] GetGlyphAdvances(ReadOnlySpan<ushort> glyphs)
  34. {
  35. var advances = new int[glyphs.Length];
  36. for (var i = 0; i < advances.Length; i++)
  37. {
  38. advances[i] = 8;
  39. }
  40. return advances;
  41. }
  42. public void Dispose() { }
  43. public bool TryGetTable(uint tag, out byte[] table)
  44. {
  45. table = null;
  46. return false;
  47. }
  48. public bool TryGetGlyphMetrics(ushort glyph, out GlyphMetrics metrics)
  49. {
  50. metrics = new GlyphMetrics
  51. {
  52. Width = 10,
  53. Height = 10
  54. };
  55. return true;
  56. }
  57. }
  58. }