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.

165 lines
5.5 KiB

11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * PDF file Resource abstraction
  23. *
  24. * @package Zend_Pdf
  25. * @copyright Copyright (c) 2005-2015 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_Resource
  29. {
  30. /**
  31. * Each Pdf resource (fonts, images, ...) interacts with a PDF itself.
  32. * It creates appropriate PDF objects, structures and sometime embedded files.
  33. * Resources are referenced in content streams by names, which are stored in
  34. * a page resource dictionaries.
  35. *
  36. * Thus, resources must be attached to the PDF.
  37. *
  38. * Resource abstraction uses own PDF object factory to store all necessary information.
  39. * At the render time internal object factory is appended to the global PDF file
  40. * factory.
  41. *
  42. * Resource abstraction also cashes information about rendered PDF files and
  43. * doesn't duplicate resource description each time then Resource is rendered
  44. * (referenced).
  45. *
  46. * @var Zend_Pdf_ElementFactory_Interface
  47. */
  48. protected $_objectFactory;
  49. /**
  50. * Main resource object
  51. *
  52. * @var Zend_Pdf_Element_Object
  53. */
  54. protected $_resource;
  55. /**
  56. * Object constructor.
  57. *
  58. * If resource is not a Zend_Pdf_Element object, then stream object with specified value is
  59. * generated.
  60. *
  61. * @param Zend_Pdf_Element|string $resource
  62. */
  63. public function __construct($resource)
  64. {
  65. if ($resource instanceof Zend_Pdf_Element_Object) {
  66. $this->_objectFactory = $resource->getFactory();
  67. $this->_resource = $resource;
  68. return;
  69. }
  70. // require_once 'Zend/Pdf/ElementFactory.php';
  71. $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
  72. if ($resource instanceof Zend_Pdf_Element) {
  73. $this->_resource = $this->_objectFactory->newObject($resource);
  74. } else {
  75. $this->_resource = $this->_objectFactory->newStreamObject($resource);
  76. }
  77. }
  78. /**
  79. * Clone page, extract it and dependent objects from the current document,
  80. * so it can be used within other docs.
  81. */
  82. public function __clone()
  83. {
  84. /** @todo implementation*/
  85. // $factory = Zend_Pdf_ElementFactory::createFactory(1);
  86. // $processed = array();
  87. //
  88. // // Clone dictionary object.
  89. // // Do it explicitly to prevent sharing resource attributes between different
  90. // // results of clone operation (other resources are still shared)
  91. // $dictionary = new Zend_Pdf_Element_Dictionary();
  92. // foreach ($this->_pageDictionary->getKeys() as $key) {
  93. // $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
  94. // $processed,
  95. // Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
  96. // }
  97. //
  98. // $this->_pageDictionary = $factory->newObject($dictionary);
  99. // $this->_objectFactory = $factory;
  100. // $this->_attached = false;
  101. // $this->_style = null;
  102. // $this->_font = null;
  103. }
  104. /**
  105. * Clone resource, extract it and dependent objects from the current document,
  106. * so it can be used within other docs.
  107. *
  108. * @internal
  109. * @param Zend_Pdf_ElementFactory_Interface $factory
  110. * @param array $processed
  111. * @return Zend_Pdf_Page
  112. */
  113. public function cloneResource($factory, &$processed)
  114. {
  115. /** @todo implementation*/
  116. // // Clone dictionary object.
  117. // // Do it explicitly to prevent sharing page attributes between different
  118. // // results of clonePage() operation (other resources are still shared)
  119. // $dictionary = new Zend_Pdf_Element_Dictionary();
  120. // foreach ($this->_pageDictionary->getKeys() as $key) {
  121. // $dictionary->$key = $this->_pageDictionary->$key->makeClone($factory->getFactory(),
  122. // $processed,
  123. // Zend_Pdf_Element::CLONE_MODE_SKIP_PAGES);
  124. // }
  125. //
  126. // $clonedPage = new Zend_Pdf_Page($factory->newObject($dictionary), $factory);
  127. // $clonedPage->_attached = false;
  128. //
  129. // return $clonedPage;
  130. }
  131. /**
  132. * Get resource.
  133. * Used to reference resource in an internal PDF data structures (resource dictionaries)
  134. *
  135. * @internal
  136. * @return Zend_Pdf_Element_Object
  137. */
  138. public function getResource()
  139. {
  140. return $this->_resource;
  141. }
  142. /**
  143. * Get factory.
  144. *
  145. * @internal
  146. * @return Zend_Pdf_ElementFactory_Interface
  147. */
  148. public function getFactory()
  149. {
  150. return $this->_objectFactory;
  151. }
  152. }