canvas.cls.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /**
  3. * DOMPDF - PHP5 HTML to PDF renderer
  4. *
  5. * File: $RCSfile: canvas.cls.php,v $
  6. * Created on: 2004-06-06
  7. *
  8. * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library in the file LICENSE.LGPL; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  23. * 02111-1307 USA
  24. *
  25. * Alternatively, you may distribute this software under the terms of the
  26. * PHP License, version 3.0 or later. A copy of this license should have
  27. * been distributed with this file in the file LICENSE.PHP . If this is not
  28. * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
  29. *
  30. * The latest version of DOMPDF might be available at:
  31. * http://www.dompdf.com/
  32. *
  33. * @link http://www.dompdf.com/
  34. * @copyright 2004 Benj Carson
  35. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  36. * @package dompdf
  37. */
  38. /* $Id: canvas.cls.php 216 2010-03-11 22:49:18Z ryan.masten $ */
  39. /**
  40. * Main rendering interface
  41. *
  42. * Currently {@link CPDF_Adapter}, {@link PDFLib_Adapter}, {@link TCPDF_Adapter}, and {@link GD_Adapter}
  43. * implement this interface.
  44. *
  45. * Implementations should measure x and y increasing to the left and down,
  46. * respectively, with the origin in the top left corner. Implementations
  47. * are free to use a unit other than points for length, but I can't
  48. * guarantee that the results will look any good.
  49. *
  50. * @package dompdf
  51. */
  52. interface Canvas {
  53. /**
  54. * Returns the current page number
  55. *
  56. * @return int
  57. */
  58. function get_page_number();
  59. /**
  60. * Returns the total number of pages
  61. *
  62. * @return int
  63. */
  64. function get_page_count();
  65. /**
  66. * Sets the total number of pages
  67. *
  68. * @param int $count
  69. */
  70. function set_page_count($count);
  71. /**
  72. * Draws a line from x1,y1 to x2,y2
  73. *
  74. * See {@link Style::munge_colour()} for the format of the colour array.
  75. * See {@link Cpdf::setLineStyle()} for a description of the format of the
  76. * $style parameter (aka dash).
  77. *
  78. * @param float $x1
  79. * @param float $y1
  80. * @param float $x2
  81. * @param float $y2
  82. * @param array $color
  83. * @param float $width
  84. * @param array $style
  85. */
  86. function line($x1, $y1, $x2, $y2, $color, $width, $style = null);
  87. /**
  88. * Draws a rectangle at x1,y1 with width w and height h
  89. *
  90. * See {@link Style::munge_colour()} for the format of the colour array.
  91. * See {@link Cpdf::setLineStyle()} for a description of the $style
  92. * parameter (aka dash)
  93. *
  94. * @param float $x1
  95. * @param float $y1
  96. * @param float $w
  97. * @param float $h
  98. * @param array $color
  99. * @param float $width
  100. * @param array $style
  101. */
  102. function rectangle($x1, $y1, $w, $h, $color, $width, $style = null);
  103. /**
  104. * Draws a filled rectangle at x1,y1 with width w and height h
  105. *
  106. * See {@link Style::munge_colour()} for the format of the colour array.
  107. *
  108. * @param float $x1
  109. * @param float $y1
  110. * @param float $w
  111. * @param float $h
  112. * @param array $color
  113. */
  114. function filled_rectangle($x1, $y1, $w, $h, $color);
  115. /**
  116. * Draws a polygon
  117. *
  118. * The polygon is formed by joining all the points stored in the $points
  119. * array. $points has the following structure:
  120. * <code>
  121. * array(0 => x1,
  122. * 1 => y1,
  123. * 2 => x2,
  124. * 3 => y2,
  125. * ...
  126. * );
  127. * </code>
  128. *
  129. * See {@link Style::munge_colour()} for the format of the colour array.
  130. * See {@link Cpdf::setLineStyle()} for a description of the $style
  131. * parameter (aka dash)
  132. *
  133. * @param array $points
  134. * @param array $color
  135. * @param float $width
  136. * @param array $style
  137. * @param bool $fill Fills the polygon if true
  138. */
  139. function polygon($points, $color, $width = null, $style = null, $fill = false);
  140. /**
  141. * Draws a circle at $x,$y with radius $r
  142. *
  143. * See {@link Style::munge_colour()} for the format of the colour array.
  144. * See {@link Cpdf::setLineStyle()} for a description of the $style
  145. * parameter (aka dash)
  146. *
  147. * @param float $x
  148. * @param float $y
  149. * @param float $r
  150. * @param array $color
  151. * @param float $width
  152. * @param array $style
  153. * @param bool $fill Fills the circle if true
  154. */
  155. function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false);
  156. /**
  157. * Add an image to the pdf.
  158. *
  159. * The image is placed at the specified x and y coordinates with the
  160. * given width and height.
  161. *
  162. * @param string $img_url the path to the image
  163. * @param string $img_type the type (e.g. extension) of the image
  164. * @param float $x x position
  165. * @param float $y y position
  166. * @param int $w width (in pixels)
  167. * @param int $h height (in pixels)
  168. */
  169. function image($img_url, $img_type, $x, $y, $w, $h);
  170. /**
  171. * Writes text at the specified x and y coordinates
  172. *
  173. * See {@link Style::munge_colour()} for the format of the colour array.
  174. *
  175. * @param float $x
  176. * @param float $y
  177. * @param string $text the text to write
  178. * @param string $font the font file to use
  179. * @param float $size the font size, in points
  180. * @param array $color
  181. * @param float $adjust word spacing adjustment
  182. */
  183. function text($x, $y, $text, $font, $size, $color = array(0,0,0), $adjust = 0);
  184. /**
  185. * Add a named destination (similar to <a name="foo">...</a> in html)
  186. *
  187. * @param string $anchorname The name of the named destination
  188. */
  189. function add_named_dest($anchorname);
  190. /**
  191. * Add a link to the pdf
  192. *
  193. * @param string $url The url to link to
  194. * @param float $x The x position of the link
  195. * @param float $y The y position of the link
  196. * @param float $width The width of the link
  197. * @param float $height The height of the link
  198. */
  199. function add_link($url, $x, $y, $width, $height);
  200. /**
  201. * Calculates text size, in points
  202. *
  203. * @param string $text the text to be sized
  204. * @param string $font the desired font
  205. * @param float $size the desired font size
  206. * @param float $spacing word spacing, if any
  207. * @return float
  208. */
  209. function get_text_width($text, $font, $size, $spacing = 0);
  210. /**
  211. * Calculates font height, in points
  212. *
  213. * @param string $font
  214. * @param float $size
  215. * @return float
  216. */
  217. function get_font_height($font, $size);
  218. /**
  219. * Starts a new page
  220. *
  221. * Subsequent drawing operations will appear on the new page.
  222. */
  223. function new_page();
  224. /**
  225. * Streams the PDF directly to the browser
  226. *
  227. * @param string $filename the name of the PDF file
  228. * @param array $options associative array, 'Attachment' => 0 or 1, 'compress' => 1 or 0
  229. */
  230. function stream($filename, $options = null);
  231. /**
  232. * Returns the PDF as a string
  233. *
  234. * @param array $options associative array: 'compress' => 1 or 0
  235. * @return string
  236. */
  237. function output($options = null);
  238. }