MockFontManagerImpl.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Diagnostics.CodeAnalysis;
  2. using System.Globalization;
  3. using System.IO;
  4. using Avalonia.Media;
  5. using Avalonia.Platform;
  6. namespace Avalonia.UnitTests
  7. {
  8. public class MockFontManagerImpl : IFontManagerImpl
  9. {
  10. private readonly string _defaultFamilyName;
  11. public MockFontManagerImpl(string defaultFamilyName = "Default")
  12. {
  13. _defaultFamilyName = defaultFamilyName;
  14. }
  15. public int TryCreateGlyphTypefaceCount { get; private set; }
  16. public string GetDefaultFontFamilyName()
  17. {
  18. return _defaultFamilyName;
  19. }
  20. string[] IFontManagerImpl.GetInstalledFontFamilyNames(bool checkForUpdates)
  21. {
  22. return new[] { _defaultFamilyName };
  23. }
  24. public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight,
  25. FontStretch fontStretch,
  26. CultureInfo culture, out Typeface fontKey)
  27. {
  28. fontKey = new Typeface(_defaultFamilyName);
  29. return false;
  30. }
  31. public virtual bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeight weight,
  32. FontStretch stretch, [NotNullWhen(true)] out IGlyphTypeface glyphTypeface)
  33. {
  34. glyphTypeface = null;
  35. TryCreateGlyphTypefaceCount++;
  36. if (familyName == "Unknown")
  37. {
  38. return false;
  39. }
  40. glyphTypeface = new MockGlyphTypeface();
  41. return true;
  42. }
  43. public virtual bool TryCreateGlyphTypeface(Stream stream, out IGlyphTypeface glyphTypeface)
  44. {
  45. glyphTypeface = new MockGlyphTypeface();
  46. return true;
  47. }
  48. }
  49. }