TextSpanDescriptorExtensions.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.Fluent
  5. {
  6. public static class TextSpanDescriptorExtensions
  7. {
  8. public static T Style<T>(this T descriptor, TextStyle style) where T : TextSpanDescriptor
  9. {
  10. if (style == null)
  11. return descriptor;
  12. descriptor.TextStyle.OverrideStyle(style);
  13. return descriptor;
  14. }
  15. public static T FontColor<T>(this T descriptor, string value) where T : TextSpanDescriptor
  16. {
  17. descriptor.TextStyle.Color = value;
  18. return descriptor;
  19. }
  20. public static T BackgroundColor<T>(this T descriptor, string value) where T : TextSpanDescriptor
  21. {
  22. descriptor.TextStyle.BackgroundColor = value;
  23. return descriptor;
  24. }
  25. public static T FontFamily<T>(this T descriptor, string value) where T : TextSpanDescriptor
  26. {
  27. descriptor.TextStyle.FontFamily = value;
  28. return descriptor;
  29. }
  30. public static T FontSize<T>(this T descriptor, float value) where T : TextSpanDescriptor
  31. {
  32. descriptor.TextStyle.Size = value;
  33. return descriptor;
  34. }
  35. public static T LineHeight<T>(this T descriptor, float value) where T : TextSpanDescriptor
  36. {
  37. descriptor.TextStyle.LineHeight = value;
  38. return descriptor;
  39. }
  40. public static T Italic<T>(this T descriptor, bool value = true) where T : TextSpanDescriptor
  41. {
  42. descriptor.TextStyle.IsItalic = value;
  43. return descriptor;
  44. }
  45. public static T Strikethrough<T>(this T descriptor, bool value = true) where T : TextSpanDescriptor
  46. {
  47. descriptor.TextStyle.HasStrikethrough = value;
  48. return descriptor;
  49. }
  50. public static T Underline<T>(this T descriptor, bool value = true) where T : TextSpanDescriptor
  51. {
  52. descriptor.TextStyle.HasUnderline = value;
  53. return descriptor;
  54. }
  55. public static T WrapAnywhere<T>(this T descriptor, bool value = true) where T : TextSpanDescriptor
  56. {
  57. descriptor.TextStyle.WrapAnywhere = value;
  58. return descriptor;
  59. }
  60. #region Weight
  61. public static T Weight<T>(this T descriptor, FontWeight weight) where T : TextSpanDescriptor
  62. {
  63. descriptor.TextStyle.FontWeight = weight;
  64. return descriptor;
  65. }
  66. public static T Thin<T>(this T descriptor) where T : TextSpanDescriptor
  67. {
  68. return descriptor.Weight(FontWeight.Thin);
  69. }
  70. public static T ExtraLight<T>(this T descriptor) where T : TextSpanDescriptor
  71. {
  72. return descriptor.Weight(FontWeight.ExtraLight);
  73. }
  74. public static T Light<T>(this T descriptor) where T : TextSpanDescriptor
  75. {
  76. return descriptor.Weight(FontWeight.Light);
  77. }
  78. public static T NormalWeight<T>(this T descriptor) where T : TextSpanDescriptor
  79. {
  80. return descriptor.Weight(FontWeight.Normal);
  81. }
  82. public static T Medium<T>(this T descriptor) where T : TextSpanDescriptor
  83. {
  84. return descriptor.Weight(FontWeight.Medium);
  85. }
  86. public static T SemiBold<T>(this T descriptor) where T : TextSpanDescriptor
  87. {
  88. return descriptor.Weight(FontWeight.SemiBold);
  89. }
  90. public static T Bold<T>(this T descriptor) where T : TextSpanDescriptor
  91. {
  92. return descriptor.Weight(FontWeight.Bold);
  93. }
  94. public static T ExtraBold<T>(this T descriptor) where T : TextSpanDescriptor
  95. {
  96. return descriptor.Weight(FontWeight.ExtraBold);
  97. }
  98. public static T Black<T>(this T descriptor) where T : TextSpanDescriptor
  99. {
  100. return descriptor.Weight(FontWeight.Black);
  101. }
  102. public static T ExtraBlack<T>(this T descriptor) where T : TextSpanDescriptor
  103. {
  104. return descriptor.Weight(FontWeight.ExtraBlack);
  105. }
  106. #endregion
  107. #region Position
  108. public static T NormalPosition<T>(this T descriptor) where T : TextSpanDescriptor
  109. {
  110. return descriptor.Position(FontPosition.Normal);
  111. }
  112. public static T Subscript<T>(this T descriptor) where T : TextSpanDescriptor
  113. {
  114. return descriptor.Position(FontPosition.Subscript);
  115. }
  116. public static T Superscript<T>(this T descriptor) where T : TextSpanDescriptor
  117. {
  118. return descriptor.Position(FontPosition.Superscript);
  119. }
  120. private static T Position<T>(this T descriptor, FontPosition fontPosition) where T : TextSpanDescriptor
  121. {
  122. descriptor.TextStyle.FontPosition = fontPosition;
  123. return descriptor;
  124. }
  125. #endregion
  126. }
  127. }