pdfobjects::CContentStream Class Reference

#include <ccontentstream.h>

Inheritance diagram for pdfobjects::CContentStream:
observer::ObserverHandler< T >

List of all members.

Classes

struct  CStreamObserver
struct  OperandObserver

Public Types

typedef std::list
< boost::shared_ptr
< PdfOperator > > 
Operators
typedef std::list
< boost::shared_ptr< CStream > > 
CStreams
typedef PdfOperator::Iterator OperatorIterator
typedef
observer::BasicChangeContext
< CContentStream
BasicObserverContext

Public Member Functions

 CContentStream (CStreams &strs, boost::shared_ptr< GfxState > state, boost::shared_ptr< GfxResources > res)
template<typename Cont >
void getCStreams (Cont &cont) const
template<typename Iter >
void getStringRepresentation (std::string &str) const
void getStringRepresentation (std::string &str) const
template<typename OpContainer , typename PdfOpPosComparator >
void getOperatorsAtPosition (OpContainer &opContainer, const PdfOpPosComparator &cmp) const
template<typename T >
void getPdfOperators (T &container) const
void deleteOperator (OperatorIterator it, bool indicateChange=true)
void deleteOperator (boost::shared_ptr< PdfOperator > oper, bool indicateChange=true)
void insertOperator (OperatorIterator it, boost::shared_ptr< PdfOperator > newOper, bool indicateChange=true)
void insertOperator (boost::shared_ptr< PdfOperator > oper, boost::shared_ptr< PdfOperator > newOper, bool indicateChange=true)
void frontInsertOperator (boost::shared_ptr< PdfOperator > newOper, bool indicateChange=true)
void replaceOperator (OperatorIterator it, boost::shared_ptr< PdfOperator > newOper, bool indicateChange=true)
void replaceOperator (boost::shared_ptr< PdfOperator > oper, boost::shared_ptr< PdfOperator > newOper, bool indicateChange=true)
bool empty () const
void reparse (bool bboxOnly=false, boost::shared_ptr< GfxState > state=boost::shared_ptr< GfxState >(), boost::shared_ptr< GfxResources > res=boost::shared_ptr< GfxResources >())
void setGfxParams (boost::shared_ptr< GfxState > state, boost::shared_ptr< GfxResources > res)
boost::shared_ptr< GfxResources > getResources () const
void saveChange ()
boost::shared_ptr< CContentStreamgetSmartPointer () const
void setSmartPointer (boost::shared_ptr< CContentStream > ths)
void replaceText (const std::string &what, const std::string &with)
 ~CContentStream ()

Protected Member Functions

void registerCStreamObservers () const
void unregisterCStreamObservers () const

Private Member Functions

void _objectChanged ()

Private Attributes

CStreams cstreams
Operators operators
boost::shared_ptr< GfxState > gfxstate
boost::shared_ptr< GfxResources > gfxres
boost::weak_ptr< CContentStreamsmart_this
boost::shared_ptr
< CStreamObserver
cstreamobserver
boost::shared_ptr
< OperandObserver
operandobserver

Detailed Description

Content stream class representing pdf content stream.

This object represents operators and operands of a content stream. Each content stream consists of one or more indirect streams. These streams are listed in "Contents" entry of page dictionary.

Each operator represents an operation that alters the current graphic state. These operators are processed sequentially. We cannot parse only one stream when the content stream consists of more streams, because the split point is almost arbitrary. Every content stream class represents a valid content which can consist of one or more streams.

During initialization of this object, observers are registred on all underlying streams, which means a change to the stream object(s) representing the content stream will transparently update this object. This feature could be tricky. (E.g. Content stream consists of more streams and we need to save the content stream, which means changing streams one after another. After a change the content stream becomes invalid.)

Operators form a tree-like structure consisting of Simple and Composite objects.

Only first level operators are stored.

The pdf feature that a content stream can consist of several streams means we can not derive from CStream object. Due to this limitation we do not have Observer interface so we need to implement it.

