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