2
0

Resource.php 3.1 KB

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