Mainly this object is responsible for all visible objects on a page. If a content stream is empty, the page is empty. Changing operators can be very destructive (e.g. text matrix, font type, deleting one operator of a pair, ...)

The requirement of processing operators sequentially has lead to the decision that these operators will be in an iterator queue meaning we can process them seqeuntially with the advantage of Iterator design pattern.

Another characteristis of content stream operators is that they build a tree like structure which has lead to another decision that these operators will be in a tree like queue. It means operators are designed as a Composite design pattern. This enables e.g. gui to represent content stream in a human readable from)


Member Typedef Documentation

typedef std::list<boost::shared_ptr<CStream> > pdfobjects::CContentStream::CStreams
typedef std::list<boost::shared_ptr<PdfOperator> > pdfobjects::CContentStream::Operators

Constructor & Destructor Documentation

pdfobjects::CContentStream::CContentStream ( CStreams strs,
boost::shared_ptr< GfxState >  state,
boost::shared_ptr< GfxResources >  res 
)

Constructor.

Parameters:
strs Array of content streams. Typically only one.
state Graphical state.
res Graphical resources.

References cstreamobserver, cstreams, debug::DBG_DBG, pdfobjects::PdfOperator::getIterator(), gfxres, gfxstate, pdfobjects::hasValidPdf(), pdfobjects::hasValidRef(), kernelPrintDbg, operandobserver, registerCStreamObservers(), and pdfobjects::StateUpdater::updatePdfOperators().

pdfobjects::CContentStream::~CContentStream (  )  [inline]

Member Function Documentation

void pdfobjects::CContentStream::_objectChanged (  )  [private]
void pdfobjects::CContentStream::deleteOperator ( boost::shared_ptr< PdfOperator oper,
bool  indicateChange = true 
) [inline]

References deleteOperator().

Referenced by deleteOperator().

void pdfobjects::CContentStream::deleteOperator ( OperatorIterator  it,
bool  indicateChange = true 
)

Delete an operator from a content stream.

We have to remove an operator from the iterator queue and also from the tree queue.

When removing from the tree queue an operator we have to find it and remove from the composite it is in (if not first level)

Needs to be careful when removing from the iterator queue. If a composite is removed we have to update its top level operator and also the last item of the iterator queue that is still in the composite.

Parameters:
it Iterator pointing to operator that will be deleted.
indicateChange If true, changed contentstream will be written to its cstreams, otherwise the change will not be visible.

References _objectChanged(), cstreams, debug::DBG_DBG, pdfobjects::findCompositeOfPdfOperator(), iterator::DoubleListIterator< Item >::getCurrent(), pdfobjects::PdfOperator::getIterator(), pdfobjects::getLastOperator(), iterator::DoubleListIterator< Item >::isBegin(), iterator::DoubleListIterator< Item >::isEnd(), kernelPrintDbg, and iterator::DoubleListIterator< Item >::prev().

bool pdfobjects::CContentStream::empty (  )  const [inline]

Is the content stream empty.

Returns:
True if the contentstream is empty, false otherwise.
void pdfobjects::CContentStream::frontInsertOperator ( boost::shared_ptr< PdfOperator newOper,
bool  indicateChange = true 
)

Insert pdf operator in the front.

Parameters:
newOper Operator that will be inserted.
indicateChange If true, changed contentstream will be written to its cstreams, otherwise the change will not be visible.

References _objectChanged(), cstreams, pdfobjects::getLastOperator(), pdfobjects::hasValidPdf(), pdfobjects::hasValidRef(), and operandobserver.

template<typename Cont >
void pdfobjects::CContentStream::getCStreams ( Cont &  cont  )  const [inline]

Get all cstreams from which this content stream is made of.

References cstreams.

template<typename OpContainer , typename PdfOpPosComparator >
void pdfobjects::CContentStream::getOperatorsAtPosition ( OpContainer &  opContainer,
const PdfOpPosComparator &  cmp 
) const [inline]

Get objects at position.

We can compute a bounding box (rectangle) to every operator specifying its exact position. This bounding box is used to select specific operators.

Parameters:
opContainer Output container.
cmp Comparator that will decide if an operator is close enough.

