FontSystemSettings.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using FontStashSharp.Interfaces;
  3. #if MONOGAME || FNA
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Graphics;
  6. #elif STRIDE
  7. using Stride.Core.Mathematics;
  8. using Stride.Graphics;
  9. using Texture2D = Stride.Graphics.Texture;
  10. #else
  11. using System.Drawing;
  12. using System.Numerics;
  13. using Texture2D = Veldrid.Texture;
  14. #endif
  15. namespace FontStashSharp
  16. {
  17. public enum FontSystemEffect
  18. {
  19. None,
  20. Blurry,
  21. Stroked
  22. }
  23. public class FontSystemSettings
  24. {
  25. private int _effectAmount = 0;
  26. private int _textureWidth = 1024, _textureHeight = 1024;
  27. private float _fontResolutionFactor = 1.0f;
  28. private int _kernelWidth = 0, _kernelHeight = 0;
  29. public int TextureWidth
  30. {
  31. get => _textureWidth;
  32. set
  33. {
  34. if (value <= 0)
  35. {
  36. throw new ArgumentOutOfRangeException(nameof(value));
  37. }
  38. _textureWidth = value;
  39. }
  40. }
  41. public int TextureHeight
  42. {
  43. get => _textureHeight;
  44. set
  45. {
  46. if (value <= 0)
  47. {
  48. throw new ArgumentOutOfRangeException(nameof(value));
  49. }
  50. _textureHeight = value;
  51. }
  52. }
  53. public bool PremultiplyAlpha { get; set; } = true;
  54. public int EffectAmount
  55. {
  56. get => _effectAmount;
  57. set
  58. {
  59. if (value < 0 || value > 20)
  60. {
  61. throw new ArgumentOutOfRangeException(nameof(value));
  62. }
  63. _effectAmount = value;
  64. }
  65. }
  66. public FontSystemEffect Effect { get; set; } = FontSystemEffect.None;
  67. public float FontResolutionFactor
  68. {
  69. get => _fontResolutionFactor;
  70. set
  71. {
  72. if (value < 0)
  73. {
  74. throw new ArgumentOutOfRangeException(nameof(value), value, "This cannot be smaller than 0");
  75. }
  76. _fontResolutionFactor = value;
  77. }
  78. }
  79. public int KernelWidth
  80. {
  81. get => _kernelWidth;
  82. set
  83. {
  84. if (value < 0)
  85. {
  86. throw new ArgumentOutOfRangeException(nameof(value), value, "This cannot be smaller than 0");
  87. }
  88. _kernelWidth = value;
  89. }
  90. }
  91. public int KernelHeight
  92. {
  93. get => _kernelHeight;
  94. set
  95. {
  96. if (value < 0)
  97. {
  98. throw new ArgumentOutOfRangeException(nameof(value), value, "This cannot be smaller than 0");
  99. }
  100. _kernelHeight = value;
  101. }
  102. }
  103. /// <summary>
  104. /// Use existing texture for storing glyphs
  105. /// If this is set, then TextureWidth & TextureHeight are ignored
  106. /// </summary>
  107. public Texture2D ExistingTexture { get; set; }
  108. /// <summary>
  109. /// Defines rectangle of the used space in the ExistingTexture
  110. /// </summary>
  111. public Rectangle ExistingTextureUsedSpace { get; set; }
  112. /// <summary>
  113. /// Font Rasterizer. If set to null then default rasterizer(StbTrueTypeSharp) is used.
  114. /// </summary>
  115. public IFontLoader FontLoader { get; set; }
  116. public FontSystemSettings()
  117. {
  118. TextureWidth = FontSystemDefaults.TextureWidth;
  119. TextureHeight = FontSystemDefaults.TextureHeight;
  120. PremultiplyAlpha = FontSystemDefaults.PremultiplyAlpha;
  121. Effect = FontSystemDefaults.Effect;
  122. EffectAmount = FontSystemDefaults.EffectAmount;
  123. FontResolutionFactor = FontSystemDefaults.FontResolutionFactor;
  124. KernelWidth = FontSystemDefaults.KernelWidth;
  125. KernelHeight = FontSystemDefaults.KernelHeight;
  126. FontLoader = FontSystemDefaults.FontLoader;
  127. }
  128. public FontSystemSettings Clone()
  129. {
  130. return new FontSystemSettings
  131. {
  132. Effect = Effect,
  133. EffectAmount = EffectAmount,
  134. TextureWidth = TextureWidth,
  135. TextureHeight = TextureHeight,
  136. PremultiplyAlpha = PremultiplyAlpha,
  137. FontResolutionFactor = FontResolutionFactor,
  138. KernelWidth = KernelWidth,
  139. KernelHeight = KernelHeight,
  140. ExistingTexture = ExistingTexture,
  141. ExistingTextureUsedSpace = ExistingTextureUsedSpace,
  142. FontLoader = FontLoader
  143. };
  144. }
  145. }
  146. }