PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/app/library/Zend/Pdf/Element.php

https://github.com/Zefiryn/graduationprojects
PHP | 176 lines | 71 code | 17 blank | 88 comment | 10 complexity | 8bfa031ea8a2b19da19aac0f7059c334 MD5 | raw file
  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Element.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * PDF file element implementation
  23. *
  24. * @package Zend_Pdf
  25. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. abstract class Zend_Pdf_Element
  29. {
  30. const TYPE_BOOL = 1;
  31. const TYPE_NUMERIC = 2;
  32. const TYPE_STRING = 3;
  33. const TYPE_NAME = 4;
  34. const TYPE_ARRAY = 5;
  35. const TYPE_DICTIONARY = 6;
  36. const TYPE_STREAM = 7;
  37. const TYPE_NULL = 11;
  38. /**
  39. * Reference to the top level indirect object, which contains this element.
  40. *
  41. * @var Zend_Pdf_Element_Object
  42. */
  43. private $_parentObject = null;
  44. /**
  45. * Return type of the element.
  46. * See ZPdfPDFConst for possible values
  47. *
  48. * @return integer
  49. */
  50. abstract public function getType();
  51. /**
  52. * Convert element to a string, which can be directly
  53. * written to a PDF file.
  54. *
  55. * $factory parameter defines operation context.
  56. *
  57. * @param Zend_Pdf_Factory $factory
  58. * @return string
  59. */
  60. abstract public function toString($factory = null);
  61. const CLONE_MODE_SKIP_PAGES = 1; // Do not follow pages during deep copy process
  62. const CLONE_MODE_FORCE_CLONING = 2; // Force top level object cloning even it's already processed
  63. /**
  64. * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
  65. *
  66. * @todo It's nevessry to check if SplObjectStorage class works faster
  67. * (Needs PHP 5.3.x to attach object _with_ additional data to storage)
  68. *
  69. * @param Zend_Pdf_ElementFactory $factory The factory to attach
  70. * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
  71. * @param integer $mode Cloning mode (defines filter for objects cloning)
  72. * @returns Zend_Pdf_Element
  73. */
  74. public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
  75. {
  76. return clone $this;
  77. }
  78. /**
  79. * Set top level parent indirect object.
  80. *
  81. * @param Zend_Pdf_Element_Object $parent
  82. */
  83. public function setParentObject(Zend_Pdf_Element_Object $parent)
  84. {
  85. $this->_parentObject = $parent;
  86. }
  87. /**
  88. * Get top level parent indirect object.
  89. *
  90. * @return Zend_Pdf_Element_Object
  91. */
  92. public function getParentObject()
  93. {
  94. return $this->_parentObject;
  95. }
  96. /**
  97. * Mark object as modified, to include it into new PDF file segment.
  98. *
  99. * We don't automate this action to keep control on PDF update process.
  100. * All new objects are treated as "modified" automatically.
  101. */
  102. public function touch()
  103. {
  104. if ($this->_parentObject !== null) {
  105. $this->_parentObject->touch();
  106. }
  107. }
  108. /**
  109. * Clean up resources, used by object
  110. */
  111. public function cleanUp()
  112. {
  113. // Do nothing
  114. }
  115. /**
  116. * Convert PDF element to PHP type.
  117. *
  118. * @return mixed
  119. */
  120. public function toPhp()
  121. {
  122. return $this->value;
  123. }
  124. /**
  125. * Convert PHP value into PDF element.
  126. *
  127. * @param mixed $input
  128. * @return Zend_Pdf_Element
  129. */
  130. public static function phpToPdf($input)
  131. {
  132. if (is_numeric($input)) {
  133. require_once 'Zend/Pdf/Element/Numeric.php';
  134. return new Zend_Pdf_Element_Numeric($input);
  135. } else if (is_bool($input)) {
  136. require_once 'Zend/Pdf/Element/Boolean.php';
  137. return new Zend_Pdf_Element_Boolean($input);
  138. } else if (is_array($input)) {
  139. $pdfElementsArray = array();
  140. $isDictionary = false;
  141. foreach ($input as $key => $value) {
  142. if (is_string($key)) {
  143. $isDictionary = true;
  144. }
  145. $pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value);
  146. }
  147. if ($isDictionary) {
  148. require_once 'Zend/Pdf/Element/Dictionary.php';
  149. return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
  150. } else {
  151. require_once 'Zend/Pdf/Element/Array.php';
  152. return new Zend_Pdf_Element_Array($pdfElementsArray);
  153. }
  154. } else {
  155. require_once 'Zend/Pdf/Element/String.php';
  156. return new Zend_Pdf_Element_String((string)$input);
  157. }
  158. }
  159. }