Resource.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /**
  22. * PDF file Resource abstraction
  23. *
  24. * @package Zend_Pdf
  25. * @copyright Copyright (c) 2005-2009 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. require_once 'Zend/Pdf/ElementFactory.php';
  66. $this->_objectFactory = Zend_Pdf_ElementFactory::createFactory(1);
  67. if ($resource instanceof Zend_Pdf_Element) {
  68. $this->_resource = $this->_objectFactory->newObject($resource);
  69. } else {
  70. $this->_resource = $this->_objectFactory->newStreamObject($resource);
  71. }
  72. }
  73. /**
  74. * Get resource.
  75. * Used to reference resource in an internal PDF data structures (resource dictionaries)
  76. *
  77. * @internal
  78. * @return Zend_Pdf_Element_Object
  79. */
  80. public function getResource()
  81. {
  82. return $this->_resource;
  83. }
  84. /**
  85. * Get factory.
  86. *
  87. * @internal
  88. * @return Zend_Pdf_ElementFactory_Interface
  89. */
  90. public function getFactory()
  91. {
  92. return $this->_objectFactory;
  93. }
  94. }