TextExamples.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using NUnit.Framework;
  5. using QuestPDF.Elements.Text;
  6. using QuestPDF.Examples.Engine;
  7. using QuestPDF.Fluent;
  8. using QuestPDF.Helpers;
  9. using QuestPDF.Infrastructure;
  10. namespace QuestPDF.Examples
  11. {
  12. public class TextExamples
  13. {
  14. [Test]
  15. public void SimpleText()
  16. {
  17. RenderingTest
  18. .Create()
  19. .PageSize(500, 100)
  20. .ProduceImages()
  21. .ShowResults()
  22. .Render(container =>
  23. {
  24. container
  25. .Padding(5)
  26. .MinimalBox()
  27. .Border(1)
  28. .Padding(10)
  29. .Text(Placeholders.Paragraph());
  30. });
  31. }
  32. [Test]
  33. public void SimpleTextBlock()
  34. {
  35. RenderingTest
  36. .Create()
  37. .PageSize(600, 300)
  38. .ProduceImages()
  39. .ShowResults()
  40. .Render(container =>
  41. {
  42. container
  43. .Padding(5)
  44. .MinimalBox()
  45. .Border(1)
  46. .MaxWidth(300)
  47. .Padding(10)
  48. .Text(text =>
  49. {
  50. text.DefaultTextStyle(TextStyle.Default.FontSize(20));
  51. text.Span("This is a normal text, followed by an ");
  52. text.Span("underlined red text").FontColor(Colors.Red.Medium).Underline();
  53. text.Span(".");
  54. });
  55. });
  56. }
  57. [Test]
  58. public void TextWeight()
  59. {
  60. RenderingTest
  61. .Create()
  62. .PageSize(500, 500)
  63. .ProduceImages()
  64. .ShowResults()
  65. .Render(container =>
  66. {
  67. container
  68. .Padding(20)
  69. .MinimalBox()
  70. .Border(1)
  71. .Padding(20)
  72. .Text(text =>
  73. {
  74. text.DefaultTextStyle(x => x.FontFamily(Fonts.Calibri).FontSize(20));
  75. text.Line("Thin").Thin();
  76. text.Line("ExtraLight").ExtraLight();
  77. text.Line("Light").Light();
  78. text.Line("NormalWeight").NormalWeight();
  79. text.Line("Medium").Medium();
  80. text.Line("SemiBold").SemiBold();
  81. text.Line("Bold").Bold();
  82. text.Line("ExtraBold").ExtraBold();
  83. text.Line("Black").Black();
  84. text.Line("ExtraBlack").ExtraBlack();
  85. });
  86. });
  87. }
  88. [Test]
  89. public void LineHeight()
  90. {
  91. RenderingTest
  92. .Create()
  93. .PageSize(500, 700)
  94. .ProduceImages()
  95. .ShowResults()
  96. .Render(container =>
  97. {
  98. container
  99. .Padding(20)
  100. .Column(column =>
  101. {
  102. var lineHeights = new[] { 0.8f, 1f, 1.5f };
  103. var paragraph = Placeholders.Paragraph();
  104. foreach (var lineHeight in lineHeights)
  105. {
  106. column
  107. .Item()
  108. .Border(1)
  109. .Padding(10)
  110. .Text(paragraph)
  111. .FontSize(16)
  112. .LineHeight(lineHeight);
  113. }
  114. });
  115. });
  116. }
  117. [Test]
  118. public void LetterSpacing()
  119. {
  120. RenderingTest
  121. .Create()
  122. .PageSize(500, 700)
  123. .ProduceImages()
  124. .ShowResults()
  125. .Render(container =>
  126. {
  127. container
  128. .Padding(20)
  129. .Column(column =>
  130. {
  131. var letterSpacing = new[] { -0.1f, 0f, 0.2f };
  132. var paragraph = Placeholders.Sentence().ToUpper();
  133. foreach (var spacing in letterSpacing)
  134. {
  135. column
  136. .Item()
  137. .Border(1)
  138. .Padding(10)
  139. .Column(nestedColumn =>
  140. {
  141. nestedColumn.Item()
  142. .Text(paragraph)
  143. .FontSize(16)
  144. .LetterSpacing(spacing);
  145. nestedColumn.Item()
  146. .Text($"Letter spacing of {spacing} em")
  147. .FontSize(10)
  148. .Italic()
  149. .FontColor(Colors.Blue.Medium);
  150. });
  151. }
  152. });
  153. });
  154. }
  155. [Test]
  156. public void LetterSpacing_Arabic()
  157. {
  158. RenderingTest
  159. .Create()
  160. .PageSize(500, 700)
  161. .ProduceImages()
  162. .ShowResults()
  163. .Render(container =>
  164. {
  165. container
  166. .Padding(50)
  167. .Column(column =>
  168. {
  169. var letterSpacing = new[] { -0.1f, 0f, 0.2f };
  170. var paragraph = "ينا الألم. في بعض الأحيان ونظراً للالتزامات التي يفرضها علينا";
  171. foreach (var spacing in letterSpacing)
  172. {
  173. column
  174. .Item()
  175. .Border(1)
  176. .Padding(10)
  177. .Column(nestedColumn =>
  178. {
  179. nestedColumn.Item()
  180. .Text(paragraph)
  181. .FontSize(16)
  182. .FontFamily(Fonts.Calibri)
  183. .LetterSpacing(spacing);
  184. nestedColumn.Item()
  185. .Text($"Letter spacing of {spacing} em")
  186. .FontSize(10)
  187. .Italic()
  188. .FontColor(Colors.Blue.Medium);
  189. });
  190. }
  191. });
  192. });
  193. }
  194. [Test]
  195. public void LetterSpacing_Unicode()
  196. {
  197. RenderingTest
  198. .Create()
  199. .PageSize(500, 700)
  200. .ProduceImages()
  201. .ShowResults()
  202. .Render(container =>
  203. {
  204. container
  205. .Padding(50)
  206. .Column(column =>
  207. {
  208. var letterSpacing = new[] { 0f, 0.5f };
  209. var paragraph = "Ţ̴̡̧̤̮̺̤̗͎̱̹͙͎͖͂̿̓́̉̊̀̍͜h̵̞̘͇̾̎̏̅į̵̹̖͔͉̰̎̉̄̐̏͑͂̅̃̃͘͝s̷͓͉̭̭̯̬̥̻̰̩̦̑̀̀͌́̒̍̒̌̇͛̀͛́̎ ̷̡̡̟͕̳̺̝̼͇͔̬̟̖͍̈́̽͜͝͝i̶͔͚̟̊̐͛́͛̄̌ṡ̸̡̤̪͙͍̥͙̟̼̝̰̥͈̿̓̄̿̓͠ ̶̢̦̙͍̯̖̱̰̯͕͔͎̯̝̎͑t̸͖̲̱̼̎͐̎̉̾̎̾̌̅̔̏͘ȩ̶̝̫̙͓̙̣̔̀̌̔̋̂̑̈́̏̀̈͘̕͜͝s̸̫̝̮̻̼͐̅̄̎̎̑͝ț̷̨̢̨̻͈̮̞̆͗̓͊̃̌͂̑̉̕̕͜͝͝";
  210. foreach (var spacing in letterSpacing)
  211. {
  212. column.Item()
  213. .Text($"Letter spacing of {spacing} em")
  214. .FontSize(10)
  215. .Italic()
  216. .FontColor(Colors.Blue.Medium);
  217. column.Item()
  218. .PaddingVertical(50)
  219. .Text(paragraph)
  220. .FontSize(16)
  221. .FontFamily(Fonts.Calibri)
  222. .LetterSpacing(spacing);
  223. }
  224. });
  225. });
  226. }
  227. [Test]
  228. public void SuperscriptSubscript_Simple()
  229. {
  230. RenderingTest
  231. .Create()
  232. .PageSize(500, 500)
  233. .ProduceImages()
  234. .ShowResults()
  235. .Render(container =>
  236. {
  237. container
  238. .Padding(20)
  239. .MinimalBox()
  240. .Border(1)
  241. .Padding(20)
  242. .Text(text =>
  243. {
  244. text.DefaultTextStyle(x => x.FontSize(20));
  245. text.ParagraphSpacing(10);
  246. var highlight = TextStyle.Default.BackgroundColor(Colors.Green.Lighten3);
  247. text.Span("E=mc").Style(highlight);
  248. text.Span("2").Superscript().Style(highlight);
  249. text.Span(" is the equation of mass–energy equivalence.");
  250. text.EmptyLine();
  251. text.Span("H").Style(highlight);
  252. text.Span("2").Subscript().Style(highlight);
  253. text.Span("O").Style(highlight);
  254. text.Span(" is the chemical formula for water.");
  255. });
  256. });
  257. }
  258. [Test]
  259. public void SuperscriptSubscript_Effects()
  260. {
  261. RenderingTest
  262. .Create()
  263. .PageSize(800, 400)
  264. .ProduceImages()
  265. .ShowResults()
  266. .Render(container =>
  267. {
  268. container
  269. .Padding(25)
  270. .DefaultTextStyle(x => x.FontSize(30))
  271. .Column(column =>
  272. {
  273. column.Spacing(25);
  274. column.Item().Text(text =>
  275. {
  276. text.DefaultTextStyle(x => x.Underline());
  277. text.Span("Underline of the superscript (E = mc");
  278. text.Span("2").Superscript();
  279. text.Span(") should be at the same height as for normal text.");
  280. });
  281. column.Item().Text(text =>
  282. {
  283. text.DefaultTextStyle(x => x.Underline());
  284. text.Span("Underline of the subscript(H");
  285. text.Span("2").Subscript();
  286. text.Span("O) should be slightly lower than a normal text.");
  287. });
  288. column.Item().Text(text =>
  289. {
  290. text.DefaultTextStyle(x => x.Strikethrough());
  291. text.Span("Strikethrough of both superscript (E=mc");
  292. text.Span("2").Superscript();
  293. text.Span(") and subscript(H");
  294. text.Span("2").Subscript();
  295. text.Span("O) should be visible in the middle of the text.");
  296. });
  297. });
  298. });
  299. }
  300. [Test]
  301. public void ParagraphSpacing()
  302. {
  303. RenderingTest
  304. .Create()
  305. .PageSize(500, 500)
  306. .ProduceImages()
  307. .ShowResults()
  308. .Render(container =>
  309. {
  310. container
  311. .Padding(5)
  312. .MinimalBox()
  313. .Border(1)
  314. .Padding(10)
  315. .Text(text =>
  316. {
  317. text.Line(Placeholders.Paragraph());
  318. });
  319. });
  320. }
  321. [Test]
  322. public void CustomElement()
  323. {
  324. RenderingTest
  325. .Create()
  326. .PageSize(500, 200)
  327. .ProduceImages()
  328. .ShowResults()
  329. .Render(container =>
  330. {
  331. container
  332. .Padding(5)
  333. .MinimalBox()
  334. .Border(1)
  335. .Padding(10)
  336. .Text(text =>
  337. {
  338. text.DefaultTextStyle(TextStyle.Default.FontSize(20));
  339. text.Span("This is a random image aligned to the baseline: ");
  340. text.Element()
  341. .PaddingBottom(-6)
  342. .Height(24)
  343. .Width(48)
  344. .Image(Placeholders.Image);
  345. text.Span(".");
  346. });
  347. });
  348. }
  349. [Test]
  350. public void TextElements()
  351. {
  352. RenderingTest
  353. .Create()
  354. .PageSize(PageSizes.A4)
  355. .ProducePdf()
  356. .ShowResults()
  357. .Render(container =>
  358. {
  359. container
  360. .Padding(20)
  361. .Padding(10)
  362. .MinimalBox()
  363. .Border(1)
  364. .Padding(5)
  365. .Padding(10)
  366. .Text(text =>
  367. {
  368. text.DefaultTextStyle(TextStyle.Default);
  369. text.AlignLeft();
  370. text.ParagraphSpacing(10);
  371. text.Line(Placeholders.LoremIpsum());
  372. text.Span($"This is target text that should show up. {DateTime.UtcNow:T} > This is a short sentence that will be wrapped into second line hopefully, right? <").Underline();
  373. });
  374. });
  375. }
  376. [Test]
  377. public void Textcolumn()
  378. {
  379. RenderingTest
  380. .Create()
  381. .PageSize(PageSizes.A4)
  382. .ProducePdf()
  383. .ShowResults()
  384. .Render(container =>
  385. {
  386. container
  387. .Padding(20)
  388. .Padding(10)
  389. .MinimalBox()
  390. .Border(1)
  391. .Padding(5)
  392. .Padding(10)
  393. .Text(text =>
  394. {
  395. text.DefaultTextStyle(TextStyle.Default);
  396. text.AlignLeft();
  397. text.ParagraphSpacing(10);
  398. foreach (var i in Enumerable.Range(1, 100))
  399. text.Line($"{i}: {Placeholders.Paragraph()}");
  400. });
  401. });
  402. }
  403. [Test]
  404. public void SpaceIssue()
  405. {
  406. RenderingTest
  407. .Create()
  408. .PageSize(PageSizes.A4)
  409. .ProducePdf()
  410. .ShowResults()
  411. .Render(container =>
  412. {
  413. container
  414. .Padding(20)
  415. .Padding(10)
  416. .MinimalBox()
  417. .Border(1)
  418. .Padding(5)
  419. .Padding(10)
  420. .Text(text =>
  421. {
  422. text.DefaultTextStyle(x => x.Bold());
  423. text.DefaultTextStyle(TextStyle.Default);
  424. text.AlignLeft();
  425. text.ParagraphSpacing(10);
  426. text.Span(Placeholders.LoremIpsum());
  427. text.EmptyLine();
  428. text.Span("This text is a normal text, ");
  429. text.Span("this is a bold text, ").Bold();
  430. text.Span("this is a red and underlined text, ").FontColor(Colors.Red.Medium).Underline();
  431. text.Span("and this is slightly bigger text.").FontSize(16);
  432. text.EmptyLine();
  433. text.Span("The new text element also supports injecting custom content between words: ");
  434. text.Element().PaddingBottom(-4).Height(16).Width(32).Image(Placeholders.Image);
  435. text.Span(".");
  436. text.EmptyLine();
  437. text.Span("This is page number ");
  438. text.CurrentPageNumber();
  439. text.Span(" out of ");
  440. text.TotalPages();
  441. text.EmptyLine();
  442. text.Hyperlink("Please visit QuestPDF website", "https://www.questpdf.com");
  443. text.EmptyLine();
  444. text.Span(Placeholders.Paragraphs());
  445. text.EmptyLine();
  446. text.Span(Placeholders.Paragraphs()).Italic();
  447. text.Line("This is target text that does not show up. " + Placeholders.Paragraph());
  448. });
  449. });
  450. }
  451. [Test]
  452. public void HugeList()
  453. {
  454. RenderingTest
  455. .Create()
  456. .PageSize(PageSizes.A4)
  457. .ProducePdf()
  458. .ShowResults()
  459. .Render(container =>
  460. {
  461. container
  462. .Padding(20)
  463. .Padding(10)
  464. .MinimalBox()
  465. .Border(1)
  466. .Padding(5)
  467. .Padding(10)
  468. .Text(text =>
  469. {
  470. text.DefaultTextStyle(TextStyle.Default.FontSize(20).BackgroundColor(Colors.Red.Lighten4));
  471. text.AlignLeft();
  472. text.ParagraphSpacing(10);
  473. text.Span("This text is a normal text, ");
  474. text.Span("this is a bold text, ").Bold();
  475. text.Span("this is a red and underlined text, ").FontColor(Colors.Red.Medium).Underline();
  476. text.Span("and this is slightly bigger text.").FontSize(16);
  477. text.Span("The new text element also supports injecting custom content between words: ");
  478. text.Element().PaddingBottom(-4).Height(16).Width(32).Image(Placeholders.Image);
  479. text.Span(".");
  480. text.EmptyLine();
  481. foreach (var i in Enumerable.Range(1, 100))
  482. {
  483. text.Line($"{i}: {Placeholders.Paragraph()}");
  484. text.Hyperlink("Please visit QuestPDF website. ", "https://www.questpdf.com");
  485. text.Span("This is page number ");
  486. text.CurrentPageNumber();
  487. text.Span(" out of ");
  488. text.TotalPages();
  489. text.EmptyLine();
  490. }
  491. });
  492. });
  493. }
  494. [Test]
  495. public void MeasureIssueWhenSpaceAtLineEnd()
  496. {
  497. // issue 135
  498. RenderingTest
  499. .Create()
  500. .ProduceImages()
  501. .ShowResults()
  502. .RenderDocument(container =>
  503. {
  504. container.Page(page =>
  505. {
  506. page.Margin(50);
  507. page.PageColor(Colors.White);
  508. page.Size(PageSizes.A4);
  509. page.Content().Text("This is a specially crafted sentence with a specially chosen length for demonstration of the bug that occurs ;;;;;. ").FontSize(11).BackgroundColor(Colors.Red.Lighten3);
  510. });
  511. });
  512. }
  513. [Test]
  514. public void EmptyText()
  515. {
  516. // issue 135
  517. RenderingTest
  518. .Create()
  519. .ProduceImages()
  520. .ShowResults()
  521. .RenderDocument(container =>
  522. {
  523. container.Page(page =>
  524. {
  525. page.Margin(50);
  526. page.PageColor(Colors.White);
  527. page.Size(PageSizes.A4);
  528. page.Content().Text(" ").FontSize(11).BackgroundColor(Colors.Red.Lighten3);
  529. });
  530. });
  531. }
  532. [Test]
  533. public void Whitespaces()
  534. {
  535. // issue 135
  536. RenderingTest
  537. .Create()
  538. .ProduceImages()
  539. .ShowResults()
  540. .RenderDocument(container =>
  541. {
  542. container.Page(page =>
  543. {
  544. page.Margin(50);
  545. page.PageColor(Colors.White);
  546. page.Size(PageSizes.A4);
  547. page.Content().Text(" x ").FontSize(11).BackgroundColor(Colors.Red.Lighten3);
  548. });
  549. });
  550. }
  551. [Test]
  552. public void DrawingNullTextShouldNotThrowException()
  553. {
  554. RenderingTest
  555. .Create()
  556. .ProduceImages()
  557. .ShowResults()
  558. .RenderDocument(container =>
  559. {
  560. container.Page(page =>
  561. {
  562. page.Margin(50);
  563. page.PageColor(Colors.White);
  564. page.Size(PageSizes.A4);
  565. page.Content().Column(column =>
  566. {
  567. column.Item().Text((string) null);
  568. column.Item().Text(text =>
  569. {
  570. text.Span(null);
  571. text.Line(null);
  572. text.Hyperlink(null, "http://www.questpdf.com");
  573. text.TotalPages().Format(x => null);
  574. });
  575. });
  576. });
  577. });
  578. }
  579. [Test]
  580. public void BreakingLongWord()
  581. {
  582. RenderingTest
  583. .Create()
  584. .ProduceImages()
  585. .ShowResults()
  586. .RenderDocument(container =>
  587. {
  588. container.Page(page =>
  589. {
  590. page.Margin(50);
  591. page.PageColor(Colors.White);
  592. page.Size(PageSizes.A4);
  593. page.Content().Column(column =>
  594. {
  595. column.Item().Text((string) null);
  596. column.Item().Text(text =>
  597. {
  598. text.DefaultTextStyle(x => x.BackgroundColor(Colors.Red.Lighten3).FontSize(24));
  599. text.Span(" " + Placeholders.LoremIpsum());
  600. text.Span(" 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ").WrapAnywhere();
  601. });
  602. });
  603. });
  604. });
  605. }
  606. [Test]
  607. public void TextShaping_Unicode()
  608. {
  609. RenderingTest
  610. .Create()
  611. .PageSize(600, 100)
  612. .ProduceImages()
  613. .ShowResults()
  614. .Render(container =>
  615. {
  616. container
  617. .Padding(35)
  618. .MinimalBox()
  619. .Background(Colors.Grey.Lighten2)
  620. .Text(text =>
  621. {
  622. text.DefaultTextStyle(TextStyle.Default.FontSize(20));
  623. text.Span("Complex Unicode structure: ");
  624. text.Span("T̶̖̔͆͆̽̔ḩ̷̼̫̐̈́̀͜͝͝ì̶͇̤͓̱̣͇͓͉̎s̵̡̟̹͍̜͉̗̾͛̈̐́͋͂͝͠ͅ ̴̨͙͍͇̭̒͗̀́͝ì̷̡̺͉̼̏̏̉̌͝s̷͍͙̗̰̖͙̈̑̂̔͑͊̌̓̊̇͜ ̶̛̼͚͊̅͘ṭ̷̨̘̣̙̖͉͌̏̂̅͑̄̽̕͝ȅ̶̲̲̙̭͈̬̣͔̝͔̈́͝s̸̢̯̪̫͓̭̮̓̀͆͜ț̸̢͉̞̥̤̏̌̓͝").FontFamily(Fonts.Calibri).FontColor(Colors.Red.Medium);
  625. text.Span(".");
  626. });
  627. });
  628. }
  629. [Test]
  630. public void TextShaping_Arabic()
  631. {
  632. RenderingTest
  633. .Create()
  634. .PageSize(250, 100)
  635. .ProduceImages()
  636. .ShowResults()
  637. .Render(container =>
  638. {
  639. container
  640. .Padding(25)
  641. .MinimalBox()
  642. .Background(Colors.Grey.Lighten2)
  643. .Text("خوارزمية ترتيب")
  644. .FontFamily(Fonts.Calibri)
  645. .FontSize(30);
  646. });
  647. }
  648. [Test]
  649. public void FontFallback()
  650. {
  651. RenderingTest
  652. .Create()
  653. .ProduceImages()
  654. .ShowResults()
  655. .RenderDocument(container =>
  656. {
  657. container.Page(page =>
  658. {
  659. page.Margin(50);
  660. page.PageColor(Colors.White);
  661. page.DefaultTextStyle(x => x
  662. .Fallback(y => y.FontFamily("Segoe UI Emoji")
  663. .Fallback(y => y.FontFamily("Microsoft YaHei"))));
  664. page.Size(PageSizes.A4);
  665. page.Content().Text(t =>
  666. {
  667. t.Line("This is normal text.");
  668. t.EmptyLine();
  669. t.Line("Following line should use font fallback:");
  670. t.Line("中文文本");
  671. t.EmptyLine();
  672. t.Line("The following line contains a mix of known and unknown characters.");
  673. t.Line("Mixed line: This 中文 is 文文 a mixed 本 本 line 本 中文文本!");
  674. t.EmptyLine();
  675. t.Line("Emojis work out of the box because of font fallback: 😊😅🥳👍❤😍👌");
  676. });
  677. });
  678. });
  679. }
  680. [Test]
  681. public void WordWrappingStability()
  682. {
  683. // instruction: check if any characters repeat when performing the word-wrapping algorithm
  684. RenderingTest
  685. .Create()
  686. .PageSize(PageSizes.A4)
  687. .ProducePdf()
  688. .ShowResults()
  689. .Render(container =>
  690. {
  691. var text = "Lorem ipsum dolor sit amet consectetuer";
  692. container
  693. .Padding(20)
  694. .Column(column =>
  695. {
  696. column.Spacing(10);
  697. foreach (var width in Enumerable.Range(25, 200))
  698. {
  699. column
  700. .Item()
  701. .MaxWidth(width)
  702. .Background(Colors.Grey.Lighten3)
  703. .Text(text);
  704. }
  705. });
  706. });
  707. }
  708. [Test]
  709. public void AdvancedLanguagesSupport()
  710. {
  711. RenderingTest
  712. .Create()
  713. .PageSize(new PageSize(400, 400))
  714. .ProduceImages()
  715. .ShowResults()
  716. .Render(container =>
  717. {
  718. var text = "في المعلوماتية أو الرياضيات، خوارزمية الترتيب هي خوارزمية تمكن من تنظيم مجموعة عناصر حسب ترتيب محدد.";
  719. container
  720. .Padding(20)
  721. .ContentFromRightToLeft()
  722. .Text(text)
  723. .FontFamily(Fonts.Calibri)
  724. .FontSize(22);
  725. });
  726. }
  727. [Test]
  728. public void WordWrappingWhenRightToLeft()
  729. {
  730. RenderingTest
  731. .Create()
  732. .PageSize(new PageSize(1000, 500))
  733. .ProducePdf()
  734. .ShowResults()
  735. .Render(container =>
  736. {
  737. var text = "في المعلوماتية أو الرياضيات، خوارزمية الترتيب هي خوارزمية تمكن من تنظيم مجموعة عناصر حسب ترتيب محدد.";
  738. container
  739. .Padding(25)
  740. .ContentFromRightToLeft()
  741. .Column(column =>
  742. {
  743. column.Spacing(20);
  744. foreach (var size in new[] { 36, 34, 32, 30, 15 })
  745. {
  746. column
  747. .Item()
  748. .ShowEntire()
  749. .MaxWidth(size * 25)
  750. .Background(Colors.Grey.Lighten3)
  751. .MinimalBox()
  752. .Background(Colors.Grey.Lighten2)
  753. .Text(text)
  754. .FontSize(20)
  755. .FontFamily("Segoe UI");
  756. }
  757. });
  758. });
  759. }
  760. [Test]
  761. public void ForcingTextDirection()
  762. {
  763. RenderingTest
  764. .Create()
  765. .PageSize(new PageSize(1000, 500))
  766. .ProduceImages()
  767. .ShowResults()
  768. .Render(container =>
  769. {
  770. container
  771. .Padding(10)
  772. .DefaultTextStyle(x => x.FontSize(24).FontFamily("Calibri"))
  773. .Column(column =>
  774. {
  775. column.Spacing(10);
  776. var word = "الجوريتم";
  777. var definition = "algorithm in Arabic";
  778. var text = $"{word} - {definition}";
  779. // text direction is automatically detected using the first word
  780. column.Item().Text(text);
  781. // it is possible to force specific content direction
  782. column.Item().Text(text).DirectionFromLeftToRight();
  783. column.Item().Text(text).DirectionFromRightToLeft();
  784. // to combine text in various content directions, split it into segments
  785. column.Item().Text(text =>
  786. {
  787. text.Span(word);
  788. text.Span(" - ");
  789. text.Span(definition);
  790. });
  791. });
  792. });
  793. }
  794. }
  795. }