2
0

Resource.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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-2009 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. /** Zend_Pdf_ElementFactory */
  22. require_once 'Zend/Pdf/ElementFactory.php';
  23. /** Zend_Pdf_Element_Object */
  24. require_once 'Zend/Pdf/Element/Object.php';
  25. /** Zend_Pdf_Element_Dictionary */
  26. require_once 'Zend/Pdf/Element/Dictionary.php';
  27. /**
  28. * PDF file Resource abstraction
  29. *
  30. * @package Zend_Pdf
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. abstract class Zend_Pdf_Resource
  35. {
  36. /**
  37. * Each Pdf resource (fonts, images, ...) interacts with a PDF itself.
  38. * It creates appropriate PDF objects, structures and sometime embedded files.
  39. * Resources are referenced in content streams by names, which are stored in
  40. * a page resource dictionaries.
  41. *
  42. * Thus, resources must be attached to the PDF.
  43. *
  44. * Resource abstraction uses own PDF object factory to store all necessary information.
  45. * At the render time internal object factory is appended to the global PDF file
  46. * factory.
  47. *
  48. * Resource abstraction also cashes information about rendered PDF files and
  49. * doesn't duplicate resource description each time then Resource is rendered
  50. * (referenced).
  51. *
  52. * @var Zend_Pdf_ElementFactory_Interface
  53. */
  54. protected $_objectFactory;
  55. /**
  56. * Main resource object
  57. *
  58. * @var Zend_Pdf_Element_Object
  59. */
  60. protected $_resource;
  61. /**
  62. * Object constructor.
  63. *
  64. * If resource is not a Zend_Pdf_Element object, then stream object with specified value is
  65. * generated.
  66. *
  67. * @param Zend_Pdf_Element|string $resource
  68. */
  69. public function __construct($resource)
  70. {
  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. * Get resource.
  80. * Used to reference resource in an internal PDF data structures (resource dictionaries)
  81. *
  82. * @internal
  83. * @return Zend_Pdf_Element_Object
  84. */
  85. public function getResource()
  86. {
  87. return $this->_resource;
  88. }
  89. /**
  90. * Get factory.
  91. *
  92. * @internal
  93. * @return Zend_Pdf_ElementFactory_Interface
  94. */
  95. public function getFactory()
  96. {
  97. return $this->_objectFactory;
  98. }
  99. }