References debug::DBG_DBG, iterator::DoubleListIterator< Item >::getCurrent(), getStringRepresentation(), iterator::DoubleListIterator< Item >::isEnd(), iterator::DoubleListIterator< Item >::next(), operators, and utilsPrintDbg.

template<typename T >
void pdfobjects::CContentStream::getPdfOperators ( T &  container  )  const [inline]

Get first level pdf operators.

Operators form a tree-like structure. We store all root operands in a container.

Parameters:
container Output container.

References operators.

boost::shared_ptr<GfxResources> pdfobjects::CContentStream::getResources (  )  const [inline]

Returns resources used by this content stream.

Returns:
Resources instance wrapped by shared pointer.

References gfxres.

boost::shared_ptr<CContentStream> pdfobjects::CContentStream::getSmartPointer (  )  const [inline]

Get smart pointer to this content stream.

Returns:
Smart pointer to this content stream.

References smart_this.

Referenced by pdfobjects::PdfOperator::getContentStream().

void pdfobjects::CContentStream::getStringRepresentation ( std::string &  str  )  const [inline]

Get the string representation of the content stream.

Parameters:
str Output string.

References debug::DBG_DBG, operators, and utilsPrintDbg.

template<typename Iter >
void pdfobjects::CContentStream::getStringRepresentation ( std::string &  str  )  const [inline]

Get the string representation of specific operators.

Traverse all operators using specific iterator and save their string repersentation.

REMARK: If an iterator accepts composite objects and also simple objects and if an accepted composite contains one accepted simple object, the string representation will be incorrect. It will contain the string represenation of the composite including the child and also a separate string representation of the child.

Parameters:
str Output string.

References debug::DBG_DBG, kernelPrintDbg, and operators.

Referenced by _objectChanged(), and getOperatorsAtPosition().

void pdfobjects::CContentStream::insertOperator ( boost::shared_ptr< PdfOperator oper,
boost::shared_ptr< PdfOperator newOper,
bool  indicateChange = true 
) [inline]
See also:
insertOperator

References insertOperator().

Referenced by insertOperator().

void pdfobjects::CContentStream::insertOperator ( OperatorIterator  it,
boost::shared_ptr< PdfOperator newOper,
bool  indicateChange = true 
)

Insert pdf operator after specified position. If it is not valid it is assumend that the content stream is empty and operator will be inserted at the beginning.

We have to insert the operator into the iterator queue and also into the tree queue.

Insertion has to take the depth of the position into account.

Parameters:
it Iterator pointing to operator after which the new operator will be inserted.
newOper Operator that will be inserted.
indicateChange If true, changed contentstream will be written to its cstreams, otherwise the change will not be visible.

References _objectChanged(), cstreams, debug::DBG_DBG, pdfobjects::findCompositeOfPdfOperator(), iterator::DoubleListIterator< Item >::getCurrent(), pdfobjects::PdfOperator::getIterator(), pdfobjects::getLastOperator(), pdfobjects::hasValidPdf(), pdfobjects::hasValidRef(), iterator::DoubleListIterator< Item >::isEnd(), kernelPrintDbg, iterator::DoubleListIterator< Item >::next(), operandobserver, and iterator::DoubleListIterator< Item >::valid().

void pdfobjects::CContentStream::registerCStreamObservers (  )  const [protected]

Register observers on all cstreams that this object consists of.

This function is called in constructor and also after saving to more cstreams.

References cstreamobserver, cstreams, and REGISTER_SHAREDPTR_OBSERVER.

Referenced by _objectChanged(), and CContentStream().

void pdfobjects::CContentStream::reparse ( bool  bboxOnly = false,
boost::shared_ptr< GfxState >  state = boost::shared_ptr<GfxState> (),
boost::shared_ptr< GfxResources >  res = boost::shared_ptr<GfxResources> () 
)

Reparse pdf operators and set their bounding boxes.

Parameters:
bboxOnly If true only bounding boxes are set, if false operators are also reparsed.
state Graphical state, if changed.
res Graphical resources, if changed.

