2
0

TextExample.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using QuestPDF.Elements;
  5. using QuestPDF.Examples.Engine;
  6. using QuestPDF.Fluent;
  7. using QuestPDF.Helpers;
  8. using QuestPDF.Infrastructure;
  9. using SkiaSharp;
  10. namespace QuestPDF.Examples
  11. {
  12. public class TextExample : ExampleTestBase
  13. {
  14. [ShowResult]
  15. [ImageSize(1400, 600)]
  16. public void OldText(IContainer container)
  17. {
  18. var fonts = new[]
  19. {
  20. Fonts.Arial,
  21. Fonts.Calibri,
  22. Fonts.Cambria,
  23. Fonts.Candara,
  24. Fonts.ComicSans,
  25. Fonts.Consolas,
  26. Fonts.Corbel,
  27. Fonts.Courier,
  28. Fonts.CourierNew,
  29. Fonts.Georgia,
  30. Fonts.Impact,
  31. Fonts.LucidaConsole,
  32. Fonts.SegoeSD,
  33. Fonts.SegoeUI,
  34. Fonts.Tahoma,
  35. Fonts.TimesNewRoman,
  36. Fonts.TimesRoman,
  37. Fonts.Trebuchet,
  38. Fonts.Verdana,
  39. };
  40. container
  41. .Padding(50)
  42. .Grid(stack =>
  43. {
  44. stack.Spacing(10);
  45. stack.Columns(2);
  46. foreach (var font in fonts)
  47. {
  48. stack
  49. .Element()
  50. .Box()
  51. .Background(Placeholders.BackgroundColor())
  52. .Text($"Lorem ipsum dolor sit amet {font}", TextStyle.Default.Size(24).FontType(font));
  53. }
  54. });
  55. }
  56. //[ShowResult]
  57. [ImageSize(1400, 800)]
  58. public void Test(IContainer container)
  59. {
  60. List<TextElement> Lorem()
  61. {
  62. return new List<TextElement>
  63. {
  64. new TextElement()
  65. {
  66. Style = TextStyle.Default.Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  67. Text = "Podstawowy łaciński Tabela znaków Unicode"
  68. },
  69. new TextElement()
  70. {
  71. Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  72. Text = "✔"
  73. },
  74. new TextElement()
  75. {
  76. Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  77. Text = "🥛"
  78. },
  79. new TextElement()
  80. {
  81. Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  82. Text = "🧀"
  83. },
  84. new TextElement()
  85. {
  86. Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  87. Text = "❤🚵‍♀️"
  88. },
  89. new TextElement()
  90. {
  91. Style = TextStyle.Default.Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  92. Text = "Lorem ipsum "
  93. },
  94. new TextElement()
  95. {
  96. Style = TextStyle.Default.Size(24).BackgroundColor(Placeholders.BackgroundColor()),
  97. Text = " dolor "
  98. },
  99. new TextElement()
  100. {
  101. Style = TextStyle.Default.Size(64).BackgroundColor(Placeholders.BackgroundColor()),
  102. Text = " sijt "
  103. },
  104. new TextElement()
  105. {
  106. Style = TextStyle.Default.Size(32).BackgroundColor(Placeholders.BackgroundColor()),
  107. Text = " amet"
  108. }
  109. };
  110. }
  111. Func<List<TextElement>> Source = () => Split(RandomText());
  112. container
  113. .Padding(50)
  114. .Box().Border(1).Stack(stack =>
  115. {
  116. stack
  117. .Element()
  118. .Box()
  119. //.Background(Placeholders.BackgroundColor())
  120. .Element(new TextRun()
  121. {
  122. Elements = Lorem()
  123. });
  124. stack
  125. .Element()
  126. .Box()
  127. //.Background(Placeholders.BackgroundColor())
  128. .Element(new TextRun()
  129. {
  130. Elements = Source()
  131. });
  132. stack
  133. .Element()
  134. .Box()
  135. //.Background(Placeholders.BackgroundColor())
  136. .Element(new TextRun()
  137. {
  138. Elements = Source()
  139. });
  140. stack
  141. .Element()
  142. .Box()
  143. //.Background(Placeholders.BackgroundColor())
  144. .Element(new TextRun()
  145. {
  146. Elements = Source()
  147. });
  148. stack
  149. .Element()
  150. .Box()
  151. //.Background(Placeholders.BackgroundColor())
  152. .Element(new TextRun()
  153. {
  154. Elements = Source()
  155. });
  156. stack
  157. .Element()
  158. .Box()
  159. //.Background(Placeholders.BackgroundColor())
  160. .Element(new TextRun()
  161. {
  162. Elements = Source()
  163. });
  164. });
  165. }
  166. List<TextElement> RandomText()
  167. {
  168. var sizes = new[] { 24, 32, 48, 64};
  169. return Placeholders
  170. .Sentence()
  171. .Split(" ")
  172. .Select(x => new TextElement
  173. {
  174. Text = $"{x} ",
  175. Style = TextStyle
  176. .Default
  177. //.Size(sizes[Placeholders.Random.Next(0, 3)])
  178. .Size(24)
  179. .BackgroundColor(Placeholders.BackgroundColor())
  180. //.LineHeight((float)Placeholders.Random.NextDouble() / 2 + 1f)
  181. .LineHeight(1.2f)
  182. })
  183. .ToList();
  184. }
  185. List<TextElement> Split(List<TextElement> elements)
  186. {
  187. return elements
  188. .SelectMany(x => x
  189. .Text
  190. .Select(y => new TextElement
  191. {
  192. Style = x.Style,
  193. Text = y.ToString()
  194. }))
  195. .ToList();
  196. }
  197. }
  198. }