pdfobjects::CStream Class Reference

#include <cstream.h>

Inheritance diagram for pdfobjects::CStream:
pdfobjects::IProperty observer::ObserverHandler< T > pdfobjects::CInlineImage

List of all members.

Public Types

typedef char StreamChar
typedef std::vector< StreamCharBuffer
typedef
observer::BasicChangeContext
< IProperty
BasicObserverContext

Public Member Functions

 CStream (boost::weak_ptr< CPdf > p, const Object &o, const IndiRef &rf)
 CStream (const Object &o)
 CStream (const CDict &dict)
 CStream (bool makeReqEntries=true)
size_t getPropertyCount () const
template<typename Container >
void getAllPropertyNames (Container &container) const
boost::shared_ptr< IPropertygetProperty (PropertyId id) const
bool containsProperty (PropertyId id) const
PropertyType getPropertyType (PropertyId id) const
boost::shared_ptr< IPropertysetProperty (PropertyId id, IProperty &ip)
boost::shared_ptr< IPropertyaddProperty (PropertyId id, const IProperty &newIp)
void delProperty (PropertyId id)
virtual PropertyType getType () const
virtual void getStringRepresentation (std::string &str) const
virtual void getDecodedStringRepresentation (std::string &str) const
const BuffergetBuffer () const
template<typename Container >
void getFilters (Container &container) const
virtual void setPdf (boost::weak_ptr< CPdf > pdf)
virtual void setIndiRef (const IndiRef &rf)
void setRawBuffer (const Buffer &buf)
template<typename Container >
void setBuffer (const Container &buf)
 ~CStream ()
virtual Object * _makeXpdfObject () const
template<typename Storage >
void _getAllChildObjects (Storage &store) const

Static Public Attributes

static const PropertyType type = pStream

Protected Member Functions

virtual IPropertydoClone () const
virtual CStream_newInstance () const
void createReqEntries ()

Protected Attributes

CDict dictionary
Buffer buffer
::Parser * parser
mutable::Object curObj

Private Types

typedef std::string PropertyId

Private Member Functions

void open ()
void close ()
void getXpdfObject (::Object &obj)
::Stream * getXpdfStream ()
bool eof () const
void _objectChanged (boost::shared_ptr< const ObserverContext > context)
size_t getLength () const
void setLength (size_t len)
ObserverContext_createContext () const

Private Attributes

::Object * tmpObj

Friends

class CStreamsXpdfReader

Detailed Description

Class representing stream object from pdf specification v1.5.

We do not want to use xpdf stream because it is a real mess and it is really not suitable for editing. We use xpdf object just for initializing and for reading objects.

According to pdf specification, stream is a dictionary and a stream of characters of specified length. Dictionary is used to describe the stream (its length, filters, parameters, etc..)

This class does not provide default copy constructor because copying a property could be understood either as deep copy or shallow copy. Copying complex types could be very expensive so we have made the decision to avoid it.


Member Typedef Documentation

typedef std::string pdfobjects::CStream::PropertyId [private]

Constructor & Destructor Documentation

pdfobjects::CStream::CStream ( boost::weak_ptr< CPdf p,
const Object &  o,
const IndiRef rf 
)

Constructor. Stream will be associated with specified pdf.

Parameters:
p Pointer to pdf object.
o Xpdf object.
rf Indirect id and gen id.

Referenced by _newInstance().

pdfobjects::CStream::CStream ( const Object &  o  ) 

Constructor. Stream will not be associated with a pdf.

Parameters:
o Xpdf object.
pdfobjects::CStream::CStream ( const CDict dict  ) 

Constructor. Stream will not be associated with a pdf.

Parameters:
dict reference to a dictionary which will be associated with this stream
buffer reference to buffer associtated with this stream

References debug::DBG_DBG, and kernelPrintDbg.

pdfobjects::CStream::CStream ( bool  makeReqEntries = true  ) 

Public constructor. This object will not be associated with a pdf. It adds all required properties to object dictionary in compliance with the pdf specification if needed.

Parameters:
makeReqEntries If true required entries are added to the stream dictionary.

References createReqEntries(), debug::DBG_DBG, and kernelPrintDbg.

pdfobjects::CStream::~CStream (  ) 

Member Function Documentation

IProperty::ObserverContext * pdfobjects::CStream::_createContext (  )  const [private]

Create context of a change.

