driver_tests.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. <?php
  2. /**
  3. * ezcDocumentPdfDriverHaruTests
  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 'base.php';
  28. /**
  29. * Test suite for class.
  30. *
  31. * @package Document
  32. * @subpackage Tests
  33. */
  34. abstract class ezcDocumentPdfDriverTests extends ezcDocumentPdfTestCase
  35. {
  36. /**
  37. * Expected font widths for calculateWordWidth tests
  38. *
  39. * @var array
  40. */
  41. protected $expectedWidths = array(
  42. 'testEstimateDefaultWordWidthWithoutPageCreation' => null,
  43. 'testEstimateDefaultWordWidth' => null,
  44. 'testEstimateWordWidthDifferentSize' => null,
  45. 'testEstimateWordWidthDifferentSizeAndUnit' => null,
  46. 'testEstimateBoldWordWidth' => null,
  47. 'testEstimateMonospaceWordWidth' => null,
  48. 'testFontStyleFallback' => null,
  49. 'testUtf8FontWidth' => null,
  50. 'testCustomFontWidthEstimation' => null,
  51. );
  52. /**
  53. * Get driver to test
  54. *
  55. * @return ezcDocumentPdfDriver
  56. */
  57. abstract protected function getDriver();
  58. public function testEstimateDefaultWordWidthWithoutPageCreation()
  59. {
  60. $driver = $this->getDriver();
  61. $this->assertEquals(
  62. $this->expectedWidths[__FUNCTION__],
  63. $driver->calculateWordWidth( 'Hello' ),
  64. 'Wrong word width estimation', .1
  65. );
  66. }
  67. public function testEstimateDefaultWordWidth()
  68. {
  69. $driver = $this->getDriver();
  70. $driver->createPage( 210, 297 );
  71. $this->assertEquals(
  72. $this->expectedWidths[__FUNCTION__],
  73. $driver->calculateWordWidth( 'Hello' ),
  74. 'Wrong word width estimation', .1
  75. );
  76. }
  77. public function testEstimateWordWidthDifferentSize()
  78. {
  79. $driver = $this->getDriver();
  80. $driver->createPage( 210, 297 );
  81. $driver->setTextFormatting( 'font-size', '14' );
  82. $this->assertEquals(
  83. $this->expectedWidths[__FUNCTION__],
  84. $driver->calculateWordWidth( 'Hello' ),
  85. 'Wrong word width estimation', .1
  86. );
  87. }
  88. public function testEstimateWordWidthDifferentSizeAndUnit()
  89. {
  90. $driver = $this->getDriver();
  91. $driver->createPage( 210, 297 );
  92. $driver->setTextFormatting( 'font-size', '14pt' );
  93. $this->assertEquals(
  94. $this->expectedWidths[__FUNCTION__],
  95. $driver->calculateWordWidth( 'Hello' ),
  96. 'Wrong word width estimation', .1
  97. );
  98. }
  99. public function testEstimateBoldWordWidth()
  100. {
  101. $driver = $this->getDriver();
  102. $driver->createPage( 210, 297 );
  103. $driver->setTextFormatting( 'font-weight', 'bold' );
  104. $this->assertEquals(
  105. $this->expectedWidths[__FUNCTION__],
  106. $driver->calculateWordWidth( 'Hello' ),
  107. 'Wrong word width estimation', .1
  108. );
  109. }
  110. public function testEstimateMonospaceWordWidth()
  111. {
  112. $driver = $this->getDriver();
  113. $driver->createPage( 210, 297 );
  114. $driver->setTextFormatting( 'font-family', 'monospace' );
  115. $driver->setTextFormatting( 'font-size', '12' );
  116. $this->assertEquals(
  117. $this->expectedWidths[__FUNCTION__],
  118. $driver->calculateWordWidth( 'Hello' ),
  119. 'Wrong word width estimation', .1
  120. );
  121. }
  122. public function testFontStyleFallback()
  123. {
  124. $driver = $this->getDriver();
  125. $driver->createPage( 210, 297 );
  126. $driver->setTextFormatting( 'font-family', 'ZapfDingbats' );
  127. $driver->setTextFormatting( 'font-weight', 'bold' );
  128. $driver->setTextFormatting( 'font-style', 'italic' );
  129. $this->assertEquals(
  130. $this->expectedWidths[__FUNCTION__],
  131. $driver->calculateWordWidth( 'Hello' ),
  132. 'Wrong word width estimation', .1
  133. );
  134. }
  135. public function testUtf8FontWidth()
  136. {
  137. $driver = $this->getDriver();
  138. $driver->createPage( 210, 297 );
  139. $this->assertEquals(
  140. $this->expectedWidths[__FUNCTION__],
  141. $driver->calculateWordWidth( 'ℋℇℒℒΩ' ),
  142. 'Wrong word width estimation', .1
  143. );
  144. }
  145. public function testCustomFontWidthEstimation()
  146. {
  147. $driver = $this->getDriver();
  148. try {
  149. $driver->registerFont(
  150. 'my_font',
  151. ezcDocumentPdfDriver::FONT_PLAIN,
  152. array(
  153. dirname( __FILE__ ) . '/../files/fonts/fdb_font.fdb',
  154. dirname( __FILE__ ) . '/../files/fonts/ps_font.pfb',
  155. dirname( __FILE__ ) . '/../files/fonts/font.ttf',
  156. )
  157. );
  158. } catch ( ezcBaseFunctionalityNotSupportedException $e )
  159. {
  160. $this->markTestSkipped( 'Fonts are not supported.' );
  161. }
  162. $driver->createPage( 210, 297 );
  163. $driver->setTextFormatting( 'font-family', 'my_font' );
  164. $driver->setTextFormatting( 'font-size', '10' );
  165. $driver->setTextFormatting( 'font-weight', 'bold' );
  166. $this->assertEquals(
  167. $this->expectedWidths[__FUNCTION__],
  168. $driver->calculateWordWidth( 'Hello world.' ),
  169. 'Wrong word width estimation', .1
  170. );
  171. }
  172. public function testRenderHelloWorld()
  173. {
  174. $driver = $this->getDriver();
  175. $driver->createPage( 210, 297 );
  176. $driver->setTextFormatting( 'font-family', 'sans-serif' );
  177. $driver->setTextFormatting( 'font-size', '10' );
  178. $driver->drawWord( 0, 10, 'The quick brown fox jumps over the lazy dog' );
  179. $driver->drawWord( 0, 297, 'The quick brown fox jumps over the lazy dog' );
  180. $pdf = $driver->save();
  181. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  182. }
  183. public function testRenderHelloWorldSmallFont()
  184. {
  185. $driver = $this->getDriver();
  186. $driver->createPage( 210, 297 );
  187. $driver->setTextFormatting( 'font-family', 'sans-serif' );
  188. $driver->setTextFormatting( 'font-size', '4' );
  189. $driver->drawWord( 0, 4, 'The quick brown fox jumps over the lazy dog' );
  190. $driver->drawWord( 0, 297, 'The quick brown fox jumps over the lazy dog' );
  191. $pdf = $driver->save();
  192. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  193. }
  194. public function testRenderSwitchingFontStates()
  195. {
  196. $driver = $this->getDriver();
  197. $driver->createPage( 210, 297 );
  198. $driver->setTextFormatting( 'font-size', '8' );
  199. $driver->drawWord( 0, 8, 'The quick brown fox jumps over the lazy dog' );
  200. $driver->setTextFormatting( 'font-weight', 'bold' );
  201. $driver->setTextFormatting( 'font-style', 'italic' );
  202. $driver->drawWord( 0, 18, 'The quick brown fox jumps over the lazy dog' );
  203. $driver->setTextFormatting( 'font-style', 'normal' );
  204. $driver->drawWord( 0, 28, 'The quick brown fox jumps over the lazy dog' );
  205. $driver->setTextFormatting( 'font-weight', 'normal' );
  206. $driver->drawWord( 0, 38, 'The quick brown fox jumps over the lazy dog' );
  207. $driver->setTextFormatting( 'font-weight', 'bold' );
  208. $driver->drawWord( 0, 48, 'The quick brown fox jumps over the lazy dog' );
  209. $driver->setTextFormatting( 'font-family', 'serif' );
  210. $driver->drawWord( 0, 58, 'The quick brown fox jumps over the lazy dog' );
  211. $driver->setTextFormatting( 'font-weight', 'normal' );
  212. $driver->drawWord( 0, 68, 'The quick brown fox jumps over the lazy dog' );
  213. $driver->setTextFormatting( 'font-family', 'Symbol' );
  214. $driver->drawWord( 0, 78, 'The quick brown fox jumps over the lazy dog' );
  215. $driver->setTextFormatting( 'font-weight', 'bold' );
  216. $driver->drawWord( 0, 88, 'The quick brown fox jumps over the lazy dog' );
  217. $driver->setTextFormatting( 'font-style', 'italic' );
  218. $driver->drawWord( 0, 98, 'The quick brown fox jumps over the lazy dog' );
  219. $driver->setTextFormatting( 'font-family', 'monospace' );
  220. $driver->drawWord( 0, 108, 'The quick brown fox jumps over the lazy dog' );
  221. $driver->setTextFormatting( 'font-weight', 'bold' );
  222. $driver->setTextFormatting( 'font-style', 'italic' );
  223. $driver->drawWord( 0, 118, 'The quick brown fox jumps over the lazy dog' );
  224. $pdf = $driver->save();
  225. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  226. }
  227. public function testRenderUtf8Text()
  228. {
  229. $driver = $this->getDriver();
  230. $driver->createPage( 210, 297 );
  231. $driver->drawWord( 10, 10, 'ℋℇℒℒΩ' );
  232. $pdf = $driver->save();
  233. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  234. }
  235. public function testRenderPngImage()
  236. {
  237. $driver = $this->getDriver();
  238. $driver->createPage( 210, 297 );
  239. $driver->drawImage(
  240. dirname( __FILE__ ) . '/../files/pdf/images/logo-white.png', 'image/png',
  241. 50, 50,
  242. ezcDocumentPcssMeasure::create( '113px' )->get(),
  243. ezcDocumentPcssMeasure::create( '57px' )->get()
  244. );
  245. $pdf = $driver->save();
  246. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  247. }
  248. public function testRenderResizedJpegImage()
  249. {
  250. $driver = $this->getDriver();
  251. $driver->createPage( 210, 297 );
  252. $driver->drawImage(
  253. dirname( __FILE__ ) . '/../files/pdf/images/large.jpeg', 'image/jpeg',
  254. 50, 50,
  255. 110, 100
  256. );
  257. $pdf = $driver->save();
  258. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  259. }
  260. public function testRenderColoredText()
  261. {
  262. $driver = $this->getDriver();
  263. $driver->createPage( 210, 297 );
  264. $driver->setTextFormatting( 'font-family', 'sans-serif' );
  265. $driver->setTextFormatting( 'font-size', '4' );
  266. $color = new ezcDocumentPcssStyleColorValue();
  267. $color->parse( '#204a87' );
  268. $driver->setTextFormatting( 'color', $color->value );
  269. $driver->drawWord( 10, 10, 'The quick brown fox jumps over the lazy dog.' );
  270. $pdf = $driver->save();
  271. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  272. }
  273. public function testRenderPolygon()
  274. {
  275. $driver = $this->getDriver();
  276. $driver->createPage( 210, 297 );
  277. $color = new ezcDocumentPcssStyleColorValue();
  278. $color->parse( '#204a87' );
  279. $driver->drawPolygon(
  280. array(
  281. array( 10, 10 ),
  282. array( 200, 10 ),
  283. array( 105, 287 ),
  284. ),
  285. $color->value
  286. );
  287. $pdf = $driver->save();
  288. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  289. }
  290. public function testRenderPolylineClosed()
  291. {
  292. $driver = $this->getDriver();
  293. $driver->createPage( 210, 297 );
  294. $color = new ezcDocumentPcssStyleColorValue();
  295. $color->parse( '#204a87' );
  296. $driver->drawPolyline(
  297. array(
  298. array( 10, 10 ),
  299. array( 200, 10 ),
  300. array( 105, 287 ),
  301. ),
  302. $color->value,
  303. 1
  304. );
  305. $pdf = $driver->save();
  306. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  307. }
  308. public function testRenderPolylineOpen()
  309. {
  310. $driver = $this->getDriver();
  311. $driver->createPage( 210, 297 );
  312. $color = new ezcDocumentPcssStyleColorValue();
  313. $color->parse( '#204a87' );
  314. $driver->drawPolyline(
  315. array(
  316. array( 200, 10 ),
  317. array( 105, 287 ),
  318. array( 10, 10 ),
  319. ),
  320. $color->value,
  321. ezcDocumentPcssMeasure::create( '1pt' )->get(),
  322. false
  323. );
  324. $pdf = $driver->save();
  325. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  326. }
  327. public function testRenderLayeredPolygons()
  328. {
  329. $driver = $this->getDriver();
  330. $driver->createPage( 210, 297 );
  331. $color = new ezcDocumentPcssStyleColorValue();
  332. $color->parse( '#204a87' );
  333. $driver->drawPolygon(
  334. array(
  335. array( 10, 10 ),
  336. array( 200, 10 ),
  337. array( 105, 287 ),
  338. ),
  339. $color->value
  340. );
  341. $color = new ezcDocumentPcssStyleColorValue();
  342. $color->parse( '#2e3436' );
  343. $driver->drawPolyline(
  344. array(
  345. array( 200, 287 ),
  346. array( 105, 10 ),
  347. array( 10, 287 ),
  348. ),
  349. $color->value,
  350. 1,
  351. false
  352. );
  353. $pdf = $driver->save();
  354. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  355. }
  356. public function testAddExternalLink()
  357. {
  358. $driver = $this->getDriver();
  359. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  360. {
  361. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  362. }
  363. $driver->createPage( 100, 100 );
  364. $driver->addExternalLink( 0, 0, 100, 100, 'http://ezcomponents.org/' );
  365. $pdf = $driver->save();
  366. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  367. }
  368. public function testAddInternalLinkWithoutTarget()
  369. {
  370. $driver = $this->getDriver();
  371. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  372. {
  373. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  374. }
  375. $driver->createPage( 100, 100 );
  376. $driver->addInternalLink( 0, 0, 100, 50, 'my_target' );
  377. $pdf = $driver->save();
  378. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  379. }
  380. public function testAddInternalLinkAndTarget()
  381. {
  382. $driver = $this->getDriver();
  383. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  384. {
  385. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  386. }
  387. $driver->createPage( 100, 100 );
  388. $driver->addInternalLink( 0, 0, 100, 50, 'my_target' );
  389. $driver->addInternalLinkTarget( 'my_target' );
  390. $pdf = $driver->save();
  391. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  392. }
  393. public function testAddInternalLinkAndTargetOnNextPage()
  394. {
  395. $driver = $this->getDriver();
  396. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  397. {
  398. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  399. }
  400. $driver->createPage( 100, 100 );
  401. $driver->addInternalLink( 0, 0, 100, 50, 'my_target' );
  402. $driver->createPage( 100, 100 );
  403. $driver->addInternalLinkTarget( 'my_target' );
  404. $pdf = $driver->save();
  405. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  406. }
  407. public function testRenderUnknownFont()
  408. {
  409. $driver = $this->getDriver();
  410. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  411. {
  412. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  413. }
  414. try {
  415. $driver->createPage( 250, 100 );
  416. $driver->setTextFormatting( 'font-family', 'my_font' );
  417. $this->fail( 'Expected ezcDocumentInvalidFontException.' );
  418. } catch ( ezcDocumentInvalidFontException $e )
  419. { /* Expected */ }
  420. }
  421. public function testRenderPlainTTFFont()
  422. {
  423. $driver = $this->getDriver();
  424. try {
  425. $driver->registerFont(
  426. 'my_font',
  427. ezcDocumentPdfDriver::FONT_PLAIN,
  428. array(
  429. dirname( __FILE__ ) . '/../files/fonts/font.ttf',
  430. )
  431. );
  432. } catch ( ezcBaseFunctionalityNotSupportedException $e )
  433. {
  434. $this->markTestSkipped( 'Fonts are not supported.' );
  435. }
  436. $driver->createPage( 250, 100 );
  437. $driver->setTextFormatting( 'font-family', 'my_font' );
  438. $driver->setTextFormatting( 'font-size', '10' );
  439. $driver->drawWord( 0, 10, 'The quick brown fox jumps over the lazy dog' );
  440. $pdf = $driver->save();
  441. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  442. }
  443. public function testRenderUnregisteredBoldTTFFont()
  444. {
  445. $driver = $this->getDriver();
  446. try {
  447. $driver->registerFont(
  448. 'my_font',
  449. ezcDocumentPdfDriver::FONT_PLAIN,
  450. array(
  451. dirname( __FILE__ ) . '/../files/fonts/font.ttf',
  452. )
  453. );
  454. } catch ( ezcBaseFunctionalityNotSupportedException $e )
  455. {
  456. $this->markTestSkipped( 'Fonts are not supported.' );
  457. }
  458. $driver->createPage( 250, 100 );
  459. $driver->setTextFormatting( 'font-family', 'my_font' );
  460. $driver->setTextFormatting( 'font-size', '10' );
  461. $driver->setTextFormatting( 'font-weight', 'bold' );
  462. $driver->drawWord( 0, 10, 'The quick brown fox jumps over the lazy dog' );
  463. $pdf = $driver->save();
  464. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  465. }
  466. public function testRenderRegisteredBoldTTFFont()
  467. {
  468. $driver = $this->getDriver();
  469. try {
  470. $driver->registerFont(
  471. 'my_font',
  472. ezcDocumentPdfDriver::FONT_PLAIN,
  473. array(
  474. dirname( __FILE__ ) . '/../files/fonts/font.ttf',
  475. )
  476. );
  477. $driver->registerFont(
  478. 'my_font',
  479. ezcDocumentPdfDriver::FONT_BOLD,
  480. array(
  481. dirname( __FILE__ ) . '/../files/fonts/font2.ttf',
  482. )
  483. );
  484. } catch ( ezcBaseFunctionalityNotSupportedException $e )
  485. {
  486. $this->markTestSkipped( 'Fonts are not supported.' );
  487. }
  488. $driver->createPage( 250, 100 );
  489. $driver->setTextFormatting( 'font-family', 'my_font' );
  490. $driver->setTextFormatting( 'font-size', '10' );
  491. $driver->setTextFormatting( 'font-weight', 'bold' );
  492. $driver->drawWord( 0, 10, 'The quick brown fox jumps over the lazy dog' );
  493. $pdf = $driver->save();
  494. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  495. }
  496. public function testRenderMultipleAlternativeFonts()
  497. {
  498. $driver = $this->getDriver();
  499. try {
  500. $driver->registerFont(
  501. 'my_font',
  502. ezcDocumentPdfDriver::FONT_PLAIN,
  503. array(
  504. dirname( __FILE__ ) . '/../files/fonts/fdb_font.fdb',
  505. dirname( __FILE__ ) . '/../files/fonts/ps_font.pfb',
  506. dirname( __FILE__ ) . '/../files/fonts/font.ttf',
  507. )
  508. );
  509. } catch ( ezcBaseFunctionalityNotSupportedException $e )
  510. {
  511. $this->markTestSkipped( 'Fonts are not supported.' );
  512. }
  513. $driver->createPage( 250, 100 );
  514. $driver->setTextFormatting( 'font-family', 'my_font' );
  515. $driver->setTextFormatting( 'font-size', '10' );
  516. $driver->drawWord( 0, 10, 'The quick brown fox jumps over the lazy dog' );
  517. $pdf = $driver->save();
  518. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  519. }
  520. public function testSetDocumentMetaDataTitle()
  521. {
  522. $driver = $this->getDriver();
  523. $driver->createPage( 100, 100 );
  524. $driver->setTextFormatting( 'font-size', '10' );
  525. $driver->drawWord( 0, 10, 'Document metadata test.' );
  526. $driver->setMetaData( 'title', 'Test document title' );
  527. $pdf = $driver->save();
  528. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  529. }
  530. public function testSetDocumentMetaDataAuthor()
  531. {
  532. $driver = $this->getDriver();
  533. $driver->createPage( 100, 100 );
  534. $driver->setTextFormatting( 'font-size', '10' );
  535. $driver->drawWord( 0, 10, 'Document metadata test.' );
  536. $driver->setMetaData( 'author', 'Kore Nordmann' );
  537. $pdf = $driver->save();
  538. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  539. }
  540. public function testSetDocumentMetaDataSubject()
  541. {
  542. $driver = $this->getDriver();
  543. $driver->createPage( 100, 100 );
  544. $driver->setTextFormatting( 'font-size', '10' );
  545. $driver->drawWord( 0, 10, 'Document metadata test.' );
  546. $driver->setMetaData( 'subject', 'Test document subject' );
  547. $pdf = $driver->save();
  548. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  549. }
  550. public function testSetDocumentMetaDataCreated()
  551. {
  552. $driver = $this->getDriver();
  553. $driver->createPage( 100, 100 );
  554. $driver->setTextFormatting( 'font-size', '10' );
  555. $driver->drawWord( 0, 10, 'Document metadata test.' );
  556. $driver->setMetaData( 'created', date( 'r', 12345678 ) );
  557. $pdf = $driver->save();
  558. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  559. }
  560. public function testSetDocumentMetaDataModified()
  561. {
  562. $driver = $this->getDriver();
  563. $driver->createPage( 100, 100 );
  564. $driver->setTextFormatting( 'font-size', '10' );
  565. $driver->drawWord( 0, 10, 'Document metadata test.' );
  566. $driver->setMetaData( 'modified', date( 'r', 12345678 ) );
  567. $pdf = $driver->save();
  568. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  569. }
  570. public function testGenerateCompressedPdf()
  571. {
  572. $driver = $this->getDriver();
  573. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  574. {
  575. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  576. }
  577. $options = new ezcDocumentPdfOptions();
  578. $options->compress = true;
  579. $driver->setOptions( $options );
  580. $driver->createPage( 100, 100 );
  581. $driver->setTextFormatting( 'font-size', '10' );
  582. $driver->drawWord( 0, 10, 'Document compression test.' );
  583. $pdf = $driver->save();
  584. $this->assertPdfDocumentsSimilar( $pdf, get_class( $driver ) . '_' . __FUNCTION__ );
  585. }
  586. public function testGeneratePdfWithOwnerPassword()
  587. {
  588. $driver = $this->getDriver();
  589. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  590. {
  591. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  592. }
  593. $options = new ezcDocumentPdfOptions();
  594. $options->ownerPassword = 'foobar23';
  595. $driver->setOptions( $options );
  596. $driver->createPage( 100, 100 );
  597. $driver->setTextFormatting( 'font-size', '10' );
  598. $driver->drawWord( 0, 10, 'Document compression test.' );
  599. $pdf = $driver->save();
  600. // We cannot make any proper asserstions here, since the PDF contents
  601. // change with each regeneration because of the encryption
  602. $this->assertFalse( empty( $pdf ) );
  603. }
  604. public function testGenerateEncryptedPdf()
  605. {
  606. $driver = $this->getDriver();
  607. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  608. {
  609. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  610. }
  611. $options = new ezcDocumentPdfOptions();
  612. $options->ownerPassword = 'foobar23';
  613. $options->userPassword = 'foobar';
  614. $driver->setOptions( $options );
  615. $driver->createPage( 100, 100 );
  616. $driver->setTextFormatting( 'font-size', '10' );
  617. $driver->drawWord( 0, 10, 'Document compression test.' );
  618. $pdf = $driver->save();
  619. // We cannot make any proper asserstions here, since the PDF contents
  620. // change with each regeneration because of the encryption
  621. $this->assertFalse( empty( $pdf ) );
  622. }
  623. public function testGenerateEncryptedProtectedPdf()
  624. {
  625. $driver = $this->getDriver();
  626. if ( $driver instanceof ezcDocumentPdfSvgDriver )
  627. {
  628. $this->markTestSkipped( 'Not supported by the SVG driver.' );
  629. }
  630. $options = new ezcDocumentPdfOptions();
  631. $options->permissions = 0;
  632. $options->ownerPassword = 'foobar23';
  633. $options->userPassword = 'foobar';
  634. $driver->setOptions( $options );
  635. $driver->createPage( 100, 100 );
  636. $driver->setTextFormatting( 'font-size', '10' );
  637. $driver->drawWord( 0, 10, 'Document compression test.' );
  638. $pdf = $driver->save();
  639. // We cannot make any proper asserstions here, since the PDF contents
  640. // change with each regeneration because of the encryption
  641. $this->assertFalse( empty( $pdf ) );
  642. }
  643. }
  644. ?>