ScaleTests.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. using QuestPDF.Helpers;
  2. namespace QuestPDF.LayoutTests;
  3. public class ScaleTests
  4. {
  5. private void DrawTestSubject(IContainer container)
  6. {
  7. container
  8. .Inlined(inlined =>
  9. {
  10. inlined.Item().Mock("a").SolidBlock(100, 100);
  11. inlined.Item().Mock("b").SolidBlock(100, 100);
  12. inlined.Item().Mock("c").SolidBlock(100, 100);
  13. inlined.Item().Mock("d").SolidBlock(100, 100);
  14. inlined.Item().Mock("e").SolidBlock(100, 100);
  15. inlined.Item().Mock("f").SolidBlock(100, 100);
  16. });
  17. }
  18. [Test]
  19. public void DefaultScale()
  20. {
  21. LayoutTest
  22. .HavingSpaceOfSize(800, 500)
  23. .ForContent(content =>
  24. {
  25. content.Element(DrawTestSubject);
  26. })
  27. .ExpectDrawResult(document =>
  28. {
  29. document
  30. .Page()
  31. .RequiredAreaSize(600, 100)
  32. .Content(page =>
  33. {
  34. page.Mock("a").Position(0, 0).Size(100, 100);
  35. page.Mock("b").Position(100, 0).Size(100, 100);
  36. page.Mock("c").Position(200, 0).Size(100, 100);
  37. page.Mock("d").Position(300, 0).Size(100, 100);
  38. page.Mock("e").Position(400, 0).Size(100, 100);
  39. page.Mock("f").Position(500, 0).Size(100, 100);
  40. });
  41. });
  42. }
  43. [Test]
  44. public void PositiveScale05()
  45. {
  46. LayoutTest
  47. .HavingSpaceOfSize(800, 500)
  48. .ForContent(content =>
  49. {
  50. content.Scale(0.5f).Element(DrawTestSubject);
  51. })
  52. .ExpectDrawResult(document =>
  53. {
  54. document
  55. .Page()
  56. .RequiredAreaSize(300, 50)
  57. .Content(page =>
  58. {
  59. page.Mock("a").Position(0, 0).Size(100, 100);
  60. page.Mock("b").Position(50, 0).Size(100, 100);
  61. page.Mock("c").Position(100, 0).Size(100, 100);
  62. page.Mock("d").Position(150, 0).Size(100, 100);
  63. page.Mock("e").Position(200, 0).Size(100, 100);
  64. page.Mock("f").Position(250, 0).Size(100, 100);
  65. });
  66. });
  67. }
  68. [Test]
  69. public void PositiveScale15()
  70. {
  71. LayoutTest
  72. .HavingSpaceOfSize(800, 500)
  73. .ForContent(content =>
  74. {
  75. content.Scale(1.5f).Element(DrawTestSubject);
  76. })
  77. .ExpectDrawResult(document =>
  78. {
  79. document
  80. .Page()
  81. .RequiredAreaSize(750, 300)
  82. .Content(page =>
  83. {
  84. page.Mock("a").Position(0, 0).Size(100, 100);
  85. page.Mock("b").Position(150, 0).Size(100, 100);
  86. page.Mock("c").Position(300, 0).Size(100, 100);
  87. page.Mock("d").Position(450, 0).Size(100, 100);
  88. page.Mock("e").Position(600, 0).Size(100, 100);
  89. page.Mock("f").Position(0, 150).Size(100, 100);
  90. });
  91. });
  92. }
  93. [Test]
  94. public void PositiveScale25()
  95. {
  96. LayoutTest
  97. .HavingSpaceOfSize(800, 500)
  98. .ForContent(content =>
  99. {
  100. content.Scale(2.5f).Element(DrawTestSubject);
  101. })
  102. .ExpectDrawResult(document =>
  103. {
  104. document
  105. .Page()
  106. .RequiredAreaSize(750, 500)
  107. .Content(page =>
  108. {
  109. page.Mock("a").Position(0, 0).Size(100, 100);
  110. page.Mock("b").Position(250, 0).Size(100, 100);
  111. page.Mock("c").Position(500, 0).Size(100, 100);
  112. page.Mock("d").Position(0, 250).Size(100, 100);
  113. page.Mock("e").Position(250, 250).Size(100, 100);
  114. page.Mock("f").Position(500, 250).Size(100, 100);
  115. });
  116. });
  117. }
  118. [Test]
  119. public void PositiveScaleTwoPages()
  120. {
  121. LayoutTest
  122. .HavingSpaceOfSize(800, 250)
  123. .ForContent(content =>
  124. {
  125. content.Scale(2).Element(DrawTestSubject);
  126. })
  127. .ExpectDrawResult(document =>
  128. {
  129. document
  130. .Page()
  131. .RequiredAreaSize(800, 200)
  132. .Content(page =>
  133. {
  134. page.Mock("a").Position(0, 0).Size(100, 100);
  135. page.Mock("b").Position(200, 0).Size(100, 100);
  136. page.Mock("c").Position(400, 0).Size(100, 100);
  137. page.Mock("d").Position(600, 0).Size(100, 100);
  138. });
  139. document
  140. .Page()
  141. .RequiredAreaSize(400, 200)
  142. .Content(page =>
  143. {
  144. page.Mock("e").Position(0, 0).Size(100, 100);
  145. page.Mock("f").Position(200, 0).Size(100, 100);
  146. });
  147. });
  148. }
  149. [Test]
  150. public void ScaleVertical()
  151. {
  152. LayoutTest
  153. .HavingSpaceOfSize(450, 800)
  154. .ForContent(content =>
  155. {
  156. content.ScaleVertical(2f).Element(DrawTestSubject);
  157. })
  158. .ExpectDrawResult(document =>
  159. {
  160. document
  161. .Page()
  162. .RequiredAreaSize(400, 400)
  163. .Content(page =>
  164. {
  165. page.Mock("a").Position(0, 0).Size(100, 100);
  166. page.Mock("b").Position(100, 0).Size(100, 100);
  167. page.Mock("c").Position(200, 0).Size(100, 100);
  168. page.Mock("d").Position(300, 0).Size(100, 100);
  169. page.Mock("e").Position(0, 200).Size(100, 100);
  170. page.Mock("f").Position(100, 200).Size(100, 100);
  171. });
  172. });
  173. }
  174. [Test]
  175. public void ScaleVerticalNegative()
  176. {
  177. LayoutTest
  178. .HavingSpaceOfSize(400, 500)
  179. .ForContent(content =>
  180. {
  181. content.ScaleVertical(-1.5f).Element(DrawTestSubject);
  182. })
  183. .ExpectDrawResult(document =>
  184. {
  185. document
  186. .Page()
  187. .RequiredAreaSize(400, 300)
  188. .Content(page =>
  189. {
  190. page.Mock("a").Position(0, 500).Size(100, 100);
  191. page.Mock("b").Position(100, 500).Size(100, 100);
  192. page.Mock("c").Position(200, 500).Size(100, 100);
  193. page.Mock("d").Position(300, 500).Size(100, 100);
  194. page.Mock("e").Position(0, 350).Size(100, 100);
  195. page.Mock("f").Position(100, 350).Size(100, 100);
  196. });
  197. });
  198. }
  199. [Test]
  200. public void ScaleHorizontal()
  201. {
  202. LayoutTest
  203. .HavingSpaceOfSize(450, 800)
  204. .ForContent(content =>
  205. {
  206. content.ScaleHorizontal(2f).Element(DrawTestSubject);
  207. })
  208. .ExpectDrawResult(document =>
  209. {
  210. document
  211. .Page()
  212. .RequiredAreaSize(400, 300)
  213. .Content(page =>
  214. {
  215. page.Mock("a").Position(0, 0).Size(100, 100);
  216. page.Mock("b").Position(200, 0).Size(100, 100);
  217. page.Mock("c").Position(0, 100).Size(100, 100);
  218. page.Mock("d").Position(200, 100).Size(100, 100);
  219. page.Mock("e").Position(0, 200).Size(100, 100);
  220. page.Mock("f").Position(200, 200).Size(100, 100);
  221. });
  222. });
  223. }
  224. [Test]
  225. public void ScaleHorizontalNegative()
  226. {
  227. LayoutTest
  228. .HavingSpaceOfSize(700, 400)
  229. .ForContent(content =>
  230. {
  231. content.ScaleHorizontal(-1.5f).Element(DrawTestSubject);
  232. })
  233. .ExpectDrawResult(document =>
  234. {
  235. document
  236. .Page()
  237. .RequiredAreaSize(600, 200)
  238. .Content(page =>
  239. {
  240. page.Mock("a").Position(700, 0).Size(100, 100);
  241. page.Mock("b").Position(550, 0).Size(100, 100);
  242. page.Mock("c").Position(400, 0).Size(100, 100);
  243. page.Mock("d").Position(250, 0).Size(100, 100);
  244. page.Mock("e").Position(700, 100).Size(100, 100);
  245. page.Mock("f").Position(550, 100).Size(100, 100);
  246. });
  247. });
  248. }
  249. [Test]
  250. public void WrapHorizontal()
  251. {
  252. LayoutTest
  253. .HavingSpaceOfSize(100, 100)
  254. .ForContent(content =>
  255. {
  256. content.Scale(3).Width(50).Height(10);
  257. })
  258. .ExpectLayoutException("The available horizontal space is less than the minimum width.");
  259. }
  260. [Test]
  261. public void WrapVertical()
  262. {
  263. LayoutTest
  264. .HavingSpaceOfSize(100, 100)
  265. .ForContent(content =>
  266. {
  267. content.Scale(3).Width(10).Height(50);
  268. })
  269. .ExpectLayoutException("The available vertical space is less than the minimum height.");
  270. }
  271. }