FontStyleSetTests.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using FluentAssertions;
  2. using NUnit.Framework;
  3. using QuestPDF.Drawing;
  4. using SkiaSharp;
  5. using static SkiaSharp.SKFontStyleSlant;
  6. namespace QuestPDF.UnitTests
  7. {
  8. [TestFixture]
  9. public class FontStyleSetTests
  10. {
  11. private void ExpectComparisonOrder(SKFontStyle target, SKFontStyle[] styles)
  12. {
  13. for (var i = 0; i < styles.Length - 1; i++)
  14. {
  15. var currentStyle = styles[i];
  16. var nextStyle = styles[i + 1];
  17. FontStyleSet.IsBetterMatch(target, currentStyle, nextStyle).Should().BeTrue();
  18. FontStyleSet.IsBetterMatch(target, nextStyle, currentStyle).Should().BeFalse();
  19. }
  20. }
  21. [Test]
  22. public void FontStyleSet_IsBetterMatch_CondensedWidth()
  23. {
  24. var styles = new[]
  25. {
  26. new SKFontStyle(500, 5, Upright),
  27. new SKFontStyle(500, 4, Upright),
  28. new SKFontStyle(500, 3, Upright),
  29. new SKFontStyle(500, 6, Upright)
  30. };
  31. ExpectComparisonOrder(new SKFontStyle(500, 5, Upright), styles);
  32. }
  33. [Test]
  34. public void FontStyleSet_IsBetterMatch_ExpandedWidth()
  35. {
  36. var styles = new[]
  37. {
  38. new SKFontStyle(500, 6, Upright),
  39. new SKFontStyle(500, 7, Upright),
  40. new SKFontStyle(500, 8, Upright),
  41. new SKFontStyle(500, 5, Upright)
  42. };
  43. ExpectComparisonOrder(new SKFontStyle(500, 6, Upright), styles);
  44. }
  45. [Test]
  46. public void FontStyleSet_IsBetterMatch_ItalicSlant()
  47. {
  48. var styles = new[]
  49. {
  50. new SKFontStyle(500, 5, Italic),
  51. new SKFontStyle(500, 5, Oblique),
  52. new SKFontStyle(500, 5, Upright)
  53. };
  54. ExpectComparisonOrder(new SKFontStyle(500, 5, Italic), styles);
  55. }
  56. [Test]
  57. public void FontStyleSet_IsBetterMatch_ObliqueSlant()
  58. {
  59. var styles = new[]
  60. {
  61. new SKFontStyle(500, 5, Oblique),
  62. new SKFontStyle(500, 5, Italic),
  63. new SKFontStyle(500, 5, Upright)
  64. };
  65. ExpectComparisonOrder(new SKFontStyle(500, 5, Oblique), styles);
  66. }
  67. [Test]
  68. public void FontStyleSet_IsBetterMatch_UprightSlant()
  69. {
  70. var styles = new[]
  71. {
  72. new SKFontStyle(500, 5, Upright),
  73. new SKFontStyle(500, 5, Oblique),
  74. new SKFontStyle(500, 5, Italic)
  75. };
  76. ExpectComparisonOrder(new SKFontStyle(500, 5, Upright), styles);
  77. }
  78. [Test]
  79. public void FontStyleSet_IsBetterMatch_ThinWeight()
  80. {
  81. var styles = new[]
  82. {
  83. new SKFontStyle(300, 5, Upright),
  84. new SKFontStyle(200, 5, Upright),
  85. new SKFontStyle(100, 5, Upright),
  86. new SKFontStyle(400, 5, Upright)
  87. };
  88. ExpectComparisonOrder(new SKFontStyle(300, 5, Upright), styles);
  89. }
  90. [Test]
  91. public void FontStyleSet_IsBetterMatch_RegularWeight()
  92. {
  93. var styles = new[]
  94. {
  95. new SKFontStyle(500, 5, Upright),
  96. new SKFontStyle(300, 5, Upright),
  97. new SKFontStyle(100, 5, Upright),
  98. new SKFontStyle(600, 5, Upright)
  99. };
  100. ExpectComparisonOrder(new SKFontStyle(400, 5, Upright), styles);
  101. }
  102. [Test]
  103. public void FontStyleSet_IsBetterMatch_BoldWeight()
  104. {
  105. var styles = new[]
  106. {
  107. new SKFontStyle(600, 5, Upright),
  108. new SKFontStyle(700, 5, Upright),
  109. new SKFontStyle(800, 5, Upright),
  110. new SKFontStyle(500, 5, Upright)
  111. };
  112. ExpectComparisonOrder(new SKFontStyle(600, 5, Upright), styles);
  113. }
  114. [Test]
  115. public void FontStyleSet_RespectsPriority()
  116. {
  117. var styles = new[]
  118. {
  119. new SKFontStyle(600, 5, Italic),
  120. new SKFontStyle(600, 6, Upright),
  121. new SKFontStyle(500, 6, Italic)
  122. };
  123. ExpectComparisonOrder(new SKFontStyle(500, 5, Upright), styles);
  124. }
  125. }
  126. }