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.

130 lines
3.0 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. /** Internally used classes */
  22. // require_once 'Zend/Pdf.php';
  23. /** Zend_Pdf_Element */
  24. // require_once 'Zend/Pdf/Element.php';
  25. /**
  26. * PDF file 'stream' element implementation
  27. *
  28. * @category Zend
  29. * @package Zend_Pdf
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Pdf_Element_Stream extends Zend_Pdf_Element
  34. {
  35. /**
  36. * Object value
  37. *
  38. * @var Zend_Memory_Container
  39. */
  40. public $value;
  41. /**
  42. * Object constructor
  43. *
  44. * @param string $val
  45. */
  46. public function __construct($val)
  47. {
  48. $this->value = Zend_Pdf::getMemoryManager()->create($val);
  49. }
  50. /**
  51. * Return type of the element.
  52. *
  53. * @return integer
  54. */
  55. public function getType()
  56. {
  57. return Zend_Pdf_Element::TYPE_STREAM;
  58. }
  59. /**
  60. * Stream length.
  61. * (Method is used to avoid string copying, which may occurs in some cases)
  62. *
  63. * @return integer
  64. */
  65. public function length()
  66. {
  67. return strlen($this->value->getRef());
  68. }
  69. /**
  70. * Clear stream
  71. *
  72. */
  73. public function clear()
  74. {
  75. $ref = &$this->value->getRef();
  76. $ref = '';
  77. $this->value->touch();
  78. }
  79. /**
  80. * Append value to a stream
  81. *
  82. * @param mixed $val
  83. */
  84. public function append($val)
  85. {
  86. $ref = &$this->value->getRef();
  87. $ref .= (string)$val;
  88. $this->value->touch();
  89. }
  90. /**
  91. * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
  92. *
  93. * @param Zend_Pdf_ElementFactory $factory The factory to attach
  94. * @param array &$processed List of already processed indirect objects, used to avoid objects duplication
  95. * @param integer $mode Cloning mode (defines filter for objects cloning)
  96. * @returns Zend_Pdf_Element
  97. */
  98. public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
  99. {
  100. return new self($this->value->getRef());
  101. }
  102. /**
  103. * Return object as string
  104. *
  105. * @param Zend_Pdf_Factory $factory
  106. * @return string
  107. */
  108. public function toString($factory = null)
  109. {
  110. return "stream\n" . $this->value->getRef() . "\nendstream";
  111. }
  112. }