TextShaperTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Globalization;
  3. using Avalonia.Media;
  4. using Avalonia.Media.TextFormatting;
  5. using Avalonia.UnitTests;
  6. using Xunit;
  7. namespace Avalonia.Skia.UnitTests.Media.TextFormatting
  8. {
  9. public class TextShaperTests
  10. {
  11. [Fact]
  12. public void Should_Form_Clusters_For_BreakPairs()
  13. {
  14. using (Start())
  15. {
  16. var text = "\n\r\n";
  17. var options = new TextShaperOptions(Typeface.Default.GlyphTypeface, 12,0, CultureInfo.CurrentCulture);
  18. var shapedBuffer = TextShaper.Current.ShapeText(text, options);
  19. Assert.Equal(shapedBuffer.Length, text.Length);
  20. Assert.Equal(shapedBuffer.Length, text.Length);
  21. Assert.Equal(0, shapedBuffer[0].GlyphCluster);
  22. Assert.Equal(1, shapedBuffer[1].GlyphCluster);
  23. Assert.Equal(1, shapedBuffer[2].GlyphCluster);
  24. }
  25. }
  26. [Fact]
  27. public void Should_Apply_IncrementalTabWidth()
  28. {
  29. using (Start())
  30. {
  31. var text = "012345\t";
  32. var options = new TextShaperOptions(Typeface.Default.GlyphTypeface, 12, 0, CultureInfo.CurrentCulture, 100);
  33. var shapedBuffer = TextShaper.Current.ShapeText(text.AsMemory().Slice(6), options);
  34. Assert.Equal(1, shapedBuffer.Length);
  35. Assert.Equal(100, shapedBuffer[0].GlyphAdvance);
  36. }
  37. }
  38. private static IDisposable Start()
  39. {
  40. var disposable = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface
  41. .With(renderInterface: new PlatformRenderInterface(null),
  42. textShaperImpl: new TextShaperImpl(),
  43. fontManagerImpl: new CustomFontManagerImpl()));
  44. return disposable;
  45. }
  46. }
  47. }