FontManager.Internals.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Drawing;
  3. namespace FastReport
  4. {
  5. public static partial class FontManager
  6. {
  7. // do not remove
  8. private static readonly FontFamilyMatcher fontFamilyMatcher = new FontFamilyMatcher();
  9. [Flags]
  10. private enum SearchScope
  11. {
  12. Temporary = 0x1,
  13. Private = 0x2,
  14. Installed = 0x4,
  15. NonInstalled = Temporary | Private,
  16. All = Temporary | Private | Installed
  17. }
  18. // Defines a font substitute item.
  19. private class FontSubstitute
  20. {
  21. private string[] _substituteList;
  22. private FontFamily _substituteFamily;
  23. public string Name { get; }
  24. // null value indicates that no substitute found
  25. public FontFamily SubstituteFamily => _substituteFamily ?? FindSubstituteFamily(SearchScope.NonInstalled);
  26. private FontFamily FindSubstituteFamily(SearchScope searchScope)
  27. {
  28. foreach (var item in _substituteList)
  29. {
  30. var family = FindFontFamily(item, searchScope);
  31. if (family != null)
  32. {
  33. return family;
  34. }
  35. }
  36. return null;
  37. }
  38. public FontSubstitute(string name, params string[] substituteList)
  39. {
  40. Name = name;
  41. _substituteList = substituteList;
  42. // do initial search in installed fonts. Other collections should be checked later.
  43. _substituteFamily = FindSubstituteFamily(SearchScope.Installed);
  44. }
  45. }
  46. // used in the FR FontConverter to look up family name in all font collections
  47. private class FontFamilyMatcher : FastReport.TypeConverters.FontConverter.IFontFamilyMatcher
  48. {
  49. public FontFamilyMatcher()
  50. {
  51. FastReport.TypeConverters.FontConverter.FontFamilyMatcher = this;
  52. }
  53. public FontFamily GetFontFamilyOrDefault(string name) => FontManager.GetFontFamilyOrDefault(name);
  54. }
  55. }
  56. }