File indexing completed on 2025-01-19 05:21:23

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
0020  */
0021 
0022 
0023 /** Internally used classes */
0024 // require_once 'Zend/Pdf/Element/Object.php';
0025 // require_once 'Zend/Pdf/Element/Dictionary.php';
0026 // require_once 'Zend/Pdf/Element/Name.php';
0027 // require_once 'Zend/Pdf/Element/Numeric.php';
0028 
0029 
0030 /** Zend_Pdf_Resource */
0031 // require_once 'Zend/Pdf/Resource.php';
0032 
0033 
0034 /**
0035  * Content stream (drawing instructions container)
0036  *
0037  * @package    Zend_Pdf
0038  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0039  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0040  */
0041 class Zend_Pdf_Resource_ContentStream extends Zend_Pdf_Resource
0042 {
0043     /**
0044      * Buffered content
0045      *
0046      * @var string
0047      */
0048     protected $_bufferedContent = '';
0049 
0050     /**
0051      * Object constructor.
0052      *
0053      * @param Zend_Pdf_Element_Object_Stream|string $contentStreamObject
0054      * @throws Zend_Pdf_Exception
0055      */
0056     public function __construct($contentStreamObject = '')
0057     {
0058         if ($contentStreamObject !== null &&
0059             !$contentStreamObject instanceof Zend_Pdf_Element_Object_Stream &&
0060             !is_string($contentStreamObject)
0061         ) {
0062             // require_once 'Zend/Pdf/Exception.php';
0063             throw new Zend_Pdf_Exception('Content stream parameter must be a string or stream object');
0064         }
0065 
0066         parent::__construct($contentStreamObject);
0067     }
0068 
0069     /**
0070      * Appends instructions to the end of the content stream
0071      *
0072      * @param string $instructions
0073      * @return Zend_Pdf_Resource_ContentStream
0074      */
0075     public function addInstructions($instructions)
0076     {
0077         $this->_bufferedContent .= $instructions;
0078         return $this;
0079     }
0080 
0081     /**
0082      * Get current stream content
0083      *
0084      * @return string
0085      */
0086     public function getInstructions()
0087     {
0088         $this->flush();
0089         return $this->_resource->value;
0090     }
0091 
0092     /**
0093      * Clear stream content.
0094      *
0095      * @return Zend_Pdf_Resource_ContentStream
0096      */
0097     public function clear()
0098     {
0099         $this->_resource->value = '';
0100         $this->_bufferedContent = '';
0101         return $this;
0102     }
0103 
0104     /**
0105      * Flush buffered content
0106      */
0107     public function flush()
0108     {
0109         $this->_resource->value .= $this->_bufferedContent;
0110         $this->_bufferedContent = '';
0111 
0112         return $this;
0113     }
0114 }