References cstreams, pdfobjects::PdfOperator::getIterator(), gfxres, gfxstate, operandobserver, and pdfobjects::StateUpdater::updatePdfOperators().

Referenced by _objectChanged(), and pdfobjects::CContentStream::CStreamObserver::notify().

void pdfobjects::CContentStream::replaceOperator ( boost::shared_ptr< PdfOperator oper,
boost::shared_ptr< PdfOperator newOper,
bool  indicateChange = true 
) [inline]

References replaceOperator().

Referenced by replaceOperator().

void pdfobjects::CContentStream::replaceOperator ( OperatorIterator  it,
boost::shared_ptr< PdfOperator newOper,
bool  indicateChange = true 
)

Replace an operator with another one.

We have to modify both iterator queue and tree queue.

This can be a problem. When replacing an operator with another operator which contains the same instance of the original operator (meaning the new operator is a composite) we can not use iterator queue of the original, because it was altered when inserting it into the new operator and points to items in the new operator.

All change functions behave this way. They insert the original operator in a new composite altering the iterator queue and making the content stream iterator queue invalid. That is why we need the next and previous items of the original operator as function arguments.

Parameters:
it Iterator pointing to the element that will be replaced.
newOper New operator.
indicateChange If true, changed contentstream will be written to its cstreams, otherwise the change will not be visible.

References _objectChanged(), cstreams, debug::DBG_DBG, pdfobjects::findCompositeOfPdfOperator(), iterator::DoubleListIterator< Item >::getCurrent(), pdfobjects::PdfOperator::getIterator(), pdfobjects::getLastOperator(), pdfobjects::hasValidPdf(), pdfobjects::hasValidRef(), iterator::DoubleListIterator< Item >::isEnd(), kernelPrintDbg, operandobserver, and iterator::DoubleListIterator< Item >::prev().

void pdfobjects::CContentStream::replaceText ( const std::string &  what,
const std::string &  with 
)
void pdfobjects::CContentStream::saveChange (  )  [inline]

Save content stream to underlying cstream(s) and notify all observers.

Does not reparse anything.

References _objectChanged().

Referenced by pdfobjects::CContentStream::OperandObserver::notify().

void pdfobjects::CContentStream::setGfxParams ( boost::shared_ptr< GfxState >  state,
boost::shared_ptr< GfxResources >  res 
) [inline]

Set gfx resources.

References gfxres, and gfxstate.

void pdfobjects::CContentStream::setSmartPointer ( boost::shared_ptr< CContentStream ths  )  [inline]

Set smart pointer to this content stream.

Parameters:
ths Smart pointer to this content stream.

References smart_this.

void pdfobjects::CContentStream::unregisterCStreamObservers (  )  const [protected]

Unregister observers from all cstreams that this object consists of.

This function is called when saving consten stream consisting of more streams. If we do not unregister observers, we would be notified that a stream has changed after the first save (when the content stream is invalid) and our observer would want to reparse an invalid stream.

References cstreamobserver, cstreams, and UNREGISTER_SHAREDPTR_OBSERVER.

Referenced by _objectChanged(), and ~CContentStream().


Member Data Documentation

Observer observing underlying cstreams.

Referenced by CContentStream(), registerCStreamObservers(), and unregisterCStreamObservers().

boost::shared_ptr<GfxResources> pdfobjects::CContentStream::gfxres [private]

Graphical resources.

Referenced by CContentStream(), getResources(), reparse(), and setGfxParams().

boost::shared_ptr<GfxState> pdfobjects::CContentStream::gfxstate [private]

Graphical state.

Referenced by CContentStream(), reparse(), and setGfxParams().

Observer observing operands of all operators.

Referenced by CContentStream(), frontInsertOperator(), insertOperator(), reparse(), replaceOperator(), and replaceText().

Parsed first level content stream operators.

Referenced by getOperatorsAtPosition(), getPdfOperators(), and getStringRepresentation().

Smart pointer to this object.

Referenced by getSmartPointer(), and setSmartPointer().


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