REMARK: Be carefull. Deallocate the object.

Returns:
Context in which a change occured.

Referenced by setBuffer(), and setRawBuffer().

template<typename Storage >
void pdfobjects::CStream::_getAllChildObjects ( Storage &  store  )  const [inline]

Return all child objects.

Parameters:
store Container of objects.

References dictionary, and pdfobjects::CDict::value.

Object * pdfobjects::CStream::_makeXpdfObject (  )  const [virtual]

Make xpdf Object from this object. This function allocates and initializes xpdf object. Caller has to deallocate the xpdf Object.

Returns:
Xpdf object representin this object.
Exceptions:
ObjBadValueE Thrown when xpdf can't parse the string representation of this object correctly.

Implements pdfobjects::IProperty.

Reimplemented in pdfobjects::CInlineImage.

References buffer, debug::DBG_DBG, debug::DBG_WARN, getLength(), kernelPrintDbg, and pdfobjects::utils::xpdfStreamObjFromBuffer().

Referenced by open().

virtual CStream* pdfobjects::CStream::_newInstance (  )  const [inline, protected, virtual]

Return new instance.

Reimplemented in pdfobjects::CInlineImage.

References CStream().

Referenced by doClone().

void pdfobjects::CStream::_objectChanged ( boost::shared_ptr< const ObserverContext context  )  [private]

Indicate that the object has changed. Notifies all observers associated with this property about the change.

Parameters:
context Context in which a change occured.

Referenced by setBuffer(), and setRawBuffer().

