You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

493 lines
15 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Pdf
  17. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Style.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /**
  22. * Canvas is an abstract rectangle drawing area which can be dropped into
  23. * page object at specified place.
  24. *
  25. * @package Zend_Pdf
  26. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  27. * @license http://framework.zend.com/license/new-bsd New BSD License
  28. */
  29. interface Zend_Pdf_Canvas_Interface
  30. {
  31. /**
  32. * Returns dictionaries of used resources.
  33. *
  34. * Used for canvas implementations interoperability
  35. *
  36. * Structure of the returned array:
  37. * array(
  38. * <resTypeName> => array(
  39. * <resName> => <Zend_Pdf_Resource object>,
  40. * <resName> => <Zend_Pdf_Resource object>,
  41. * <resName> => <Zend_Pdf_Resource object>,
  42. * ...
  43. * ),
  44. * <resTypeName> => array(
  45. * <resName> => <Zend_Pdf_Resource object>,
  46. * <resName> => <Zend_Pdf_Resource object>,
  47. * <resName> => <Zend_Pdf_Resource object>,
  48. * ...
  49. * ),
  50. * ...
  51. * 'ProcSet' => array()
  52. * )
  53. *
  54. * where ProcSet array is a list of used procedure sets names (strings).
  55. * Allowed procedure set names: 'PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'
  56. *
  57. * @internal
  58. * @return array
  59. */
  60. public function getResources();
  61. /**
  62. * Get drawing instructions stream
  63. *
  64. * It has to be returned as a PDF stream object to make it reusable.
  65. *
  66. * @internal
  67. * @returns Zend_Pdf_Resource_ContentStream
  68. */
  69. public function getContents();
  70. /**
  71. * Return canvas height.
  72. *
  73. * @return float
  74. */
  75. public function getHeight();
  76. /**
  77. * Return canvas width.
  78. *
  79. * @return float
  80. */
  81. public function getWidth();
  82. /**
  83. * Draw a canvas at the specified location
  84. *
  85. * If upper right corner is not specified then canvas heght and width
  86. * are used.
  87. *
  88. * @param Zend_Pdf_Canvas_Interface $canvas
  89. * @param float $x1
  90. * @param float $y1
  91. * @param float $x2
  92. * @param float $y2
  93. * @return Zend_Pdf_Canvas_Interface
  94. */
  95. public function drawCanvas(Zend_Pdf_Canvas_Interface $canvas, $x1, $y1, $x2 = null, $y2 = null);
  96. /**
  97. * Set fill color.
  98. *
  99. * @param Zend_Pdf_Color $color
  100. * @return Zend_Pdf_Canvas_Interface
  101. */
  102. public function setFillColor(Zend_Pdf_Color $color);
  103. /**
  104. * Set line color.
  105. *
  106. * @param Zend_Pdf_Color $color
  107. * @return Zend_Pdf_Canvas_Interface
  108. */
  109. public function setLineColor(Zend_Pdf_Color $color);
  110. /**
  111. * Set line width.
  112. *
  113. * @param float $width
  114. * @return Zend_Pdf_Canvas_Interface
  115. */
  116. public function setLineWidth($width);
  117. /**
  118. * Set line dashing pattern
  119. *
  120. * Pattern is an array of floats: array(on_length, off_length, on_length, off_length, ...)
  121. * or Zend_Pdf_Page::LINE_DASHING_SOLID constant
  122. * Phase is shift from the beginning of line.
  123. *
  124. * @param mixed $pattern
  125. * @param array $phase
  126. * @return Zend_Pdf_Canvas_Interface
  127. */
  128. public function setLineDashingPattern($pattern, $phase = 0);
  129. /**
  130. * Set current font.
  131. *
  132. * @param Zend_Pdf_Resource_Font $font
  133. * @param float $fontSize
  134. * @return Zend_Pdf_Canvas_Interface
  135. */
  136. public function setFont(Zend_Pdf_Resource_Font $font, $fontSize);
  137. /**
  138. * Set the style to use for future drawing operations on this page
  139. *
  140. * @param Zend_Pdf_Style $style
  141. * @return Zend_Pdf_Canvas_Interface
  142. */
  143. public function setStyle(Zend_Pdf_Style $style);
  144. /**
  145. * Get current font.
  146. *
  147. * @return Zend_Pdf_Resource_Font $font
  148. */
  149. public function getFont();
  150. /**
  151. * Get current font size
  152. *
  153. * @return float $fontSize
  154. */
  155. public function getFontSize();
  156. /**
  157. * Return the style, applied to the page.
  158. *
  159. * @return Zend_Pdf_Style|null
  160. */
  161. public function getStyle();
  162. /**
  163. * Save the graphics state of this page.
  164. * This takes a snapshot of the currently applied style, position, clipping area and
  165. * any rotation/translation/scaling that has been applied.
  166. *
  167. * @throws Zend_Pdf_Exception - if a save is performed with an open path
  168. * @return Zend_Pdf_Page
  169. */
  170. public function saveGS();
  171. /**
  172. * Set the transparancy
  173. *
  174. * $alpha == 0 - transparent
  175. * $alpha == 1 - opaque
  176. *
  177. * Transparency modes, supported by PDF:
  178. * Normal (default), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight,
  179. * SoftLight, Difference, Exclusion
  180. *
  181. * @param float $alpha
  182. * @param string $mode
  183. * @throws Zend_Pdf_Exception
  184. * @return Zend_Pdf_Canvas_Interface
  185. */
  186. public function setAlpha($alpha, $mode = 'Normal');
  187. /**
  188. * Intersect current clipping area with a circle.
  189. *
  190. * @param float $x
  191. * @param float $y
  192. * @param float $radius
  193. * @param float $startAngle
  194. * @param float $endAngle
  195. * @return Zend_Pdf_Canvas_Interface
  196. */
  197. public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null);
  198. /**
  199. * Intersect current clipping area with a polygon.
  200. *
  201. * Method signatures:
  202. * drawEllipse($x1, $y1, $x2, $y2);
  203. * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
  204. *
  205. * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
  206. *
  207. * @param float $x1
  208. * @param float $y1
  209. * @param float $x2
  210. * @param float $y2
  211. * @param float $startAngle
  212. * @param float $endAngle
  213. * @return Zend_Pdf_Canvas_Interface
  214. */
  215. public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null);
  216. /**
  217. * Intersect current clipping area with a polygon.
  218. *
  219. * @param array $x - array of float (the X co-ordinates of the vertices)
  220. * @param array $y - array of float (the Y co-ordinates of the vertices)
  221. * @param integer $fillMethod
  222. * @return Zend_Pdf_Canvas_Interface
  223. */
  224. public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING);
  225. /**
  226. * Intersect current clipping area with a rectangle.
  227. *
  228. * @param float $x1
  229. * @param float $y1
  230. * @param float $x2
  231. * @param float $y2
  232. * @return Zend_Pdf_Canvas_Interface
  233. */
  234. public function clipRectangle($x1, $y1, $x2, $y2);
  235. /**
  236. * Draw a circle centered on x, y with a radius of radius.
  237. *
  238. * Method signatures:
  239. * drawCircle($x, $y, $radius);
  240. * drawCircle($x, $y, $radius, $fillType);
  241. * drawCircle($x, $y, $radius, $startAngle, $endAngle);
  242. * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType);
  243. *
  244. *
  245. * It's not a really circle, because PDF supports only cubic Bezier curves.
  246. * But _very_ good approximation.
  247. * It differs from a real circle on a maximum 0.00026 radiuses
  248. * (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles).
  249. * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle.
  250. *
  251. * @param float $x
  252. * @param float $y
  253. * @param float $radius
  254. * @param mixed $param4
  255. * @param mixed $param5
  256. * @param mixed $param6
  257. * @return Zend_Pdf_Canvas_Interface
  258. */
  259. public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null);
  260. /**
  261. * Draw an ellipse inside the specified rectangle.
  262. *
  263. * Method signatures:
  264. * drawEllipse($x1, $y1, $x2, $y2);
  265. * drawEllipse($x1, $y1, $x2, $y2, $fillType);
  266. * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle);
  267. * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType);
  268. *
  269. * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0
  270. *
  271. * @param float $x1
  272. * @param float $y1
  273. * @param float $x2
  274. * @param float $y2
  275. * @param mixed $param5
  276. * @param mixed $param6
  277. * @param mixed $param7
  278. * @return Zend_Pdf_Canvas_Interface
  279. */
  280. public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null);
  281. /**
  282. * Draw an image at the specified position on the page.
  283. *
  284. * @param Zend_Pdf_Image $image
  285. * @param float $x1
  286. * @param float $y1
  287. * @param float $x2
  288. * @param float $y2
  289. * @return Zend_Pdf_Canvas_Interface
  290. */
  291. public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2);
  292. /**
  293. * Draw a LayoutBox at the specified position on the page.
  294. *
  295. * @internal (not implemented now)
  296. *
  297. * @param Zend_Pdf_Element_LayoutBox $box
  298. * @param float $x
  299. * @param float $y
  300. * @return Zend_Pdf_Canvas_Interface
  301. */
  302. public function drawLayoutBox($box, $x, $y);
  303. /**
  304. * Draw a line from x1,y1 to x2,y2.
  305. *
  306. * @param float $x1
  307. * @param float $y1
  308. * @param float $x2
  309. * @param float $y2
  310. * @return Zend_Pdf_Canvas_Interface
  311. */
  312. public function drawLine($x1, $y1, $x2, $y2);
  313. /**
  314. * Draw a polygon.
  315. *
  316. * If $fillType is Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE or
  317. * Zend_Pdf_Page::SHAPE_DRAW_FILL, then polygon is automatically closed.
  318. * See detailed description of these methods in a PDF documentation
  319. * (section 4.4.2 Path painting Operators, Filling)
  320. *
  321. * @param array $x - array of float (the X co-ordinates of the vertices)
  322. * @param array $y - array of float (the Y co-ordinates of the vertices)
  323. * @param integer $fillType
  324. * @param integer $fillMethod
  325. * @return Zend_Pdf_Canvas_Interface
  326. */
  327. public function drawPolygon($x, $y,
  328. $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
  329. $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING);
  330. /**
  331. * Draw a rectangle.
  332. *
  333. * Fill types:
  334. * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
  335. * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
  336. * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
  337. *
  338. * @param float $x1
  339. * @param float $y1
  340. * @param float $x2
  341. * @param float $y2
  342. * @param integer $fillType
  343. * @return Zend_Pdf_Canvas_Interface
  344. */
  345. public function drawRectangle($x1, $y1, $x2, $y2, $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
  346. /**
  347. * Draw a rounded rectangle.
  348. *
  349. * Fill types:
  350. * Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE - fill rectangle and stroke (default)
  351. * Zend_Pdf_Page::SHAPE_DRAW_STROKE - stroke rectangle
  352. * Zend_Pdf_Page::SHAPE_DRAW_FILL - fill rectangle
  353. *
  354. * radius is an integer representing radius of the four corners, or an array
  355. * of four integers representing the radius starting at top left, going
  356. * clockwise
  357. *
  358. * @param float $x1
  359. * @param float $y1
  360. * @param float $x2
  361. * @param float $y2
  362. * @param integer|array $radius
  363. * @param integer $fillType
  364. * @return Zend_Pdf_Canvas_Interface
  365. */
  366. public function drawRoundedRectangle($x1, $y1, $x2, $y2, $radius,
  367. $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE);
  368. /**
  369. * Draw a line of text at the specified position.
  370. *
  371. * @param string $text
  372. * @param float $x
  373. * @param float $y
  374. * @param string $charEncoding (optional) Character encoding of source text.
  375. * Defaults to current locale.
  376. * @throws Zend_Pdf_Exception
  377. * @return Zend_Pdf_Canvas_Interface
  378. */
  379. public function drawText($text, $x, $y, $charEncoding = '');
  380. /**
  381. * Close the path by drawing a straight line back to it's beginning.
  382. *
  383. * @internal (needs implementation)
  384. *
  385. * @throws Zend_Pdf_Exception - if a path hasn't been started with pathMove()
  386. * @return Zend_Pdf_Canvas_Interface
  387. */
  388. public function pathClose();
  389. /**
  390. * Continue the open path in a straight line to the specified position.
  391. *
  392. * @internal (needs implementation)
  393. *
  394. * @param float $x - the X co-ordinate to move to
  395. * @param float $y - the Y co-ordinate to move to
  396. * @return Zend_Pdf_Canvas_Interface
  397. */
  398. public function pathLine($x, $y);
  399. /**
  400. * Start a new path at the specified position. If a path has already been started,
  401. * move the cursor without drawing a line.
  402. *
  403. * @internal (needs implementation)
  404. *
  405. * @param float $x - the X co-ordinate to move to
  406. * @param float $y - the Y co-ordinate to move to
  407. * @return Zend_Pdf_Canvas_Interface
  408. */
  409. public function pathMove($x, $y);
  410. /**
  411. * Rotate the page.
  412. *
  413. * @param float $x - the X co-ordinate of rotation point
  414. * @param float $y - the Y co-ordinate of rotation point
  415. * @param float $angle - rotation angle
  416. * @return Zend_Pdf_Canvas_Interface
  417. */
  418. public function rotate($x, $y, $angle);
  419. /**
  420. * Scale coordination system.
  421. *
  422. * @param float $xScale - X dimention scale factor
  423. * @param float $yScale - Y dimention scale factor
  424. * @return Zend_Pdf_Canvas_Interface
  425. */
  426. public function scale($xScale, $yScale);
  427. /**
  428. * Translate coordination system.
  429. *
  430. * @param float $xShift - X coordinate shift
  431. * @param float $yShift - Y coordinate shift
  432. * @return Zend_Pdf_Canvas_Interface
  433. */
  434. public function translate($xShift, $yShift);
  435. /**
  436. * Translate coordination system.
  437. *
  438. * @param float $x - the X co-ordinate of axis skew point
  439. * @param float $y - the Y co-ordinate of axis skew point
  440. * @param float $xAngle - X axis skew angle
  441. * @param float $yAngle - Y axis skew angle
  442. * @return Zend_Pdf_Canvas_Interface
  443. */
  444. public function skew($x, $y, $xAngle, $yAngle);
  445. /**
  446. * Writes the raw data to the page's content stream.
  447. *
  448. * Be sure to consult the PDF reference to ensure your syntax is correct. No
  449. * attempt is made to ensure the validity of the stream data.
  450. *
  451. * @param string $data
  452. * @param string $procSet (optional) Name of ProcSet to add.
  453. * @return Zend_Pdf_Canvas_Interface
  454. */
  455. public function rawWrite($data, $procSet = null);
  456. }