pdf_mocked_driver.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. /**
  3. * File containing the ezcDocumentPdfDriver class
  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. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. * @access private
  26. */
  27. /**
  28. * Test implemenation of PDF driver mocking actual driver behaviour
  29. */
  30. class ezcTestDocumentPdfMockDriver extends ezcDocumentPdfSvgDriver
  31. {
  32. protected $style;
  33. protected $size;
  34. public $calls = array();
  35. /**
  36. * Show a debug dump of all calls to the driver.
  37. *
  38. * @return void
  39. */
  40. public function debugDump()
  41. {
  42. foreach ( $this->calls as $nr => $call )
  43. {
  44. echo "\n", $nr, ") ", $call[0], "( ", @implode( ", ", $call[1] ), " )";
  45. }
  46. }
  47. /**
  48. * Convert values
  49. *
  50. * Convert measure values from the PCSS input file into another unit. The
  51. * input unit is read from the passed value and defaults to milli meters.
  52. * The output unit can be specified as the second parameter and also
  53. * default to milli meters.
  54. *
  55. * Supported units currently are: mm, px, pt, in
  56. *
  57. * @param mixed $input
  58. * @param string $format
  59. * @return void
  60. */
  61. public function convertValue( $input, $format = 'mm' )
  62. {
  63. return parent::convertValue( $input, $format );
  64. }
  65. /**
  66. * Create a new page
  67. *
  68. * Create a new page in the PDF document with the given width and height.
  69. *
  70. * @param float $width
  71. * @param float $height
  72. * @return void
  73. */
  74. public function createPage( $width, $height )
  75. {
  76. $this->calls[] = array( __FUNCTION__, func_get_args() );
  77. }
  78. /**
  79. * Set text formatting option
  80. *
  81. * Set a text formatting option. The names of the options are the same used
  82. * in the PCSS files and need to be translated by the driver to the proper
  83. * backend calls.
  84. *
  85. *
  86. * @param string $type
  87. * @param mixed $value
  88. * @return void
  89. */
  90. public function setTextFormatting( $type, $value )
  91. {
  92. switch ( $type )
  93. {
  94. case 'font-style':
  95. if ( ( $value === 'oblique' ) ||
  96. ( $value === 'italic' ) )
  97. {
  98. $this->style |= self::FONT_OBLIQUE;
  99. }
  100. else
  101. {
  102. $this->style &= ~self::FONT_OBLIQUE;
  103. }
  104. break;
  105. case 'font-weight':
  106. if ( ( $value === 'bold' ) ||
  107. ( $value === 'bolder' ) )
  108. {
  109. $this->style |= self::FONT_BOLD;
  110. }
  111. else
  112. {
  113. $this->style &= ~self::FONT_BOLD;
  114. }
  115. break;
  116. case 'font-size':
  117. $this->size = (float) $value;
  118. break;
  119. }
  120. }
  121. /**
  122. * Calculate the rendered width of the current word
  123. *
  124. * Calculate the width of the passed word, using the currently set text
  125. * formatting options.
  126. *
  127. * @param string $word
  128. * @return float
  129. */
  130. public function calculateWordWidth( $word )
  131. {
  132. return iconv_strlen( $word, 'UTF-8' ) * $this->size * .5 *
  133. ( $this->style & self::FONT_BOLD ? 1.5 : 1 ) *
  134. ( $this->style & self::FONT_OBLIQUE ? 1.2 : 1 );
  135. }
  136. /**
  137. * Get current line height
  138. *
  139. * Return the current line height in millimeter based on the current font
  140. * and text rendering settings.
  141. *
  142. * @return float
  143. */
  144. public function getCurrentLineHeight()
  145. {
  146. return $this->size;
  147. }
  148. /**
  149. * Draw word at given position
  150. *
  151. * Draw the given word at the given position using the currently set text
  152. * formatting options.
  153. *
  154. * @param float $x
  155. * @param float $y
  156. * @param string $word
  157. * @return void
  158. */
  159. public function drawWord( $x, $y, $word )
  160. {
  161. $this->calls[] = array( __FUNCTION__, func_get_args() );
  162. }
  163. /**
  164. * Draw a fileld polygon
  165. *
  166. * Draw any filled polygon, filled using the defined color. The color
  167. * should be passed as an array with the keys "red", "green", "blue" and
  168. * optionally "alpha". Each key should have a value between 0 and 1
  169. * associated.
  170. *
  171. * The polygon itself is specified as an array of two-tuples, specifying
  172. * the x and y coordinate of the point.
  173. *
  174. * @param array $points
  175. * @param array $color
  176. * @return void
  177. */
  178. public function drawPolygon( array $points, array $color )
  179. {
  180. $this->calls[] = array( __FUNCTION__, func_get_args() );
  181. }
  182. /**
  183. * Draw a polyline
  184. *
  185. * Draw any non-filled polygon, filled using the defined color. The color
  186. * should be passed as an array with the keys "red", "green", "blue" and
  187. * optionally "alpha". Each key should have a value between 0 and 1
  188. * associated.
  189. *
  190. * The polyline itself is specified as an array of two-tuples, specifying
  191. * the x and y coordinate of the point.
  192. *
  193. * The thrid parameter defines the width of the border and the last
  194. * parameter may optionally be set to false to not close the polygon (draw
  195. * another line from the last point to the first one).
  196. *
  197. * @param array $points
  198. * @param array $color
  199. * @param float $width
  200. * @param bool $close
  201. * @return void
  202. */
  203. public function drawPolyline( array $points, array $color, $width, $close = true )
  204. {
  205. $this->calls[] = array( __FUNCTION__, func_get_args() );
  206. }
  207. /**
  208. * Add an external link
  209. *
  210. * Add an external link to the rectangle specified by its top-left
  211. * position, width and height. The last parameter is the actual URL to link
  212. * to.
  213. *
  214. * @param float $x
  215. * @param float $y
  216. * @param float $width
  217. * @param float $height
  218. * @param string $url
  219. * @return void
  220. */
  221. public function addExternalLink( $x, $y, $width, $height, $url )
  222. {
  223. $this->calls[] = array( __FUNCTION__, func_get_args() );
  224. }
  225. /**
  226. * Add an internal link
  227. *
  228. * Add an internal link to the rectangle specified by its top-left
  229. * position, width and height. The last parameter is the target identifier
  230. * to link to.
  231. *
  232. * @param float $x
  233. * @param float $y
  234. * @param float $width
  235. * @param float $height
  236. * @param string $target
  237. * @return void
  238. */
  239. public function addInternalLink( $x, $y, $width, $height, $target )
  240. {
  241. $this->calls[] = array( __FUNCTION__, func_get_args() );
  242. }
  243. /**
  244. * Add an internal link target
  245. *
  246. * Add an internal link to the current page. The last parameter
  247. * is the target identifier.
  248. *
  249. * @param string $id
  250. * @return void
  251. */
  252. public function addInternalLinkTarget( $id )
  253. {
  254. $this->calls[] = array( __FUNCTION__, func_get_args() );
  255. }
  256. /**
  257. * Generate and return PDF
  258. *
  259. * Return the generated binary PDF content as a string.
  260. *
  261. * @return string
  262. */
  263. public function save()
  264. {
  265. $this->calls[] = array( __FUNCTION__, func_get_args() );
  266. }
  267. }
  268. ?>