PoDoFo  0.9.4
Public Member Functions | Protected Member Functions | List of all members
PoDoFo::PdfFilter Class Referenceabstract

#include <PdfFilter.h>

Inheritance diagram for PoDoFo::PdfFilter:
PoDoFo::PdfAscii85Filter PoDoFo::PdfFlateFilter PoDoFo::PdfHexFilter PoDoFo::PdfLZWFilter PoDoFo::PdfRLEFilter

Public Member Functions

 PdfFilter ()
 
virtual ~PdfFilter ()
 
virtual bool CanEncode () const =0
 
void Encode (const char *pInBuffer, pdf_long lInLen, char **ppOutBuffer, pdf_long *plOutLen) const
 
void BeginEncode (PdfOutputStream *pOutput)
 
void EncodeBlock (const char *pBuffer, pdf_long lLen)
 
void EndEncode ()
 
virtual bool CanDecode () const =0
 
void Decode (const char *pInBuffer, pdf_long lInLen, char **ppOutBuffer, pdf_long *plOutLen, const PdfDictionary *pDecodeParms=NULL) const
 
void BeginDecode (PdfOutputStream *pOutput, const PdfDictionary *pDecodeParms=NULL)
 
void DecodeBlock (const char *pBuffer, pdf_long lLen)
 
void EndDecode ()
 
virtual EPdfFilter GetType () const =0
 

Protected Member Functions

PODOFO_NOTHROW void FailEncodeDecode ()
 
virtual void BeginEncodeImpl ()
 
virtual void EncodeBlockImpl (const char *pBuffer, pdf_long lLen)=0
 
virtual void EndEncodeImpl ()
 
virtual void BeginDecodeImpl (const PdfDictionary *)
 
virtual void DecodeBlockImpl (const char *pBuffer, pdf_long lLen)=0
 
virtual void EndDecodeImpl ()
 

Detailed Description

Every filter in PoDoFo has to implement this interface.

The two methods Encode() and Decode() have to be implemented for every filter.

The output buffers are podofo_malloc()'ed in the functions and have to be podofo_free()'d by the caller.

Constructor & Destructor Documentation

PoDoFo::PdfFilter::PdfFilter ( )

Construct and initialize a new filter

PoDoFo::PdfFilter::~PdfFilter ( )
inlinevirtual

All classes with virtual functions need a virtual destructor

Member Function Documentation

void PoDoFo::PdfFilter::BeginDecode ( PdfOutputStream pOutput,
const PdfDictionary pDecodeParms = NULL 
)
inline

Begin progressively decoding data using this filter.

This method sets the filter's output stream and may perform other operations defined by particular filter implementations. It calls BeginDecodeImpl().

Parameters
pOutputdecoded data will be written to this stream
pDecodeParmsa dictionary containing additional information for decoding

Call DecodeBlock() to decode blocks of data and use EndDecode() to finish the decoding process.

See also
DecodeBlock
EndDecode
virtual void PoDoFo::PdfFilter::BeginDecodeImpl ( const PdfDictionary )
inlineprotectedvirtual

Real implementation of BeginDecode(). NEVER call this method directly.

By default this function does nothing. If your filter needs to do setup for decoding, you should override this method.

PdfFilter ensures that a valid stream is available when this method is called, and that EndDecode() was called since the last BeginDecode()/ DecodeBlock().

See also
BeginDecode

Reimplemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.

void PoDoFo::PdfFilter::BeginEncode ( PdfOutputStream pOutput)
inline

Begin progressively encoding data using this filter.

This method sets the filter's output stream and may perform other operations defined by particular filter implementations. It calls BeginEncodeImpl().

Parameters
pOutputEncoded data will be written to this stream.

Call EncodeBlock() to encode blocks of data and use EndEncode() to finish the encoding process.

See also
EncodeBlock
EndEncode
virtual void PoDoFo::PdfFilter::BeginEncodeImpl ( )
inlineprotectedvirtual

Real implementation of BeginEncode(). NEVER call this method directly.

By default this function does nothing. If your filter needs to do setup for encoding, you should override this method.

PdfFilter ensures that a valid stream is available when this method is called, and that EndEncode() was called since the last BeginEncode()/ EncodeBlock().

See also
BeginEncode

Reimplemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, and PoDoFo::PdfAscii85Filter.

virtual bool PoDoFo::PdfFilter::CanDecode ( ) const
pure virtual

Check whether the decoding is implemented for this filter.

Returns
true if the filter is able to decode data

Implemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.

virtual bool PoDoFo::PdfFilter::CanEncode ( ) const
pure virtual

Check whether encoding is implemented for this filter.

Returns
true if the filter is able to encode data

Implemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.

void PoDoFo::PdfFilter::Decode ( const char *  pInBuffer,
pdf_long  lInLen,
char **  ppOutBuffer,
pdf_long *  plOutLen,
const PdfDictionary pDecodeParms = NULL 
) const

Decodes a buffer using a filter. The buffer will podofo_malloc()'d and has to be podofo_free()'d by the caller.

Parameters
pInBufferinput buffer
lInLenlength of the input buffer
ppOutBufferreceives pointer to the buffer of the decoded data
plOutLenpointer to where to write the output buffer's length
pDecodeParmsoptional pointer to a decode-parameters dictionary containing additional information to decode the data. This pointer must be NULL if no decode-parameters dictionary is available.
void PoDoFo::PdfFilter::DecodeBlock ( const char *  pBuffer,
pdf_long  lLen 
)
inline

