renderer_paragraph_tests.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. /**
  3. * ezcDocumentPdfDriverTcpdfTests
  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. require_once 'renderer_text_box_base_tests.php';
  28. /**
  29. * Test suite for class.
  30. *
  31. * @package Document
  32. * @subpackage Tests
  33. */
  34. class ezcDocumentPdfParagraphRendererTests extends ezcDocumentPdfTextBoxRendererBaseTests
  35. {
  36. /**
  37. * Renderer used for the tests
  38. *
  39. * @var string
  40. */
  41. protected $renderer = 'ezcDocumentPdfWrappingTextBoxRenderer';
  42. public static function suite()
  43. {
  44. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  45. }
  46. public function testRenderParagraphSplitting()
  47. {
  48. // Additional formatting
  49. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  50. 'createPage',
  51. 'drawWord',
  52. ) );
  53. // Expectations
  54. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  55. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  56. );
  57. $mock->expects( $this->at( 1 ) )->method( 'drawWord' )->with(
  58. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'This' )
  59. );
  60. $mock->expects( $this->at( 24 ) )->method( 'createPage' )->with(
  61. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  62. );
  63. $mock->expects( $this->at( 25 ) )->method( 'drawWord' )->with(
  64. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'short' )
  65. );
  66. $docbook = new ezcDocumentDocbook();
  67. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/wrapping.xml' );
  68. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  69. $pdf = $renderer->render(
  70. $docbook,
  71. new ezcDocumentPdfDefaultHyphenator()
  72. );
  73. }
  74. public function testRenderParagraphWidow()
  75. {
  76. // Additional formatting
  77. $this->styles->appendStyleDirectives( array(
  78. new ezcDocumentPcssLayoutDirective(
  79. array( 'article' ),
  80. array(
  81. 'orphans' => '0',
  82. 'widows' => '0',
  83. )
  84. )
  85. ) );
  86. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  87. 'createPage',
  88. 'drawWord',
  89. ) );
  90. // Expectations
  91. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  92. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  93. );
  94. $mock->expects( $this->at( 1 ) )->method( 'drawWord' )->with(
  95. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'This' )
  96. );
  97. $mock->expects( $this->at( 24 ) )->method( 'createPage' )->with(
  98. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  99. );
  100. $mock->expects( $this->at( 25 ) )->method( 'drawWord' )->with(
  101. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'the' )
  102. );
  103. $docbook = new ezcDocumentDocbook();
  104. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/widow.xml' );
  105. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  106. $pdf = $renderer->render(
  107. $docbook,
  108. new ezcDocumentPdfDefaultHyphenator()
  109. );
  110. }
  111. public function testRenderParagraphWidowWrap()
  112. {
  113. // Additional formatting
  114. $this->styles->appendStyleDirectives( array(
  115. new ezcDocumentPcssLayoutDirective(
  116. array( 'article' ),
  117. array(
  118. 'orphans' => '0',
  119. 'widows' => '2',
  120. )
  121. )
  122. ) );
  123. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  124. 'createPage',
  125. 'drawWord',
  126. ) );
  127. // Expectations
  128. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  129. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  130. );
  131. $mock->expects( $this->at( 1 ) )->method( 'drawWord' )->with(
  132. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'This' )
  133. );
  134. $mock->expects( $this->at( 21 ) )->method( 'createPage' )->with(
  135. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  136. );
  137. $mock->expects( $this->at( 22 ) )->method( 'drawWord' )->with(
  138. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'widow,' )
  139. );
  140. $mock->expects( $this->at( 25 ) )->method( 'drawWord' )->with(
  141. $this->equalTo( 10, 1. ), $this->equalTo( 29.2, 1. ), $this->equalTo( 'the' )
  142. );
  143. $docbook = new ezcDocumentDocbook();
  144. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/widow.xml' );
  145. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  146. $pdf = $renderer->render(
  147. $docbook,
  148. new ezcDocumentPdfDefaultHyphenator()
  149. );
  150. }
  151. public function testRenderParagraphOrphan()
  152. {
  153. // Additional formatting
  154. $this->styles->appendStyleDirectives( array(
  155. new ezcDocumentPcssLayoutDirective(
  156. array( 'article' ),
  157. array(
  158. 'orphans' => '0',
  159. 'widows' => '0',
  160. )
  161. )
  162. ) );
  163. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  164. 'createPage',
  165. 'drawWord',
  166. ) );
  167. // Expectations
  168. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  169. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  170. );
  171. $mock->expects( $this->at( 1 ) )->method( 'drawWord' )->with(
  172. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'This' )
  173. );
  174. $mock->expects( $this->at( 22 ) )->method( 'drawWord' )->with(
  175. $this->equalTo( 10, 1. ), $this->equalTo( 82, 1. ), $this->equalTo( 'Second' )
  176. );
  177. $mock->expects( $this->at( 24 ) )->method( 'createPage' )->with(
  178. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  179. );
  180. $mock->expects( $this->at( 25 ) )->method( 'drawWord' )->with(
  181. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'which' )
  182. );
  183. $docbook = new ezcDocumentDocbook();
  184. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/orphan.xml' );
  185. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  186. $pdf = $renderer->render(
  187. $docbook,
  188. new ezcDocumentPdfDefaultHyphenator()
  189. );
  190. }
  191. public function testRenderParagraphOrphanWrapped()
  192. {
  193. // Additional formatting
  194. $this->styles->appendStyleDirectives( array(
  195. new ezcDocumentPcssLayoutDirective(
  196. array( 'article' ),
  197. array(
  198. 'orphans' => '2',
  199. 'widows' => '0',
  200. )
  201. )
  202. ) );
  203. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  204. 'createPage',
  205. 'drawWord',
  206. ) );
  207. // Expectations
  208. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  209. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  210. );
  211. $mock->expects( $this->at( 1 ) )->method( 'drawWord' )->with(
  212. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'This' )
  213. );
  214. $mock->expects( $this->at( 22 ) )->method( 'createPage' )->with(
  215. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  216. );
  217. $mock->expects( $this->at( 23 ) )->method( 'drawWord' )->with(
  218. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'Second' )
  219. );
  220. $docbook = new ezcDocumentDocbook();
  221. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/orphan.xml' );
  222. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  223. $pdf = $renderer->render(
  224. $docbook,
  225. new ezcDocumentPdfDefaultHyphenator()
  226. );
  227. }
  228. public function testRenderParagraphOrphansAndWidows()
  229. {
  230. // Additional formatting
  231. $this->styles->appendStyleDirectives( array(
  232. new ezcDocumentPcssLayoutDirective(
  233. array( 'article' ),
  234. array(
  235. 'orphans' => '3',
  236. 'widows' => '3',
  237. )
  238. )
  239. ) );
  240. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  241. 'createPage',
  242. 'drawWord',
  243. ) );
  244. // Expectations
  245. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  246. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  247. );
  248. $mock->expects( $this->at( 1 ) )->method( 'drawWord' )->with(
  249. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'This' )
  250. );
  251. $mock->expects( $this->at( 22 ) )->method( 'createPage' )->with(
  252. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  253. );
  254. $mock->expects( $this->at( 23 ) )->method( 'drawWord' )->with(
  255. $this->equalTo( 10, 1. ), $this->equalTo( 18, 1. ), $this->equalTo( 'Second' )
  256. );
  257. $docbook = new ezcDocumentDocbook();
  258. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/short_orphan.xml' );
  259. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  260. $pdf = $renderer->render(
  261. $docbook,
  262. new ezcDocumentPdfDefaultHyphenator()
  263. );
  264. }
  265. public function testRenderParagraphSplittingWithBorderFirstPage()
  266. {
  267. // Additional formatting
  268. $this->styles->appendStyleDirectives( array(
  269. new ezcDocumentPcssLayoutDirective(
  270. array( 'para' ),
  271. array(
  272. 'line-height' => '1',
  273. 'padding' => '5',
  274. 'margin' => '5',
  275. 'border' => '1mm solid #A00000',
  276. 'background-color' => '#eedbdb',
  277. )
  278. )
  279. ) );
  280. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  281. 'drawPolyline',
  282. 'drawPolygon',
  283. 'createPage',
  284. 'drawWord',
  285. ) );
  286. // Expectations for first page
  287. $mock->expects( $this->at( 0 ) )->method( 'createPage' )->with(
  288. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  289. );
  290. $mock->expects( $this->at( 1 ) )->method( 'drawPolygon' )->with(
  291. $this->equalTo( array(
  292. array( 15, 15 ),
  293. array( 85, 15 ),
  294. array( 85, 83 ),
  295. array( 15, 83 ),
  296. ), 1. ),
  297. $this->equalTo( array(
  298. 'red' => .93,
  299. 'green' => .86,
  300. 'blue' => .86,
  301. 'alpha' => 0
  302. ), .01 )
  303. );
  304. $mock->expects( $this->at( 2 ) )->method( 'drawPolyline' )->with(
  305. $this->equalTo( array( array( 15.5, 15.5 ), array( 15.5, 82.5 ) ), .1 ),
  306. $this->equalTo( array(
  307. 'red' => .63,
  308. 'green' => .0,
  309. 'blue' => .0,
  310. 'alpha' => 0
  311. ), .01 )
  312. );
  313. $mock->expects( $this->at( 3 ) )->method( 'drawPolyline' )->with(
  314. $this->equalTo( array( array( 15.5, 15.5 ), array( 84.5, 15.5 ) ), .1 ),
  315. $this->equalTo( array(
  316. 'red' => .63,
  317. 'green' => .0,
  318. 'blue' => .0,
  319. 'alpha' => 0
  320. ), .01 )
  321. );
  322. $mock->expects( $this->at( 4 ) )->method( 'drawPolyline' )->with(
  323. $this->equalTo( array( array( 84.5, 15.5 ), array( 84.5, 82.5 ) ), .1 ),
  324. $this->equalTo( array(
  325. 'red' => .63,
  326. 'green' => .0,
  327. 'blue' => .0,
  328. 'alpha' => 0
  329. ), .01 )
  330. );
  331. $mock->expects( $this->at( 5 ) )->method( 'drawWord' )->with(
  332. $this->equalTo( 21, 1. ), $this->equalTo( 29, 1. ), $this->equalTo( 'This' )
  333. );
  334. $docbook = new ezcDocumentDocbook();
  335. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/wrapping.xml' );
  336. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  337. $pdf = $renderer->render(
  338. $docbook,
  339. new ezcDocumentPdfDefaultHyphenator()
  340. );
  341. }
  342. public function testRenderParagraphSplittingWithBorderSecondPage()
  343. {
  344. // Additional formatting
  345. $this->styles->appendStyleDirectives( array(
  346. new ezcDocumentPcssLayoutDirective(
  347. array( 'para' ),
  348. array(
  349. 'line-height' => '1',
  350. 'padding' => '5',
  351. 'margin' => '5',
  352. 'border' => '1mm solid #A00000',
  353. 'background-color' => '#eedbdb',
  354. )
  355. )
  356. ) );
  357. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  358. 'drawPolyline',
  359. 'drawPolygon',
  360. 'createPage',
  361. 'drawWord',
  362. ) );
  363. // Expectations for second page
  364. $mock->expects( $this->at( 18 ) )->method( 'createPage' )->with(
  365. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  366. );
  367. $mock->expects( $this->at( 19 ) )->method( 'drawPolygon' )->with(
  368. $this->equalTo( array(
  369. array( 15, 15 ),
  370. array( 85, 15 ),
  371. array( 85, 83 ),
  372. array( 15, 83 ),
  373. ), 1. ),
  374. $this->equalTo( array(
  375. 'red' => .93,
  376. 'green' => .86,
  377. 'blue' => .86,
  378. 'alpha' => 0
  379. ), .01 )
  380. );
  381. $mock->expects( $this->at( 20 ) )->method( 'drawPolyline' )->with(
  382. $this->equalTo( array( array( 15.5, 15.5 ), array( 15.5, 82.5 ) ), .1 ),
  383. $this->equalTo( array(
  384. 'red' => .63,
  385. 'green' => .0,
  386. 'blue' => .0,
  387. 'alpha' => 0
  388. ), .01 )
  389. );
  390. $mock->expects( $this->at( 21 ) )->method( 'drawPolyline' )->with(
  391. $this->equalTo( array( array( 84.5, 15.5 ), array( 84.5, 82.5 ) ), .1 ),
  392. $this->equalTo( array(
  393. 'red' => .63,
  394. 'green' => .0,
  395. 'blue' => .0,
  396. 'alpha' => 0
  397. ), .01 )
  398. );
  399. $mock->expects( $this->at( 22 ) )->method( 'drawWord' )->with(
  400. $this->equalTo( 21, 1. ), $this->equalTo( 29, 1. ), $this->equalTo( 'exceeding' )
  401. );
  402. $docbook = new ezcDocumentDocbook();
  403. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/wrapping.xml' );
  404. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  405. $pdf = $renderer->render(
  406. $docbook,
  407. new ezcDocumentPdfDefaultHyphenator()
  408. );
  409. }
  410. public function testRenderParagraphSplittingWithBorderLastPage()
  411. {
  412. // Additional formatting
  413. $this->styles->appendStyleDirectives( array(
  414. new ezcDocumentPcssLayoutDirective(
  415. array( 'para' ),
  416. array(
  417. 'line-height' => '1',
  418. 'padding' => '5',
  419. 'margin' => '5',
  420. 'border' => '1mm solid #A00000',
  421. 'background-color' => '#eedbdb',
  422. )
  423. )
  424. ) );
  425. $mock = $this->getMock( 'ezcTestDocumentPdfMockDriver', array(
  426. 'drawPolyline',
  427. 'drawPolygon',
  428. 'createPage',
  429. 'drawWord',
  430. ) );
  431. // Expectations for third page
  432. $mock->expects( $this->at( 38 ) )->method( 'createPage' )->with(
  433. $this->equalTo( 100, 1. ), $this->equalTo( 100, 1. )
  434. );
  435. $mock->expects( $this->at( 39 ) )->method( 'drawPolygon' )->with(
  436. $this->equalTo( array(
  437. array( 15, 15 ),
  438. array( 85, 15 ),
  439. array( 85, 51 ),
  440. array( 15, 51 ),
  441. ), 1. ),
  442. $this->equalTo( array(
  443. 'red' => .93,
  444. 'green' => .86,
  445. 'blue' => .86,
  446. 'alpha' => 0
  447. ), .01 )
  448. );
  449. $mock->expects( $this->at( 40 ) )->method( 'drawPolyline' )->with(
  450. $this->equalTo( array( array( 15.5, 15.5 ), array( 15.5, 50.5 ) ), .1 ),
  451. $this->equalTo( array(
  452. 'red' => .63,
  453. 'green' => .0,
  454. 'blue' => .0,
  455. 'alpha' => 0
  456. ), .01 )
  457. );
  458. $mock->expects( $this->at( 41 ) )->method( 'drawPolyline' )->with(
  459. $this->equalTo( array( array( 84.5, 15.5 ), array( 84.5, 50.5 ) ), .1 ),
  460. $this->equalTo( array(
  461. 'red' => .63,
  462. 'green' => .0,
  463. 'blue' => .0,
  464. 'alpha' => 0
  465. ), .01 )
  466. );
  467. $mock->expects( $this->at( 42 ) )->method( 'drawPolyline' )->with(
  468. $this->equalTo( array( array( 84.5, 50.5 ), array( 15.5, 50.5 ) ), .1 ),
  469. $this->equalTo( array(
  470. 'red' => .63,
  471. 'green' => .0,
  472. 'blue' => .0,
  473. 'alpha' => 0
  474. ), .01 )
  475. );
  476. $mock->expects( $this->at( 43 ) )->method( 'drawWord' )->with(
  477. $this->equalTo( 21, 1. ), $this->equalTo( 29, 1. ), $this->equalTo( 'be' )
  478. );
  479. $docbook = new ezcDocumentDocbook();
  480. $docbook->loadFile( dirname( __FILE__ ) . '/../files/pdf/wrapping.xml' );
  481. $renderer = new ezcDocumentPdfMainRenderer( $mock, $this->styles );
  482. $pdf = $renderer->render(
  483. $docbook,
  484. new ezcDocumentPdfDefaultHyphenator()
  485. );
  486. }
  487. }
  488. ?>