ContentOverflowVisualizationExamples.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System.Linq;
  2. using NUnit.Framework;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. namespace QuestPDF.Examples;
  8. public class ContentOverflowVisualizationExamples
  9. {
  10. [Test]
  11. public void DrawOverflow()
  12. {
  13. RenderingTest
  14. .Create()
  15. .ShowResults()
  16. .ProducePdf()
  17. .EnableDebugging()
  18. .RenderDocument(document =>
  19. {
  20. document.Page(page =>
  21. {
  22. page.Size(PageSizes.A4);
  23. page.Margin(24);
  24. page.DefaultTextStyle(TextStyle.Default.FontSize(16));
  25. page.Header().Text("Document header").FontSize(24).Bold().FontColor(Colors.Blue.Accent2);
  26. page.Content().PaddingVertical(24).Column(column =>
  27. {
  28. column.Spacing(16);
  29. foreach (var size in Enumerable.Range(20, 20))
  30. column.Item().Width(size * 10).Height(40).Background(Colors.Grey.Lighten3);
  31. column.Item().Row(row =>
  32. {
  33. row.RelativeItem().Border(1).Background(Colors.Grey.Lighten3).Padding(5).Text("Will it work?").FontSize(20);
  34. row.RelativeItem().Border(1).Background(Colors.Grey.Lighten3).Padding(5).Height(100).ShowEntire().Text(Placeholders.LoremIpsum()).FontSize(20);
  35. });
  36. });
  37. page.Footer().AlignCenter().Text(text =>
  38. {
  39. text.CurrentPageNumber();
  40. text.Span(" / ");
  41. text.TotalPages();
  42. });
  43. });
  44. });
  45. }
  46. [Test]
  47. public void DrawOverflowRealExample()
  48. {
  49. var image = Placeholders.Image(400, 300);
  50. RenderingTest
  51. .Create()
  52. .ShowResults()
  53. .PageSize(PageSizes.A4)
  54. .ProducePdf()
  55. .EnableDebugging()
  56. .Render(container =>
  57. {
  58. container.Column(column =>
  59. {
  60. foreach (var i in Enumerable.Range(0, 50))
  61. column.Item().Height(30).Width(i * 5 + 100).Background(Placeholders.BackgroundColor());
  62. column.Item()
  63. .Padding(24)
  64. // constrain area to square 200 x 200
  65. .Width(200)
  66. .Height(200)
  67. .Background(Colors.Grey.Lighten3)
  68. // draw image that fits height (and therefore will overflow)
  69. //.ContentOverflowDebugArea()
  70. .Image(image)
  71. .FitHeight();
  72. foreach (var i in Enumerable.Range(0, 50))
  73. column.Item().Height(30).Width(i * 5 + 100).Background(Placeholders.BackgroundColor());
  74. });
  75. });
  76. }
  77. [Test]
  78. public void DrawOverflowSimpleExample()
  79. {
  80. var image = Placeholders.Image(400, 300);
  81. RenderingTest
  82. .Create()
  83. .ShowResults()
  84. .PageSize(PageSizes.A4)
  85. .EnableDebugging()
  86. .ProducePdf()
  87. .Render(container =>
  88. {
  89. container
  90. .Padding(24)
  91. // constrain area to square 200 x 200
  92. .Width(200)
  93. .Height(200)
  94. .Background(Colors.Grey.Lighten3)
  95. // draw image that fits height (and therefore will overflow)
  96. //.ContentOverflowDebugArea()
  97. .Image(image)
  98. .FitHeight();
  99. });
  100. }
  101. [Test]
  102. public void DrawOverflowCases()
  103. {
  104. RenderingTest
  105. .Create()
  106. .ShowResults()
  107. .PageSize(PageSizes.A4)
  108. .EnableDebugging()
  109. .ProducePdf()
  110. .Render(container =>
  111. {
  112. container.Padding(24).Row(row =>
  113. {
  114. row.Spacing(50);
  115. row.RelativeItem().ContentFromLeftToRight().Element(GenerateOverflowPatterns);
  116. row.RelativeItem().ContentFromRightToLeft().Element(GenerateOverflowPatterns);
  117. });
  118. void GenerateOverflowPatterns(IContainer container)
  119. {
  120. container.Column(column =>
  121. {
  122. column.Spacing(50);
  123. column
  124. .Item()
  125. .Element(DrawTestcaseArea)
  126. .Width(50)
  127. .Height(150)
  128. .Text("Test");
  129. column
  130. .Item()
  131. .Element(DrawTestcaseArea)
  132. .Width(150)
  133. .Height(50)
  134. .Text("Test");
  135. column
  136. .Item()
  137. .Element(DrawTestcaseArea)
  138. .Width(200)
  139. .Height(150)
  140. .Text("Test");
  141. IContainer DrawTestcaseArea(IContainer container)
  142. {
  143. return container
  144. .Height(200)
  145. .Background(Colors.Grey.Lighten4)
  146. .Width(100)
  147. .Height(100)
  148. .Background(Colors.Grey.Lighten1);
  149. }
  150. });
  151. }
  152. });
  153. }
  154. }