PageRenderTime 130ms CodeModel.GetById 29ms RepoModel.GetById 7ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/library/Zend/Pdf/Element/Object.php

http://firephp.googlecode.com/
PHP | 250 lines | 96 code | 33 blank | 121 comment | 8 complexity | f7e532baf69e0d3a27c3ee8e923c7012 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /** Zend_Pdf_Element */
  21. require_once 'Zend/Pdf/Element.php';
  22. /** Zend_Pdf_ElementFactory */
  23. require_once 'Zend/Pdf/ElementFactory.php';
  24. /**
  25. * PDF file 'indirect object' element implementation
  26. *
  27. * @category Zend
  28. * @package Zend_Pdf
  29. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Pdf_Element_Object extends Zend_Pdf_Element
  33. {
  34. /**
  35. * Object value
  36. *
  37. * @var Zend_Pdf_Element
  38. */
  39. protected $_value;
  40. /**
  41. * Object number within PDF file
  42. *
  43. * @var integer
  44. */
  45. protected $_objNum;
  46. /**
  47. * Generation number
  48. *
  49. * @var integer
  50. */
  51. protected $_genNum;
  52. /**
  53. * Reference to the factory.
  54. *
  55. * @var Zend_Pdf_ElementFactory
  56. */
  57. protected $_factory;
  58. /**
  59. * Object constructor
  60. *
  61. * @param Zend_Pdf_Element $val
  62. * @param integer $objNum
  63. * @param integer $genNum
  64. * @param Zend_Pdf_ElementFactory $factory
  65. * @throws Zend_Pdf_Exception
  66. */
  67. public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory)
  68. {
  69. if ($val instanceof self) {
  70. throw new Zend_Pdf_Exception('Object number must not be instance of Zend_Pdf_Element_Object.');
  71. }
  72. if ( !(is_integer($objNum) && $objNum > 0) ) {
  73. throw new Zend_Pdf_Exception('Object number must be positive integer.');
  74. }
  75. if ( !(is_integer($genNum) && $genNum >= 0) ) {
  76. throw new Zend_Pdf_Exception('Generation number must be non-negative integer.');
  77. }
  78. $this->_value = $val;
  79. $this->_objNum = $objNum;
  80. $this->_genNum = $genNum;
  81. $this->_factory = $factory;
  82. $factory->registerObject($this);
  83. }
  84. /**
  85. * Check, that object is generated by specified factory
  86. *
  87. * @return Zend_Pdf_ElementFactory
  88. */
  89. public function getFactory()
  90. {
  91. return $this->_factory;
  92. }
  93. /**
  94. * Return type of the element.
  95. *
  96. * @return integer
  97. */
  98. public function getType()
  99. {
  100. return $this->_value->getType();
  101. }
  102. /**
  103. * Get object number
  104. *
  105. * @return integer
  106. */
  107. public function getObjNum()
  108. {
  109. return $this->_objNum;
  110. }
  111. /**
  112. * Get generation number
  113. *
  114. * @return integer
  115. */
  116. public function getGenNum()
  117. {
  118. return $this->_genNum;
  119. }
  120. /**
  121. * Return reference to the object
  122. *
  123. * @param Zend_Pdf_Factory $factory
  124. * @return string
  125. */
  126. public function toString($factory = null)
  127. {
  128. if ($factory === null) {
  129. $shift = 0;
  130. } else {
  131. $shift = $factory->getEnumerationShift($this->_factory);
  132. }
  133. return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
  134. }
  135. /**
  136. * Dump object to a string to save within PDF file.
  137. *
  138. * $factory parameter defines operation context.
  139. *
  140. * @param Zend_Pdf_ElementFactory $factory
  141. * @return string
  142. */
  143. public function dump(Zend_Pdf_ElementFactory $factory)
  144. {
  145. $shift = $factory->getEnumerationShift($this->_factory);
  146. return $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
  147. . $this->_value->toString($factory) . "\n"
  148. . "endobj\n";
  149. }
  150. /**
  151. * Get handler
  152. *
  153. * @param string $property
  154. * @return mixed
  155. */
  156. public function __get($property)
  157. {
  158. return $this->_value->$property;
  159. }
  160. /**
  161. * Set handler
  162. *
  163. * @param string $property
  164. * @param mixed $value
  165. */
  166. public function __set($property, $value)
  167. {
  168. $this->_value->$property = $value;
  169. }
  170. /**
  171. * Call handler
  172. *
  173. * @param string $method
  174. * @param array $args
  175. * @return mixed
  176. */
  177. public function __call($method, $args)
  178. {
  179. switch (count($args)) {
  180. case 0:
  181. return $this->_value->$method();
  182. case 1:
  183. return $this->_value->$method($args[0]);
  184. case 2:
  185. return $this->_value->$method($args[0], $args[1]);
  186. case 3:
  187. return $this->_value->$method($args[0], $args[1], $args[2]);
  188. case 4:
  189. return $this->_value->$method($args[0], $args[1], $args[2], $args[3]);
  190. default:
  191. throw new Zend_Pdf_Exception('Unsupported number of arguments');
  192. }
  193. }
  194. /**
  195. * Mark object as modified, to include it into new PDF file segment
  196. */
  197. public function touch()
  198. {
  199. $this->_factory->markAsModified($this);
  200. }
  201. /**
  202. * Clean up resources, used by object
  203. */
  204. public function cleanUp()
  205. {
  206. $this->_value = null;
  207. }
  208. /**
  209. * Convert PDF element to PHP type.
  210. *
  211. * @return mixed
  212. */
  213. public function toPhp()
  214. {
  215. return $this->_value->toPhp();
  216. }
  217. }