TextStyleTests.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Helpers;
  3. using QuestPDF.Infrastructure;
  4. namespace QuestPDF.VisualTests;
  5. public class TextStyleTests
  6. {
  7. private static readonly IEnumerable<Color> FontColor_Values = [ Colors.Red.Darken3, Colors.Green.Darken3, Colors.Blue.Darken3 ];
  8. [Test, TestCaseSource(nameof(FontColor_Values))]
  9. public void FontsColor(Color fontColor)
  10. {
  11. VisualTest.PerformWithDefaultPageSettings(container =>
  12. {
  13. container
  14. .Text(text =>
  15. {
  16. text.Span("Text can be displayed in different ");
  17. text.Span("font colors").FontColor(fontColor);
  18. text.Span(".");
  19. });
  20. });
  21. }
  22. private static readonly IEnumerable<Color> BackgroundColor_Values = [ Colors.Red.Lighten4, Colors.Green.Lighten4, Colors.Blue.Lighten4 ];
  23. [Test, TestCaseSource(nameof(BackgroundColor_Values))]
  24. public void BackgroundColor(Color backgroundColor)
  25. {
  26. VisualTest.PerformWithDefaultPageSettings(container =>
  27. {
  28. container
  29. .Text(text =>
  30. {
  31. text.Span("Text can be displayed with different ");
  32. text.Span("background colors").BackgroundColor(backgroundColor);
  33. text.Span(".");
  34. });
  35. });
  36. }
  37. [Test]
  38. public void FontSize([Values(12, 16, 24)] float fontSize)
  39. {
  40. VisualTest.PerformWithDefaultPageSettings(container =>
  41. {
  42. container
  43. .Text(text =>
  44. {
  45. text.Span("Text can be displayed in different ");
  46. text.Span($"font sizes ({fontSize}pt)").FontSize(fontSize);
  47. text.Span(".");
  48. });
  49. });
  50. }
  51. [Test]
  52. public void LineHeight([Values(0.75f, 1f, 1.5f)] float lineHeight)
  53. {
  54. VisualTest.PerformWithDefaultPageSettings(container =>
  55. {
  56. container
  57. .Width(400)
  58. .Text(text =>
  59. {
  60. text.Span($"Line height: {lineHeight}\n\n").Bold().FontColor(Colors.Blue.Darken2);
  61. text.Span(Placeholders.LoremIpsum()).LineHeight(lineHeight);
  62. });
  63. });
  64. }
  65. [Test]
  66. public void WordSpacing([Values(-0.1f, 0f, 0.25f, 1f)] float wordSpacing)
  67. {
  68. VisualTest.PerformWithDefaultPageSettings(container =>
  69. {
  70. container
  71. .Width(400)
  72. .Text(text =>
  73. {
  74. text.Span($"Word spacing: {wordSpacing}\n\n").Bold().FontColor(Colors.Blue.Darken2);
  75. text.Span(Placeholders.LoremIpsum()).WordSpacing(wordSpacing);
  76. });
  77. });
  78. }
  79. [Test]
  80. public void LetterSpacing([Values(-0.1f, 0f, 0.1f, 0.25f)] float letterSpacing)
  81. {
  82. VisualTest.PerformWithDefaultPageSettings(container =>
  83. {
  84. container
  85. .Width(400)
  86. .Text(text =>
  87. {
  88. text.Span($"Letter spacing: {letterSpacing}\n\n").Bold().FontColor(Colors.Blue.Darken2);
  89. text.Span(Placeholders.LoremIpsum()).LetterSpacing(letterSpacing);
  90. });
  91. });
  92. }
  93. [Test]
  94. public void Italic()
  95. {
  96. VisualTest.PerformWithDefaultPageSettings(container =>
  97. {
  98. container
  99. .Text(text =>
  100. {
  101. text.Span("The ");
  102. text.Span("italic effect").Italic();
  103. text.Span(" slants the letters slightly to the right.");
  104. });
  105. });
  106. }
  107. #region Font Decoration
  108. [Test]
  109. public void FontDecoration_Underline()
  110. {
  111. VisualTest.PerformWithDefaultPageSettings(container =>
  112. {
  113. container
  114. .Text(text =>
  115. {
  116. text.Span("Text can be decorated with ");
  117. text.Span("an underline").Underline().DecorationThickness(2).DecorationColor(Colors.Red.Medium);
  118. text.Span(".");
  119. });
  120. });
  121. }
  122. [Test]
  123. public void FontDecoration_Strikethrough()
  124. {
  125. VisualTest.PerformWithDefaultPageSettings(container =>
  126. {
  127. container
  128. .Text(text =>
  129. {
  130. text.Span("Text can be decorated with ");
  131. text.Span("a strikeout").Strikethrough().DecorationThickness(2).DecorationColor(Colors.Red.Medium);
  132. text.Span(".");
  133. });
  134. });
  135. }
  136. [Test]
  137. public void FontDecoration_Overline()
  138. {
  139. VisualTest.PerformWithDefaultPageSettings(container =>
  140. {
  141. container
  142. .Text(text =>
  143. {
  144. text.Span("Text can be decorated with ");
  145. text.Span("an overline").Overline().DecorationThickness(2).DecorationColor(Colors.Red.Medium);
  146. text.Span(".");
  147. });
  148. });
  149. }
  150. [Test]
  151. public void FontDecoration_Combined()
  152. {
  153. VisualTest.PerformWithDefaultPageSettings(container =>
  154. {
  155. container
  156. .Text(text =>
  157. {
  158. text.Span("Text may have ");
  159. text.Span("multiple decoration")
  160. .Underline()
  161. .Strikethrough()
  162. .Overline()
  163. .DecorationThickness(2)
  164. .DecorationColor(Colors.Blue.Medium);
  165. text.Span(" applied to it.");
  166. });
  167. });
  168. }
  169. private static readonly IEnumerable<Color> FontDecoration_Color_Values = [ Colors.Red.Medium, Colors.Green.Medium, Colors.Blue.Medium ];
  170. [Test, TestCaseSource(nameof(FontDecoration_Color_Values))]
  171. public void FontDecoration_Color(Color decorationColor)
  172. {
  173. VisualTest.PerformWithDefaultPageSettings(container =>
  174. {
  175. container
  176. .Text(text =>
  177. {
  178. text.Span("The color of ");
  179. text.Span("the text decoration").Underline().DecorationDashed().DecorationThickness(2).DecorationColor(decorationColor);
  180. text.Span(" can be changed.");
  181. });
  182. });
  183. }
  184. [Test]
  185. public void FontDecoration_Thickness([Values(1f, 2f, 3f)] float thickness)
  186. {
  187. VisualTest.PerformWithDefaultPageSettings(container =>
  188. {
  189. container
  190. .Text(text =>
  191. {
  192. text.Span("The thickness of ");
  193. text.Span("the text decoration").Underline().DecorationWavy().DecorationThickness(thickness).DecorationColor(Colors.Red.Medium);
  194. text.Span(" can be changed.");
  195. });
  196. });
  197. }
  198. [Test]
  199. public void FontDecoration_Solid()
  200. {
  201. VisualTest.PerformWithDefaultPageSettings(container =>
  202. {
  203. container
  204. .Text(text =>
  205. {
  206. text.Span("This example shows ");
  207. text.Span("a solid-line text decoration").Underline().DecorationSolid();
  208. text.Span(".");
  209. });
  210. });
  211. }
  212. [Test]
  213. public void FontDecoration_Double()
  214. {
  215. VisualTest.PerformWithDefaultPageSettings(container =>
  216. {
  217. container
  218. .Text(text =>
  219. {
  220. text.Span("This example shows ");
  221. text.Span("a double-line text decoration").Underline().DecorationDouble();
  222. text.Span(".");
  223. });
  224. });
  225. }
  226. [Test]
  227. public void FontDecoration_Wavy()
  228. {
  229. VisualTest.PerformWithDefaultPageSettings(container =>
  230. {
  231. container
  232. .Text(text =>
  233. {
  234. text.Span("This example shows ");
  235. text.Span("a wavy-line text decoration").Underline().DecorationWavy();
  236. text.Span(".");
  237. });
  238. });
  239. }
  240. [Test]
  241. public void FontDecoration_Dotted()
  242. {
  243. VisualTest.PerformWithDefaultPageSettings(container =>
  244. {
  245. container
  246. .Text(text =>
  247. {
  248. text.Span("This example shows ");
  249. text.Span("a dotted text decoration").Underline().DecorationDotted();
  250. text.Span(".");
  251. });
  252. });
  253. }
  254. [Test]
  255. public void FontDecoration_Dashed()
  256. {
  257. VisualTest.PerformWithDefaultPageSettings(container =>
  258. {
  259. container
  260. .Text(text =>
  261. {
  262. text.Span("This example shows ");
  263. text.Span("a dashed text decoration").Underline().DecorationDashed();
  264. text.Span(".");
  265. });
  266. });
  267. }
  268. #endregion
  269. #region Font Weight
  270. [Test]
  271. public void FontWeight_200_ExtraLight()
  272. {
  273. VisualTest.PerformWithDefaultPageSettings(container =>
  274. {
  275. container
  276. .Text(text =>
  277. {
  278. text.Span("This example shows ");
  279. text.Span("an extra-light").ExtraLight().BackgroundColor(Colors.Grey.Lighten3);
  280. text.Span(" font weight.");
  281. });
  282. });
  283. }
  284. [Test]
  285. public void FontWeight_300_Light()
  286. {
  287. VisualTest.PerformWithDefaultPageSettings(container =>
  288. {
  289. container
  290. .Text(text =>
  291. {
  292. text.Span("This example shows ");
  293. text.Span("a light").Light().BackgroundColor(Colors.Grey.Lighten3);
  294. text.Span(" font weight.");
  295. });
  296. });
  297. }
  298. [Test]
  299. public void FontWeight_400_Regular()
  300. {
  301. VisualTest.PerformWithDefaultPageSettings(container =>
  302. {
  303. container
  304. .Text(text =>
  305. {
  306. text.Span("This example shows ");
  307. text.Span("a regular").NormalWeight().BackgroundColor(Colors.Grey.Lighten3);
  308. text.Span(" font weight.");
  309. });
  310. });
  311. }
  312. [Test]
  313. public void FontWeight_500_Medium()
  314. {
  315. VisualTest.PerformWithDefaultPageSettings(container =>
  316. {
  317. container
  318. .Text(text =>
  319. {
  320. text.Span("This example shows ");
  321. text.Span("a medium").Medium().BackgroundColor(Colors.Grey.Lighten3);
  322. text.Span(" font weight.");
  323. });
  324. });
  325. }
  326. [Test]
  327. public void FontWeight_600_SemiBold()
  328. {
  329. VisualTest.PerformWithDefaultPageSettings(container =>
  330. {
  331. container
  332. .Text(text =>
  333. {
  334. text.Span("This example shows ");
  335. text.Span("a semi-bold").SemiBold().BackgroundColor(Colors.Grey.Lighten3);
  336. text.Span(" font weight.");
  337. });
  338. });
  339. }
  340. [Test]
  341. public void FontWeight_700_Bold()
  342. {
  343. VisualTest.PerformWithDefaultPageSettings(container =>
  344. {
  345. container
  346. .Text(text =>
  347. {
  348. text.Span("This example shows ");
  349. text.Span("a bold").Bold().BackgroundColor(Colors.Grey.Lighten3);
  350. text.Span(" font weight.");
  351. });
  352. });
  353. }
  354. [Test]
  355. public void FontWeight_800_ExtraBold()
  356. {
  357. VisualTest.PerformWithDefaultPageSettings(container =>
  358. {
  359. container
  360. .Text(text =>
  361. {
  362. text.Span("This example shows ");
  363. text.Span("an extra-bold").ExtraBold().BackgroundColor(Colors.Grey.Lighten3 );
  364. text.Span(" font weight.");
  365. });
  366. });
  367. }
  368. #endregion
  369. #region Font Position
  370. [Test]
  371. public void FontPosition_Subscript()
  372. {
  373. VisualTest.PerformWithDefaultPageSettings(container =>
  374. {
  375. container
  376. .Text(text =>
  377. {
  378. text.Span("Chemical formula of sulfuric acid: H");
  379. text.Span("2").Subscript();
  380. text.Span("SO");
  381. text.Span("4").Subscript();
  382. text.Span(".");
  383. });
  384. });
  385. }
  386. [Test]
  387. public void FontPosition_Superscript()
  388. {
  389. VisualTest.PerformWithDefaultPageSettings(container =>
  390. {
  391. container
  392. .Text(text =>
  393. {
  394. text.Span("Enstein's equation: E=mc");
  395. text.Span("2").Superscript();
  396. });
  397. });
  398. }
  399. #endregion
  400. #region Font Features
  401. [Test]
  402. public void FontFeatures_StandardLigatures_Enabled()
  403. {
  404. VisualTest.PerformWithDefaultPageSettings(container =>
  405. {
  406. container
  407. .Text("final")
  408. .EnableFontFeature(FontFeatures.StandardLigatures);
  409. });
  410. }
  411. [Test]
  412. public void FontFeatures_StandardLigatures_Disabled()
  413. {
  414. VisualTest.PerformWithDefaultPageSettings(container =>
  415. {
  416. container
  417. .Text("final")
  418. .DisableFontFeature(FontFeatures.StandardLigatures);
  419. });
  420. }
  421. #endregion
  422. }