Decode a block of data and write it to the PdfOutputStream specified by BeginDecode(). Ownership of the block is not taken and remains with the caller.

The filter implementation need not immediately process the buffer, and might internally buffer some or all of it. However, if it does this the buffer's contents will be copied, so it is guaranteed to be safe to free the passed buffer after this call returns.

This method is a wrapper around DecodeBlockImpl().

BeginDecode() must be called before this function.

Parameters
pBufferpointer to a buffer with data to encode
lLenlength of data to encode.

Call EndDecode() after all data has been decoded.

See also
BeginDecode
EndDecode
virtual void PoDoFo::PdfFilter::DecodeBlockImpl ( const char *  pBuffer,
pdf_long  lLen 
)
protectedpure virtual

Real implementation of DecodeBlock(). NEVER call this method directly.

You must method-override it to decode the buffer passed by the caller.

You are not obliged to immediately process any or all of the data in the passed buffer, but you must ensure that you have processed it and written it out by the end of EndDecodeImpl(). You must copy the buffer if you're going to store it, as ownership is not transferred to the filter and the caller may free the buffer at any time.

PdfFilter ensures that a valid stream is available when this method is called, ensures that BeginDecode() has been called, and ensures that EndDecode() has not been called since the last BeginDecode().

See also
DecodeBlock

Implemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.

void PoDoFo::PdfFilter::Encode ( const char *  pInBuffer,
pdf_long  lInLen,
char **  ppOutBuffer,
pdf_long *  plOutLen 
) const

Encodes a buffer using a filter. The buffer will podofo_malloc()'d and has to be podofo_free()'d by the caller.

This function uses BeginEncode()/EncodeBlock()/EndEncode() internally, so it's not safe to use when progressive encoding is in progress.

Parameters
pInBufferinput buffer
lInLenlength of the input buffer
ppOutBufferreceives pointer to the buffer of the encoded data
plOutLenpointer to where to write the output buffer's length
void PoDoFo::PdfFilter::EncodeBlock ( const char *  pBuffer,
pdf_long  lLen 
)
inline

Encode a block of data and write it to the PdfOutputStream specified by BeginEncode(). Ownership of the block is not taken and remains with the caller.

The filter implementation need not immediately process the buffer, and might internally buffer some or all of it. However, if it does this the buffer's contents will be copied, so it is guaranteed to be safe to free the passed buffer after this call returns.

This method is a wrapper around EncodeBlockImpl().

BeginEncode() must be called before this function.

Parameters
pBufferpointer to a buffer with data to encode
lLenlength of data to encode.

Call EndEncode() after all data has been encoded.

See also
BeginEncode
EndEncode
virtual void PoDoFo::PdfFilter::EncodeBlockImpl ( const char *  pBuffer,
pdf_long  lLen 
)
protectedpure virtual

Real implementation of EncodeBlock(). NEVER call this method directly.

You must method-override it to encode the buffer passed by the caller.

You are not obliged to immediately process any or all of the data in the passed buffer, but you must ensure that you have processed it and written it out by the end of EndEncodeImpl(). You must copy the buffer if you're going to store it, as ownership is not transferred to the filter and the caller may free the buffer at any time.

PdfFilter ensures that a valid stream is available when this method is called, ensures that BeginEncode() has been called, and ensures that EndEncode() has not been called since the last BeginEncode().

See also
EncodeBlock

Implemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.

void PoDoFo::PdfFilter::EndDecode ( )
inline

Finish decoding of data and reset the stream's state.

See also
BeginDecode
DecodeBlock
virtual void PoDoFo::PdfFilter::EndDecodeImpl ( )
inlineprotectedvirtual

Real implementation of EndDecode(). NEVER call this method directly.

By the time this method returns, all filtered data must be written to the stream and the filter must be in a state where BeginDecode() can be safely called. PdfFilter ensures that a valid stream is available when this method is called, and ensures that BeginDecodeImpl() has been called.

See also
EndDecode

Reimplemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.

void PoDoFo::PdfFilter::EndEncode ( )
inline

Finish encoding of data and reset the stream's state.

See also
BeginEncode
EncodeBlock
virtual void PoDoFo::PdfFilter::EndEncodeImpl ( )
inlineprotectedvirtual

Real implementation of EndEncode(). NEVER call this method directly.

By the time this method returns, all filtered data must be written to the stream and the filter must be in a state where BeginEncode() can be safely called. PdfFilter ensures that a valid stream is available when this method is called, and ensures that BeginEncodeImpl() has been called.

See also
EndEncode

Reimplemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, and PoDoFo::PdfAscii85Filter.

void PoDoFo::PdfFilter::FailEncodeDecode ( )
inlineprotected

Indicate that the filter has failed, and will be non-functional until BeginEncode() or BeginDecode() is next called. Call this instead of EndEncode() or EndDecode if something went wrong. It clears the stream output but otherwise does nothing.

After this method is called further calls to EncodeBlock(), DecodeBlock(), EndDecode() and EndEncode() before the next BeginEncode() or BeginDecode() are guaranteed to throw without calling their virtual implementations.

virtual EPdfFilter PoDoFo::PdfFilter::GetType ( ) const
pure virtual

Type of this filter.

Returns
the type of this filter

Implemented in PoDoFo::PdfLZWFilter, PoDoFo::PdfRLEFilter, PoDoFo::PdfFlateFilter, PoDoFo::PdfAscii85Filter, and PoDoFo::PdfHexFilter.