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.

114 lines
3.0 KiB

11 years ago
10 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: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /** Internally used classes */
  22. // require_once 'Zend/Pdf/Element/Object.php';
  23. // require_once 'Zend/Pdf/Element/Dictionary.php';
  24. // require_once 'Zend/Pdf/Element/Name.php';
  25. // require_once 'Zend/Pdf/Element/Numeric.php';
  26. /** Zend_Pdf_Resource */
  27. // require_once 'Zend/Pdf/Resource.php';
  28. /**
  29. * Content stream (drawing instructions container)
  30. *
  31. * @package Zend_Pdf
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Pdf_Resource_ContentStream extends Zend_Pdf_Resource
  36. {
  37. /**
  38. * Buffered content
  39. *
  40. * @var string
  41. */
  42. protected $_bufferedContent = '';
  43. /**
  44. * Object constructor.
  45. *
  46. * @param Zend_Pdf_Element_Object_Stream|string $contentStreamObject
  47. * @throws Zend_Pdf_Exception
  48. */
  49. public function __construct($contentStreamObject = '')
  50. {
  51. if ($contentStreamObject !== null &&
  52. !$contentStreamObject instanceof Zend_Pdf_Element_Object_Stream &&
  53. !is_string($contentStreamObject)
  54. ) {
  55. // require_once 'Zend/Pdf/Exception.php';
  56. throw new Zend_Pdf_Exception('Content stream parameter must be a string or stream object');
  57. }
  58. parent::__construct($contentStreamObject);
  59. }
  60. /**
  61. * Appends instructions to the end of the content stream
  62. *
  63. * @param string $instructions
  64. * @return Zend_Pdf_Resource_ContentStream
  65. */
  66. public function addInstructions($instructions)
  67. {
  68. $this->_bufferedContent .= $instructions;
  69. return $this;
  70. }
  71. /**
  72. * Get current stream content
  73. *
  74. * @return string
  75. */
  76. public function getInstructions()
  77. {
  78. $this->flush();
  79. return $this->_resource->value;
  80. }
  81. /**
  82. * Clear stream content.
  83. *
  84. * @return Zend_Pdf_Resource_ContentStream
  85. */
  86. public function clear()
  87. {
  88. $this->_resource->value = '';
  89. $this->_bufferedContent = '';
  90. return $this;
  91. }
  92. /**
  93. * Flush buffered content
  94. */
  95. public function flush()
  96. {
  97. $this->_resource->value .= $this->_bufferedContent;
  98. $this->_bufferedContent = '';
  99. return $this;
  100. }
  101. }