page_test.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php
  2. /**
  3. * ezcDocumentPdfHyphenatorTests
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Document
  23. * @version //autogen//
  24. * @subpackage Tests
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  26. */
  27. /**
  28. * Test suite for class.
  29. *
  30. * @package Document
  31. * @subpackage Tests
  32. */
  33. class ezcDocumentPdfPageTests extends ezcTestCase
  34. {
  35. public static function suite()
  36. {
  37. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  38. }
  39. public function testEmptyPageFixedBlock()
  40. {
  41. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  42. $this->assertEquals(
  43. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  44. $page->testFitRectangle( 10, 10, 80, 80 )
  45. );
  46. }
  47. public function testOnPageBoundings()
  48. {
  49. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  50. $this->assertEquals(
  51. new ezcDocumentPdfBoundingBox( 0, 0, 100, 100 ),
  52. $page->testFitRectangle( 0, 0, 100, 100 )
  53. );
  54. }
  55. public function testOutOfPageBoundingsX()
  56. {
  57. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  58. $this->assertEquals(
  59. false,
  60. $page->testFitRectangle( -10, 10, 80, 80 )
  61. );
  62. }
  63. public function testOutOfPageBoundingsY()
  64. {
  65. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  66. $this->assertEquals(
  67. false,
  68. $page->testFitRectangle( 10, -10, 80, 80 )
  69. );
  70. }
  71. public function testOutOfPageBoundingsWidth()
  72. {
  73. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  74. $this->assertEquals(
  75. false,
  76. $page->testFitRectangle( 10, 10, 95, 80 )
  77. );
  78. }
  79. public function testOutOfPageBoundingsHeight()
  80. {
  81. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  82. $this->assertEquals(
  83. false,
  84. $page->testFitRectangle( 10, 10, 80, 95 )
  85. );
  86. }
  87. public function testCoveredAreaNoIntersection()
  88. {
  89. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  90. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 20 ) );
  91. $this->assertEquals(
  92. new ezcDocumentPdfBoundingBox( 10, 30, 80, 60 ),
  93. $page->testFitRectangle( 10, 30, 80, 60 )
  94. );
  95. }
  96. public function testCoveredAreaOnLineNoIntersection()
  97. {
  98. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  99. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 20 ) );
  100. $this->assertEquals(
  101. new ezcDocumentPdfBoundingBox( 10, 20, 80, 70 ),
  102. $page->testFitRectangle( 10, 20, 80, 70 )
  103. );
  104. }
  105. public function testCoveredAreaIntersectionXIn()
  106. {
  107. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  108. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  109. $this->assertEquals(
  110. false,
  111. $page->testFitRectangle( 10, 10, 80, 80 )
  112. );
  113. }
  114. public function testCoveredAreaIntersectionXInSecond()
  115. {
  116. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  117. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 1, 1 ) );
  118. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  119. $this->assertEquals(
  120. false,
  121. $page->testFitRectangle( 10, 10, 80, 80 )
  122. );
  123. }
  124. public function testCoveredAreaIntersectionYIn()
  125. {
  126. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  127. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 20 ) );
  128. $this->assertEquals(
  129. false,
  130. $page->testFitRectangle( 10, 10, 80, 80 )
  131. );
  132. }
  133. public function testCoveredAreaIntersectionWidthIn()
  134. {
  135. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  136. $page->setCovered( new ezcDocumentPdfBoundingBox( 80, 0, 20, 100 ) );
  137. $this->assertEquals(
  138. false,
  139. $page->testFitRectangle( 10, 10, 80, 80 )
  140. );
  141. }
  142. public function testCoveredAreaIntersectionHeightIn()
  143. {
  144. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  145. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 80, 100, 20 ) );
  146. $this->assertEquals(
  147. false,
  148. $page->testFitRectangle( 10, 10, 80, 80 )
  149. );
  150. }
  151. public function testCoveredAreaIntersectionInnerBox()
  152. {
  153. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  154. $page->setCovered( new ezcDocumentPdfBoundingBox( 20, 20, 60, 60 ) );
  155. $this->assertEquals(
  156. false,
  157. $page->testFitRectangle( 10, 10, 80, 80 )
  158. );
  159. }
  160. public function testCoveredAreaExcatMatch()
  161. {
  162. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  163. $page->setCovered( new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ) );
  164. $this->assertEquals(
  165. false,
  166. $page->testFitRectangle( 10, 10, 80, 80 )
  167. );
  168. }
  169. public function testCoveredAreaHorizontalMovingImpossible()
  170. {
  171. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  172. $page->setCovered( new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ) );
  173. $this->assertEquals(
  174. false,
  175. $page->testFitRectangle( null, 10, 20, 80 )
  176. );
  177. }
  178. public function testCoveredAreaHorizontalMoving()
  179. {
  180. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  181. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  182. $this->assertEquals(
  183. new ezcDocumentPdfBoundingBox( 20, 10, 10, 80 ),
  184. $page->testFitRectangle( null, 10, 10, 80 )
  185. );
  186. }
  187. public function testCoveredAreaHorizontalMovingOutOfPage()
  188. {
  189. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  190. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  191. $this->assertEquals(
  192. false,
  193. $page->testFitRectangle( null, 10, 90, 80 )
  194. );
  195. }
  196. public function testCoveredAreaHorizontalMovingOutIntoBox()
  197. {
  198. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  199. $page->setCovered( new ezcDocumentPdfBoundingBox( 80, 0, 20, 100 ) );
  200. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  201. $this->assertEquals(
  202. false,
  203. $page->testFitRectangle( null, 10, 70, 80 )
  204. );
  205. }
  206. public function testCoveredAreaVerticalMoving()
  207. {
  208. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  209. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 20 ) );
  210. $this->assertEquals(
  211. new ezcDocumentPdfBoundingBox( 10, 20, 80, 10 ),
  212. $page->testFitRectangle( 10, null, 80, 10 )
  213. );
  214. }
  215. public function testCoveredAreaVerticalMovingOutOfPage()
  216. {
  217. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  218. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 20 ) );
  219. $this->assertEquals(
  220. false,
  221. $page->testFitRectangle( 10, null, 80, 90 )
  222. );
  223. }
  224. public function testCoveredAreaVerticalMovingOutIntoBox()
  225. {
  226. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  227. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 80, 100, 20 ) );
  228. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 20 ) );
  229. $this->assertEquals(
  230. false,
  231. $page->testFitRectangle( 10, null, 80, 70 )
  232. );
  233. }
  234. public function testCoveredAreaBidirectionalMove1()
  235. {
  236. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  237. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 10, 10 ) );
  238. $this->assertEquals(
  239. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  240. $page->testFitRectangle( null, null, 80, 80 )
  241. );
  242. }
  243. public function testCoveredAreaBidirectionalMove2()
  244. {
  245. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  246. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 10 ) );
  247. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 10, 100 ) );
  248. $this->assertEquals(
  249. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  250. $page->testFitRectangle( null, null, 80, 80 )
  251. );
  252. }
  253. public function testHorizontalFullPageExtension()
  254. {
  255. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  256. $this->assertEquals(
  257. new ezcDocumentPdfBoundingBox( 0, 0, 100, 100 ),
  258. $page->testFitRectangle( 0, 0, null, 100 )
  259. );
  260. }
  261. public function testCoveredBoxHorizontalExtension1()
  262. {
  263. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  264. $page->setCovered( new ezcDocumentPdfBoundingBox( 90, 0, 10, 100 ) );
  265. $this->assertEquals(
  266. new ezcDocumentPdfBoundingBox( 0, 0, 90, 100 ),
  267. $page->testFitRectangle( 0, 0, null, 100 )
  268. );
  269. }
  270. public function testCoveredBoxHorizontalExtension2()
  271. {
  272. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  273. $page->setCovered( new ezcDocumentPdfBoundingBox( 50, 0, 10, 100 ) );
  274. $this->assertEquals(
  275. new ezcDocumentPdfBoundingBox( 0, 0, 50, 100 ),
  276. $page->testFitRectangle( 0, 0, null, 100 )
  277. );
  278. }
  279. public function testCoveredBoxHorizontalExtension3()
  280. {
  281. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  282. $page->setCovered( new ezcDocumentPdfBoundingBox( 90, 0, 10, 100 ) );
  283. $this->assertEquals(
  284. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  285. $page->testFitRectangle( 10, 10, null, 80 )
  286. );
  287. }
  288. public function testCoveredBoxVerticalExtension1()
  289. {
  290. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  291. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 90, 100, 10 ) );
  292. $this->assertEquals(
  293. new ezcDocumentPdfBoundingBox( 0, 0, 100, 90 ),
  294. $page->testFitRectangle( 0, 0, 100, null )
  295. );
  296. }
  297. public function testCoveredBoxVerticalExtension2()
  298. {
  299. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  300. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 50, 100, 10 ) );
  301. $this->assertEquals(
  302. new ezcDocumentPdfBoundingBox( 0, 0, 100, 50 ),
  303. $page->testFitRectangle( 0, 0, 100, null )
  304. );
  305. }
  306. public function testCoveredBoxVerticalExtension3()
  307. {
  308. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  309. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 90, 100, 10 ) );
  310. $this->assertEquals(
  311. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  312. $page->testFitRectangle( 10, 10, 80, null )
  313. );
  314. }
  315. public function testCoveredBoxBiderectionalExtension1()
  316. {
  317. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  318. $page->setCovered( new ezcDocumentPdfBoundingBox( 90, 90, 10, 10 ) );
  319. $this->assertEquals(
  320. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  321. $page->testFitRectangle( 10, 10, null, null )
  322. );
  323. }
  324. public function testCoveredBoxBiderectionalExtension2()
  325. {
  326. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  327. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 90, 100, 10 ) );
  328. $page->setCovered( new ezcDocumentPdfBoundingBox( 90, 0, 10, 100 ) );
  329. $this->assertEquals(
  330. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  331. $page->testFitRectangle( 10, 10, null, null )
  332. );
  333. }
  334. public function testCoveredBoxExtensionAndOrthogonalMovement1()
  335. {
  336. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  337. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 10 ) );
  338. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 10, 100 ) );
  339. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 90, 100, 10 ) );
  340. $page->setCovered( new ezcDocumentPdfBoundingBox( 90, 0, 10, 100 ) );
  341. $this->assertEquals(
  342. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  343. $page->testFitRectangle( 10, null, null, 80 )
  344. );
  345. }
  346. public function testCoveredBoxExtensionAndOrthogonalMovement2()
  347. {
  348. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  349. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 100, 10 ) );
  350. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 10, 100 ) );
  351. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 90, 100, 10 ) );
  352. $page->setCovered( new ezcDocumentPdfBoundingBox( 90, 0, 10, 100 ) );
  353. $this->assertEquals(
  354. new ezcDocumentPdfBoundingBox( 10, 10, 80, 80 ),
  355. $page->testFitRectangle( null, 10, 80, null )
  356. );
  357. }
  358. public function testMoveAndExtendInSameDirection1()
  359. {
  360. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  361. try
  362. {
  363. $page->testFitRectangle( null, 10, null, 10 );
  364. $this->fail( 'Expected ezcBaseFunctionalityNotSupportedException' );
  365. }
  366. catch ( ezcBaseFunctionalityNotSupportedException $e )
  367. { /* Expected */ }
  368. }
  369. public function testMoveAndExtendInSameDirection2()
  370. {
  371. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  372. try
  373. {
  374. $page->testFitRectangle( 10, null, 10, null );
  375. $this->fail( 'Expected ezcBaseFunctionalityNotSupportedException' );
  376. }
  377. catch ( ezcBaseFunctionalityNotSupportedException $e )
  378. { /* Expected */ }
  379. }
  380. public function testMoveAndExtendInSameDirection3()
  381. {
  382. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  383. try
  384. {
  385. $page->testFitRectangle( null, null, null, null );
  386. $this->fail( 'Expected ezcBaseFunctionalityNotSupportedException' );
  387. }
  388. catch ( ezcBaseFunctionalityNotSupportedException $e )
  389. { /* Expected */ }
  390. }
  391. public function testCoveredAreasInDifferentTransactions()
  392. {
  393. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  394. $page->startTransaction( 1 );
  395. $page->setCovered( new ezcDocumentPdfBoundingBox( 80, 0, 20, 100 ) );
  396. $page->startTransaction( 2 );
  397. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  398. $this->assertEquals(
  399. new ezcDocumentPdfBoundingBox( 20, 10, 60, 80 ),
  400. $page->testFitRectangle( null, 10, 60, 80 )
  401. );
  402. }
  403. public function testCoveredAreasWithRevertedTransaction()
  404. {
  405. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  406. $page->startTransaction( 1 );
  407. $page->setCovered( new ezcDocumentPdfBoundingBox( 80, 0, 20, 100 ) );
  408. $page->startTransaction( 2 );
  409. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  410. $page->revert( 2 );
  411. $this->assertEquals(
  412. new ezcDocumentPdfBoundingBox( 0, 10, 60, 80 ),
  413. $page->testFitRectangle( null, 10, 60, 80 )
  414. );
  415. }
  416. public function testCoveredAreasWithMultipleRevertedTransactions()
  417. {
  418. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  419. $page->startTransaction( 1 );
  420. $page->setCovered( new ezcDocumentPdfBoundingBox( 80, 0, 20, 100 ) );
  421. $page->startTransaction( 2 );
  422. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 20, 100 ) );
  423. $page->revert( 1 );
  424. $this->assertEquals(
  425. new ezcDocumentPdfBoundingBox( 0, 10, 100, 80 ),
  426. $page->testFitRectangle( null, 10, 100, 80 )
  427. );
  428. }
  429. public function testUncoverArea()
  430. {
  431. $page = new ezcDocumentPdfPage( 1, 100, 100 );
  432. $page->startTransaction( 1 );
  433. $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 0, 50, 50 ) );
  434. $id = $page->setCovered( new ezcDocumentPdfBoundingBox( 0, 50, 50, 50 ) );
  435. $page->setCovered( new ezcDocumentPdfBoundingBox( 50, 0, 50, 50 ) );
  436. $this->assertEquals( false, $page->testFitRectangle( 10, 60, 30, 30 ) );
  437. $page->uncover( $id );
  438. $this->assertEquals(
  439. new ezcDocumentPdfBoundingBox( 10, 60, 30, 30 ),
  440. $page->testFitRectangle( 10, 60, 30, 30 )
  441. );
  442. }
  443. }
  444. ?>