1 /***************************************************************************
2 * Copyright (C) 2007 by Dominik Seichter *
3 * domseichter@web.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 * *
20 * In addition, as a special exception, the copyright holders give *
21 * permission to link the code of portions of this program with the *
22 * OpenSSL library under certain conditions as described in each *
23 * individual source file, and distribute linked combinations *
24 * including the two. *
25 * You must obey the GNU General Public License in all respects *
26 * for all of the code used other than OpenSSL. If you modify *
27 * file(s) with this exception, you may extend this exception to your *
28 * version of the file(s), but you are not obligated to do so. If you *
29 * do not wish to do so, delete this exception statement from your *
30 * version. If you delete this exception statement from all source *
31 * files in the program, then also delete it here. *
32 ***************************************************************************/
33
34 #ifndef _PDF_FILE_STREAM_H_
35 #define _PDF_FILE_STREAM_H_
36
37 #include "PdfDefines.h"
38
39 #include "PdfStream.h"
40
41 namespace PoDoFo {
42
43 class PdfOutputStream;
44
45 /** A PDF stream can be appended to any PdfObject
46 * and can contain arbitrary data.
47 *
48 * Most of the time it will contain either drawing commands
49 * to draw onto a page or binary data like a font or an image.
50 *
51 * A PdfFileStream writes all data directly to an output device
52 * without keeping it in memory.
53 * PdfFileStream is used automatically when creating PDF files
54 * using PdfImmediateWriter.
55 *
56 * \see PdfVecObjects
57 * \see PdfStream
58 * \see PdfMemoryStream
59 * \see PdfFileStream
60 */
61 class PODOFO_API PdfFileStream : public PdfStream {
62
63 public:
64 /** Create a new PdfFileStream object which has a parent PdfObject.
65 * The stream will be deleted along with the parent.
66 * This constructor will be called by PdfObject::Stream() for you.
67 *
68 * \param pParent parent object
69 * \param pDevice output device
70 */
71 PdfFileStream( PdfObject* pParent, PdfOutputDevice* pDevice );
72
73 virtual ~PdfFileStream();
74
75 /** Set an encryption object which is used to encrypt
76 * all data written to this stream.
77 *
78 * \param pEncrypt an encryption object or NULL if no encryption should be done
79 */
80 void SetEncrypted( PdfEncrypt* pEncrypt );
81
82 /** Write the stream to an output device
83 * \param pDevice write to this outputdevice.
84 * \param pEncrypt encrypt stream data using this object
85 */
86 virtual void Write( PdfOutputDevice* pDevice, PdfEncrypt* pEncrypt = NULL );
87
88 /** Get a malloced buffer of the current stream.
89 * No filters will be applied to the buffer, so
90 * if the stream is Flate compressed the compressed copy
91 * will be returned.
92 *
93 * The caller has to podofo_free() the buffer.
94 *
95 * This is currently not implemented for PdfFileStreams
96 * and will raise an ePdfError_InternalLogic exception
97 *
98 * \param pBuffer pointer to the buffer address (output parameter)
99 * \param lLen pointer to the buffer length (output parameter)
100 */
101 virtual void GetCopy( char** pBuffer, pdf_long* lLen ) const;
102
103 /** Get a copy of a the stream and write it to a PdfOutputStream
104 *
105 * \param pStream data is written to this stream.
106 */
107 virtual void GetCopy( PdfOutputStream* pStream ) const;
108
109 /** Get the streams length with all filters applied (eg the compressed
110 * length of a Flate compressed stream).
111 *
112 * \returns the length of the stream with all filters applied
113 */
114 inline virtual pdf_long GetLength() const;
115
116 protected:
117 /** Required for the GetFilteredCopy implementation
118 * \returns a handle to the internal buffer
119 */
120 inline virtual const char* GetInternalBuffer() const;
121
122 /** Required for the GetFilteredCopy implementation
123 * \returns the size of the internal buffer
124 */
125 inline virtual pdf_long GetInternalBufferSize() const;
126
127 /** Begin appending data to this stream.
128 * Clears the current stream contents.
129 *
130 * \param vecFilters use this filters to encode any data written to the stream.
131 */
132 virtual void BeginAppendImpl( const TVecFilters & vecFilters );
133
134 /** Append a binary buffer to the current stream contents.
135 *
136 * \param pszString a buffer
137 * \param lLen length of the buffer
138 *
139 * \see BeginAppend
140 * \see Append
141 * \see EndAppend
142 */
143 virtual void AppendImpl( const char* pszString, size_t lLen );
144
145 /** Finish appending data to the stream
146 */
147 virtual void EndAppendImpl();
148
149 private:
150 PdfOutputDevice* m_pDevice;
151 PdfOutputStream* m_pStream;
152 PdfOutputStream* m_pDeviceStream;
153 PdfOutputStream* m_pEncryptStream;
154
155 pdf_long m_lLenInitial;
156 pdf_long m_lLength;
157
158
159 PdfObject* m_pLength;
160
161 PdfEncrypt* m_pCurEncrypt;
162 };
163
164 // -----------------------------------------------------
165 //
166 // -----------------------------------------------------
GetLength()167 pdf_long PdfFileStream::GetLength() const
168 {
169 return m_lLength;
170 }
171
172 // -----------------------------------------------------
173 //
174 // -----------------------------------------------------
GetInternalBuffer()175 const char* PdfFileStream::GetInternalBuffer() const
176 {
177 return NULL;
178 }
179
180 // -----------------------------------------------------
181 //
182 // -----------------------------------------------------
GetInternalBufferSize()183 pdf_long PdfFileStream::GetInternalBufferSize() const
184 {
185 return 0;
186 }
187
188 };
189
190 #endif // _PDF_FILE_STREAM_H_
191