pdfmm 0.9.20
Public Member Functions | Protected Member Functions | List of all members
mm::PdfMemStream Class Referencefinal

#include <PdfMemStream.h>

Inheritance diagram for mm::PdfMemStream:
mm::PdfStream

Public Member Functions

 PdfMemStream (PdfObject &parent)
 
void Write (PdfOutputDevice &device, const PdfEncrypt *encrypt) override
 
void GetCopy (std::unique_ptr< char[]> &buffer, size_t &len) const override
 
void GetCopy (PdfOutputStream &stream) const override
 
size_t GetLength () const override
 
const char * Get () const
 
- Public Member Functions inherited from mm::PdfStream
virtual void Write (PdfOutputDevice &device, const PdfEncrypt *encrypt)=0
 
void Set (const std::string_view &view, const PdfFilterList &filters)
 
void Set (const char *buffer, size_t len, const PdfFilterList &filters)
 
void Set (const std::string_view &view)
 
void Set (const char *buffer, size_t len)
 
void Set (PdfInputStream &stream)
 
void Set (PdfInputStream &stream, const PdfFilterList &filters)
 
void SetRawData (PdfInputStream &stream, ssize_t len=-1)
 
void BeginAppend (bool clearExisting=true)
 
void BeginAppend (const PdfFilterList &filters, bool clearExisting=true, bool deleteFilters=true)
 
PdfStreamAppend (const std::string_view &view)
 
PdfStreamAppend (const char *buffer, size_t len)
 
void EndAppend ()
 
bool IsAppending () const
 
virtual size_t GetLength () const =0
 
virtual void GetCopy (std::unique_ptr< char[]> &buffer, size_t &len) const =0
 
virtual void GetCopy (PdfOutputStream &stream) const =0
 
void GetFilteredCopy (std::unique_ptr< char[]> &buffer, size_t &len) const
 
void GetFilteredCopy (PdfOutputStream &stream) const
 
const PdfStreamoperator= (const PdfStream &rhs)
 

Protected Member Functions

const char * GetInternalBuffer () const override
 
size_t GetInternalBufferSize () const override
 
void BeginAppendImpl (const PdfFilterList &filters) override
 
void AppendImpl (const char *data, size_t len) override
 
void EndAppendImpl () override
 
- Protected Member Functions inherited from mm::PdfStream
 PdfStream (PdfObject &parent)
 
virtual const char * GetInternalBuffer () const =0
 
virtual size_t GetInternalBufferSize () const =0
 
virtual void BeginAppendImpl (const PdfFilterList &filters)=0
 
virtual void AppendImpl (const char *data, size_t len)=0
 
virtual void EndAppendImpl ()=0
 

Additional Inherited Members

- Static Public Attributes inherited from mm::PdfStream
static enum PdfFilterType DefaultFilter
 

Detailed Description

A PDF stream can be appended to any PdfObject and can contain arbitrary data.

A PDF memory stream is held completely in memory.

Most of the time it will contain either drawing commands to draw onto a page or binary data like a font or an image.

A PdfMemStream is implicitly shared and can therefore be copied very quickly.

Constructor & Destructor Documentation

◆ PdfMemStream()

PdfMemStream::PdfMemStream ( PdfObject parent)

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.

Parameters
parentparent object

Member Function Documentation

◆ AppendImpl()

void PdfMemStream::AppendImpl ( const char *  data,
size_t  len 
)
overrideprotectedvirtual

Append a binary buffer to the current stream contents.

Parameters
dataa buffer
lenlength of the buffer
See also
BeginAppend
Append
EndAppend

Implements mm::PdfStream.

◆ BeginAppendImpl()

void PdfMemStream::BeginAppendImpl ( const PdfFilterList &  filters)
overrideprotectedvirtual

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.

Parameters
filtersuse these filters to encode any data written to the stream.

Implements mm::PdfStream.

◆ EndAppendImpl()

void PdfMemStream::EndAppendImpl ( )
overrideprotectedvirtual

Finish appending data to the stream

Implements mm::PdfStream.

◆ Get()

const char * PdfMemStream::Get ( ) const

Get a read-only handle to the current stream data. The data will not be filtered before being returned, so (eg) calling Get() on a Flate compressed stream will return a pointer to the Flate-compressed buffer.

Warning
Do not retain pointers to the stream's internal buffer, as it may be reallocated with any non-const operation.
Returns
a read-only handle to the streams data

◆ GetCopy() [1/2]

void PdfMemStream::GetCopy ( PdfOutputStream stream) const
overridevirtual

Get a copy of a the stream and write it to a PdfOutputStream

Parameters
streamdata is written to this stream.

Implements mm::PdfStream.

◆ GetCopy() [2/2]

void mm::PdfMemStream::GetCopy ( std::unique_ptr< char[]> &  buffer,
size_t &  len 
) const
overridevirtual

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 the buffer.

Parameters
bufferpointer to the buffer
lenpointer to the buffer length

Implements mm::PdfStream.

◆ GetInternalBuffer()

const char * PdfMemStream::GetInternalBuffer ( ) const
overrideprotectedvirtual

Required for the GetFilteredCopy() implementation

Returns
a handle to the internal buffer

Implements mm::PdfStream.

◆ GetInternalBufferSize()

size_t PdfMemStream::GetInternalBufferSize ( ) const
overrideprotectedvirtual

Required for the GetFilteredCopy() implementation

Returns
the size of the internal buffer

Implements mm::PdfStream.

◆ GetLength()

size_t PdfMemStream::GetLength ( ) const
overridevirtual

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

Implements mm::PdfStream.

◆ Write()

void PdfMemStream::Write ( PdfOutputDevice device,
const PdfEncrypt encrypt 
)
overridevirtual

Write the stream to an output device

Parameters
devicewrite to this outputdevice.
encryptencrypt stream data using this object

Implements mm::PdfStream.