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