boost::shared_ptr<IProperty> pdfobjects::CStream::addProperty ( PropertyId  id,
const IProperty newIp 
) [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References pdfobjects::CDict::addProperty(), and dictionary.

void pdfobjects::CStream::close (  )  [private]
bool pdfobjects::CStream::containsProperty ( PropertyId  id  )  const [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References pdfobjects::CDict::containsProperty(), and dictionary.

Referenced by gui::QSStream::exist().

void pdfobjects::CStream::createReqEntries (  )  [protected]

Create required entries.

Referenced by CStream().

void pdfobjects::CStream::delProperty ( PropertyId  id  )  [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References pdfobjects::CDict::delProperty(), and dictionary.

IProperty * pdfobjects::CStream::doClone (  )  const [protected, virtual]

Implementation of clone method.

Returns:
Deep copy of this object.

Implements pdfobjects::IProperty.

References _newInstance(), buffer, pdfobjects::IProperty::clone(), debug::DBG_DBG, dictionary, kernelPrintDbg, parser, and pdfobjects::CDict::value.

bool pdfobjects::CStream::eof (  )  const [private]

Is the last object end of stream.

This is not very common behaviour, but we can not use caching

See also:
getXpdfObject so we can tell if it is the end after fetching an object which means after calling getXpdfObject.
Returns:
True if we no more data avaliable, false otherwise.

References curObj, and parser.

Referenced by getXpdfObject().

template<typename Container >
void pdfobjects::CStream::getAllPropertyNames ( Container &  container  )  const [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References dictionary, and pdfobjects::CDict::getAllPropertyNames().

Referenced by gui::TreeItemCStream::getChildNames(), and gui::QSStream::propertyNames().

const Buffer& pdfobjects::CStream::getBuffer (  )  const [inline]

Get encoded buffer. Can contain non printable characters.

Returns:
Buffer.

References buffer.

Referenced by gui::QSStream::getBuffer(), gui::QSStream::getBufferString(), and gui::QSStream::saveBuffer().

virtual void pdfobjects::CStream::getDecodedStringRepresentation ( std::string &  str  )  const [virtual]

Returns decoded string representation of this object.

Parameters:
str Output string representation.
template<typename Container >
void pdfobjects::CStream::getFilters ( Container &  container  )  const [inline]

Get filters.

Parameters:
container Container of filter names.

References debug::DBG_DBG, dictionary, pdfobjects::CDict::getProperty(), pdfobjects::isArray(), pdfobjects::isName(), and kernelPrintDbg.

Referenced by setBuffer().

size_t pdfobjects::CStream::getLength (  )  const [private]

Get length.

Returns:
Stream length.

References pdfobjects::utils::getReferencedObject(), and pdfobjects::isInt().

Referenced by _makeXpdfObject().

boost::shared_ptr<IProperty> pdfobjects::CStream::getProperty ( PropertyId  id  )  const [inline]
size_t pdfobjects::CStream::getPropertyCount (  )  const [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References dictionary, and pdfobjects::CDict::getPropertyCount().

Referenced by gui::QSStream::count(), and gui::TreeItemCStream::haveChild().

PropertyType pdfobjects::CStream::getPropertyType ( PropertyId  id  )  const [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References dictionary, and pdfobjects::CDict::getPropertyType().

virtual void pdfobjects::CStream::getStringRepresentation ( std::string &  str  )  const [virtual]

Returns string representation of this object.

Parameters:
str Output string representation.

Implements pdfobjects::IProperty.

Reimplemented in pdfobjects::CInlineImage.

virtual PropertyType pdfobjects::CStream::getType (  )  const [inline, virtual]

Returns type of object.

Returns:
Type of this class.

Implements pdfobjects::IProperty.

References pdfobjects::pStream.

void pdfobjects::CStream::getXpdfObject ( ::Object &  obj  )  [private]

Get next xpdf object from the stream.

REMARK: We can not do any buffering (caching) of xpdf objects, because xpdf already does caching and it will NOT work correctly with inline images. We would buffer WRONG data.

Parameters:
obj Next xpdf object.

References curObj, debug::DBG_ERR, eof(), kernelPrintDbg, and parser.

Stream * pdfobjects::CStream::getXpdfStream (  )  [private]

Get xpdf stream. Be carefull this is not a copy.

Returns:
Stream.

References debug::DBG_DBG, kernelPrintDbg, and parser.

void pdfobjects::CStream::open (  )  [private]

Initialize parsing mechanism.

REMARK: if CObject is not in a pdf, we MUST be sure that it does not use indirect objects.

References _makeXpdfObject(), curObj, debug::DBG_DBG, xpdf::freeXpdfObject(), pdfobjects::IProperty::getPdf(), kernelPrintDbg, parser, and tmpObj.

template<typename Container >
void pdfobjects::CStream::setBuffer ( const Container &  buf  )  [inline]

Set decoded (raw) buffer. Drops all filters if present.

Parameters:
buf New buffer (can be string or Buffer types).

References _createContext(), _objectChanged(), buffer, pdfobjects::IProperty::canChange(), debug::DBG_DBG, pdfobjects::CDict::delProperty(), dictionary, getFilters(), kernelPrintDbg, pdfobjects::utils::makeStreamPdfValid(), parser, and setLength().

void pdfobjects::CStream::setIndiRef ( const IndiRef rf  )  [virtual]

Set ref to itself and also to all children.

Parameters:
rf New indirect reference numbers.

Reimplemented from pdfobjects::IProperty.

Referenced by pdfobjects::CInlineImage::CInlineImage().

void pdfobjects::CStream::setLength ( size_t  len  )  [private]

Set length.

Parameters:
len Stream Length.

Referenced by setBuffer(), and setRawBuffer().

void pdfobjects::CStream::setPdf ( boost::weak_ptr< CPdf pdf  )  [virtual]

Set pdf to itself and also to all children.

Parameters:
pdf New pdf.

Reimplemented from pdfobjects::IProperty.

Referenced by pdfobjects::CInlineImage::CInlineImage().

boost::shared_ptr<IProperty> pdfobjects::CStream::setProperty ( PropertyId  id,
IProperty ip 
) [inline]

Delagate this operation to underlying dictionary.

See also:
CDict

References dictionary, and pdfobjects::CDict::setProperty().

void pdfobjects::CStream::setRawBuffer ( const Buffer buf  ) 

Set encoded buffer.

Parameters:
buf New buffer.

References _createContext(), _objectChanged(), buffer, pdfobjects::IProperty::canChange(), parser, and setLength().


Friends And Related Function Documentation

friend class CStreamsXpdfReader [friend]

Member Data Documentation

mutable ::Object pdfobjects::CStream::curObj [protected]

Current object in an opened stream.

Referenced by close(), eof(), getXpdfObject(), open(), and ~CStream().

::Parser* pdfobjects::CStream::parser [protected]
::Object* pdfobjects::CStream::tmpObj [private]

Helper object, because xpdf stream does NOT automatically deallocated specified object.

Referenced by close(), open(), and ~CStream().

const PropertyType pdfobjects::CStream::type = pStream [static]

Type of this property object. This association allows us to get the PropertyType from object type.


The documentation for this class was generated from the following files: