/usr/include/podofo/base/PdfStream.h is in libpodofo-dev 0.9.5-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | /***************************************************************************
* Copyright (C) 2005 by Dominik Seichter *
* domseichter@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* In addition, as a special exception, the copyright holders give *
* permission to link the code of portions of this program with the *
* OpenSSL library under certain conditions as described in each *
* individual source file, and distribute linked combinations *
* including the two. *
* You must obey the GNU General Public License in all respects *
* for all of the code used other than OpenSSL. If you modify *
* file(s) with this exception, you may extend this exception to your *
* version of the file(s), but you are not obligated to do so. If you *
* do not wish to do so, delete this exception statement from your *
* version. If you delete this exception statement from all source *
* files in the program, then also delete it here. *
***************************************************************************/
#ifndef _PDF_STREAM_H_
#define _PDF_STREAM_H_
#include "PdfDefines.h"
#include "PdfDictionary.h"
#include "PdfFilter.h"
#include "PdfRefCountedBuffer.h"
#include <string.h>
namespace PoDoFo {
class PdfInputStream;
class PdfName;
class PdfObject;
class PdfOutputStream;
/** A PDF stream can be appended to any PdfObject
* and can contain arbitrary data.
*
* Most of the time it will contain either drawing commands
* to draw onto a page or binary data like a font or an image.
*
* You have to use a concrete implementation of a stream,
* which can be retrieved from a StreamFactory.
* \see PdfVecObjects
* \see PdfMemoryStream
* \see PdfFileStream
*/
class PODOFO_API PdfStream {
public:
/** The default filter to use when changing the stream content.
* It's a static member and applies to all newly created/changed streams.
* The default value is ePdfFilter_FlateDecode.
*/
static enum EPdfFilter eDefaultFilter;
/** Create a new PdfStream object which has a parent PdfObject.
* The stream will be deleted along with the parent.
* This constructor will be called by PdfObject::Stream() for you.
* \param pParent parent object
*/
PdfStream( PdfObject* pParent );
virtual ~PdfStream();
/** Write the stream to an output device
* \param pDevice write to this outputdevice.
* \param pEncrypt encrypt stream data using this object
*/
virtual void Write( PdfOutputDevice* pDevice, PdfEncrypt* pEncrypt = NULL ) = 0;
/** Set a binary buffer as stream data.
*
* Use PdfFilterFactory::CreateFilterList() if you want to use the contents
* of the stream dictionary's existing filter key.
*
* \param szBuffer buffer containing the stream data
* \param lLen length of the buffer
* \param vecFilters a list of filters to use when appending data
*/
void Set( const char* szBuffer, pdf_long lLen, const TVecFilters & vecFilters );
/** Set a binary buffer as stream data.
* All data will be Flate-encoded.
*
* \param szBuffer buffer containing the stream data
* \param lLen length of the buffer
*/
void Set( const char* szBuffer, pdf_long lLen );
/** Set a binary buffer whose contents are read from a PdfInputStream
* All data will be Flate-encoded.
*
* \param pStream read stream contents from this PdfInputStream
*/
void Set( PdfInputStream* pStream );
/** Set a binary buffer whose contents are read from a PdfInputStream
*
* Use PdfFilterFactory::CreateFilterList() if you want to use the contents
* of the stream dictionary's existing filter key.
*
* \param pStream read stream contents from this PdfInputStream
* \param vecFilters a list of filters to use when appending data
*/
void Set( PdfInputStream* pStream, const TVecFilters & vecFilters );
/** Set a null-terminated char* buffer as the stream's contents.
*
* The string will be copied into a newly allocated buffer.
* \param pszString a zero terminated string buffer containing only
* ASCII text data
*/
inline void Set( const char* pszString );
/** Sets raw data for this stream which is read from an input stream.
* This method does neither encode nor decode the read data.
* The filters of the object are not modified and the data is expected
* encoded as stated by the /Filters key in the stream's object.
*
* \param pStream read data from this input stream
* \param lLen read exactly lLen bytes from the input stream,
* if lLen = -1 read until the end of the input stream
* was reached.
*/
void SetRawData( PdfInputStream* pStream, pdf_long lLen = -1 );
/** Start appending data to this stream.
*
* This method has to be called before any of the append methods.
* All appended data will be Flate-encoded.
*
* \param bClearExisting if true any existing stream contents will
* be cleared.
*
* \see Append
* \see EndAppend
* \see eDefaultFilter
*/
void BeginAppend( bool bClearExisting = true );
/** Start appending data to this stream.
* This method has to be called before any of the append methods.
*
* Use PdfFilterFactory::CreateFilterList() if you want to use the contents
* of the stream dictionary's existing filter key.
*
* \param vecFilters a list of filters to use when appending data
* \param bClearExisting if true any existing stream contents will
be cleared.
* \param bDeleteFilters if true existing filter keys are deleted if an
* empty list of filters is passed (required for SetRawData())
*
* \see Append
* \see EndAppend
*/
void BeginAppend( const TVecFilters & vecFilters, bool bClearExisting = true, bool bDeleteFilters = true );
/** Append a binary buffer to the current stream contents.
*
* Make sure BeginAppend() has been called before.
*
* \param pszString a buffer
* \param lLen length of the buffer
*
* \see BeginAppend
* \see EndAppend
*/
inline void Append( const char* pszString, size_t lLen );
/** Append a null-terminated string to the current stream contents.
*
* Make sure BeginAppend() has been called before.
*
* \param pszString a zero-terminated string buffer containing only
* ASCII text data
*
* \see BeginAppend
* \see EndAppend
*/
inline void Append( const char* pszString );
/** Append to the current stream contents.
*
* Make sure BeginAppend() has been called before.
*
* \param sString a std::string containing only ASCII text data
*
* \see BeginAppend
* \see EndAppend
*/
inline void Append( const std::string& sString );
/** Finish appending data to this stream.
* BeginAppend() has to be called before this method.
*
* \see BeginAppend
* \see Append
*/
void EndAppend();
/**
* \returns true if code is between BeginAppend()
* and EndAppend() at the moment, i.e. it
* is safe to call EndAppend() now.
*
* \see BeginAppend
* \see Append
*/
inline bool IsAppending() const;
/** Get the stream's length with all filters applied (e.g. if the stream is
* Flate-compressed, the length of the compressed data stream).
*
* \returns the length of the internal buffer
*/
virtual pdf_long GetLength() const = 0;
/** Get a malloc()'d buffer of the current stream.
* No filters will be applied to the buffer, so
* if the stream is Flate-compressed the compressed copy
* will be returned.
*
* The caller has to podofo_free() the buffer.
*
* \param pBuffer pointer to the buffer
* \param lLen pointer to the buffer length
*/
virtual void GetCopy( char** pBuffer, pdf_long* lLen ) const = 0;
/** Get a copy of a the stream and write it to a PdfOutputStream
*
* \param pStream data is written to this stream.
*/
virtual void GetCopy( PdfOutputStream* pStream ) const = 0;
/** Get a malloc()'d buffer of the current stream which has been
* filtered by all filters as specified in the dictionary's
* /Filter key. For example, if the stream is Flate-compressed,
* the buffer returned from this method will have been decompressed.
*
* The caller has to podofo_free() the buffer.
*
* \param pBuffer pointer to the buffer
* \param lLen pointer to the buffer length
*/
void GetFilteredCopy( char** pBuffer, pdf_long* lLen ) const;
/** Get a filtered copy of a the stream and write it to a PdfOutputStream
*
* \param pStream filtered data is written to this stream.
*/
void GetFilteredCopy( PdfOutputStream* pStream ) const;
/** Create a copy of a PdfStream object
* \param rhs the object to clone
* \returns a reference to this object
*/
const PdfStream & operator=( const PdfStream & rhs );
protected:
/** Required for the GetFilteredCopy() implementation
* \returns a handle to the internal buffer
*/
virtual const char* GetInternalBuffer() const = 0;
/** Required for the GetFilteredCopy() implementation
* \returns the size of the internal buffer
*/
virtual pdf_long GetInternalBufferSize() const = 0;
/** Begin appending data to this stream.
* Clears the current stream contents.
*
* Use PdfFilterFactory::CreateFilterList() if you want to use the contents
* of the stream dictionary's existing filter key.
*
* \param vecFilters use these filters to encode any data written
* to the stream.
*/
virtual void BeginAppendImpl( const TVecFilters & vecFilters ) = 0;
/** Append a binary buffer to the current stream contents.
*
* \param pszString a buffer
* \param lLen length of the buffer
*
* \see BeginAppend
* \see Append
* \see EndAppend
*/
virtual void AppendImpl( const char* pszString, size_t lLen ) = 0;
/** Finish appending data to the stream
*/
virtual void EndAppendImpl() = 0;
protected:
PdfObject* m_pParent;
bool m_bAppend;
};
// -----------------------------------------------------
//
// -----------------------------------------------------
void PdfStream::Set( const char* pszString )
{
if( pszString )
Set( const_cast<char*>(pszString), strlen( pszString ) );
}
// -----------------------------------------------------
//
// -----------------------------------------------------
void PdfStream::Append( const char* pszString, size_t lLen )
{
PODOFO_RAISE_LOGIC_IF( !m_bAppend, "Append() failed because BeginAppend() was not yet called!" );
this->AppendImpl( pszString, lLen );
}
// -----------------------------------------------------
//
// -----------------------------------------------------
void PdfStream::Append( const char* pszString )
{
if( pszString )
Append( pszString, strlen( pszString ) );
}
// -----------------------------------------------------
//
// -----------------------------------------------------
void PdfStream::Append( const std::string& sString )
{
Append( sString.c_str(), sString.length() );
}
// -----------------------------------------------------
//
// -----------------------------------------------------
bool PdfStream::IsAppending() const
{
return m_bAppend;
}
};
#endif // _PDF_STREAM_H_
|