pdfedit  0.4.5
About: PDFedit is a free and open source library for manipulating PDF documents.
  Fossies Dox: pdfedit-0.4.5.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pdfobjects::utils Namespace Reference

Classes

class  IAnnotInitializator
 
class  UniversalAnnotInitializer
 
class  TextAnnotInitializer
 
class  LinkAnnotInitializer
 
class  PropertyEquals
 
class  IdCollector
 
class  IndComparator
 
class  Delinearizator
 
class  Flattener
 
struct  OperationStep
 
struct  OperationScope
 
class  IProgressBar
 
class  ProgressObserver
 
class  FilterStreamWriter
 
class  NullFilterStreamWriter
 
class  ZlibFilterStreamWriter
 
class  IPdfWriter
 
class  OldStylePdfWriter
 
struct  FileStreamData
 
class  FileStreamDataDeleter
 
class  PdfDocumentWriter
 

Typedefs

typedef unsigned char *(* stream_data_extractor )(const Object &obj, size_t &size)
 
typedef observer::IObserver
< OperationStep
PdfWriterObserver
 

Enumerations

enum  PageTreeNodeType {
  ErrorNode, UnknownNode, LeafNode, InterNode,
  RootNode
}
 

Functions

CAnnotation::AnnotType annotTypeMapping (const std::string &typeName)
 
template<PropertyType Tp, typename T >
void complexValueFromXpdfObj (IProperty &ip, const ::Object &obj, T val)
 
template<typename T >
void complexValueToString (const typename T::Value &val, std::string &str)
 
template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType getSimpleValueFromArray (const boost::shared_ptr< CArray > &array, size_t position) DEPRECATED
 
template<typename ItemType >
ItemType::Value getSimpleValueFromArray (const boost::shared_ptr< CArray > &array, size_t position)
 
template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType getSimpleValueFromArray (const boost::shared_ptr< IProperty > &array, size_t position) DEPRECATED
  More...
 
template<typename ItemType >
ItemType::Value getSimpleValueFromArray (const boost::shared_ptr< IProperty > &ip, size_t position)
 
template<typename IP >
CInt::Value getIntFromArray (const IP &ip, size_t position)
 
template<typename IP >
CReal::Value getDoubleFromArray (const IP &ip, size_t position)
 
template<typename IP >
CString::Value getStringFromArray (const IP &ip, size_t position)
 
template<typename IP >
CRef::Value getRefFromArray (const IP &ip, size_t position)
 
template<typename Value , typename ItemType , PropertyType ItemPType>
void setSimpleValueInArray (const CArray &array, size_t position, const Value &val) DEPRECATED
 
template<typename ItemType >
void setSimpleValueInArray (const CArray &array, size_t position, const typename ItemType::Value &val)
 
template<typename Value , typename ItemType , PropertyType ItemPType>
void setSimpleValueInArray (const IProperty &array, size_t position, const Value &val) DEPRECATED
  More...
 
template<typename ItemType >
void setSimpleValueInArray (const IProperty &ip, size_t position, const typename ItemType::Value &val)
 
template<typename IP >
void setIntInArray (const IP &ip, size_t position, int val)
 
template<typename IP >
void setDoubleInArray (const IP &ip, size_t position, double val)
 
template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > getTypeFromArray (const boost::shared_ptr< CArray > &array, size_t pos) DEPRECATED
 
template<typename ItemType >
boost::shared_ptr< ItemType > getTypeFromArray (const boost::shared_ptr< CArray > &array, size_t pos)
 
template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > getTypeFromArray (const boost::shared_ptr< IProperty > &array, size_t pos) DEPRECATED
  More...
 
template<typename ItemType >
boost::shared_ptr< ItemType > getTypeFromArray (const boost::shared_ptr< IProperty > &ip, size_t pos)
 
void dictFromXpdfObj (CDict &resultDict,::Object &dict)
 
size_t stringToCharBuffer (Object &stringObject, CharBuffer &outputBuf)
 
unsigned char * bufferFromStream (Stream &str, size_t dictLength, size_t &size)
 
unsigned char * convertStreamToDecodedData (const Object &obj, size_t &size)
 
size_t streamToCharBuffer (const Object &streamObject, Ref *ref, CharBuffer &outputBuf, stream_data_extractor extractor)
 
void xpdfObjToString (Object &obj, std::string &str)
 
void getStringFromXpdfStream (std::string &str,::Object &obj)
 
void createIndirectObjectStringFromString (const IndiRef &rf, const std::string &val, std::string &output)
 
template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType getSimpleValueFromDict (const boost::shared_ptr< CDict > &dict, const std::string &id)
  More...
 
template<typename ItemType >
ItemType::Value getSimpleValueFromDict (const boost::shared_ptr< CDict > &dict, CDict::PropertyId id)
 
template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType getSimpleValueFromDict (const CDict &dict, const std::string &id) DONOTUSE
  More...
 
template<typename ItemType >
ItemType::Value getSimpleValueFromDict (const CDict &dict, const std::string &id)
  More...
 
template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType getSimpleValueFromDict (const boost::shared_ptr< IProperty > &dict, const std::string &id) DONOTUSE
  More...
 
template<typename ItemType >
ItemType::Value getSimpleValueFromDict (const boost::shared_ptr< IProperty > &ip, const std::string &id)
  More...
 
template<typename IP >
int getIntFromDict (const IP &ip, const std::string &id)
 
template<typename IP >
double getDoubleFromDict (const IP &ip, const std::string &id)
 
template<typename IP >
std::string getStringFromDict (const IP &ip, const std::string &id)
 
template<typename IP >
std::string getNameFromDict (const IP &ip, const std::string &id)
 
template<typename Value , typename ItemType , PropertyType ItemPType>
void setSimpleValueInDict (const CDict &dict, const std::string &name, const Value &val) DONOTUSE
 
template<typename ItemType >
void setSimpleValueInDict (const CDict &dict, CDict::PropertyId name, const typename ItemType::Value &val)
 
template<typename Value , typename ItemType , PropertyType ItemPType>
void setSimpleValueInDict (const IProperty &dict, const std::string &name, const Value &val) DONOTUSE
  More...
 
template<typename ItemType >
void setSimpleValueInDict (const IProperty &ip, CDict::PropertyId name, const typename ItemType::Value &val)
  More...
 
template<typename IP >
void setIntInDict (const IP &ip, const std::string &name, int val)
 
template<typename IP >
void setDoubleInDict (const IP &ip, const std::string &name, double val)
 
template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > getTypeFromDictionary (const boost::shared_ptr< CDict > &dict, const std::string &key) DONOTUSE
 
template<typename ItemType >
boost::shared_ptr< ItemType > getTypeFromDictionary (const boost::shared_ptr< CDict > &dict, CDict::PropertyId key)
 
template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > getTypeFromDictionary (const boost::shared_ptr< IProperty > &dict, const std::string &key) DONOTUSE
  More...
 
template<typename ItemType >
boost::shared_ptr< ItemType > getTypeFromDictionary (const boost::shared_ptr< IProperty > &ip, CDict::PropertyId key)
 
template<typename IP >
boost::shared_ptr< CDictgetCDictFromDict (IP &ip, const std::string &key)
 
template<typename IP >
boost::shared_ptr< CArraygetCArrayFromDict (IP &ip, const std::string &key)
 
boost::shared_ptr< CDictgetCDictFromDict (boost::shared_ptr< CDict > dict, const std::string &key)
 
bool objHasParent (const IProperty &ip, boost::shared_ptr< IProperty > &indiObj)
 
bool objHasParent (const IProperty &ip)
 
template<typename T >
void parseStreamToContainer (T &container, const ::Object &obj)
 
template void parseStreamToContainer< CStream::Buffer > (CStream::Buffer &container, const ::Object &obj)
 
template<typename ITERATOR , typename OUTITERATOR >
void streamToString (const std::string &strDict, ITERATOR begin, ITERATOR end, OUTITERATOR out)
 
template void streamToString< CStream::Buffer::const_iterator, std::back_insert_iterator< std::string > > (const std::string &strDict, CStream::Buffer::const_iterator begin, CStream::Buffer::const_iterator end, std::back_insert_iterator< std::string > out)
 
void simpleValueFromString (const std::string &str, bool &val)
 
void simpleValueFromString (const std::string &str, int &val)
 
void simpleValueFromString (const std::string &str, double &val)
 
void simpleValueFromString (const std::string &str, std::string &val)
 
void simpleValueFromString (const std::string &str, IndiRef &val)
 
template<>
void simpleValueToString< pBool > (bool val, string &str)
 
template<>
void simpleValueToString< pInt > (int val, string &str)
 
void trim_trailing_zero (char *number_str)
 
template<>
void simpleValueToString< pReal > (double val, string &str)
 
template<>
void simpleValueToString< pNull > (const NullType &, string &str)
 
template<>
void simpleValueToString< pRef > (const IndiRef &ref, string &str)
 
bool isBinaryString (const std::string &val)
 
template<typename Iter >
std::string makeHexString (Iter it, Iter end)
 
template<PropertyType Tp>
void simpleValueToString (const std::string &val, std::string &str)
  More...
 
template void simpleValueToString< pString > (const string &val, string &str)
 
template void simpleValueToString< pName > (const string &val, string &str)
 
template<>
void complexValueToString< CArray > (const CArray::Value &val, string &str)
 
template<>
void complexValueToString< CDict > (const CDict::Value &val, string &str)
 
void xpdfObjToString (Object &obj, string &str)
 
IPropertycreateObjFromXpdfObj (boost::shared_ptr< CPdf > pdf, const Object &obj, const IndiRef &ref)
 
IPropertycreateObjFromXpdfObj (const Object &obj)
 
template<PropertyType Tp, typename T >
ObjectsimpleValueToXpdfObj (T val)
 
template ObjectsimpleValueToXpdfObj< pBool, const bool & > (const bool &val)
 
template ObjectsimpleValueToXpdfObj< pInt, const int & > (const int &val)
 
template ObjectsimpleValueToXpdfObj< pReal, const double & > (const double &val)
 
template ObjectsimpleValueToXpdfObj< pString, const string & > (const string &val)
 
template ObjectsimpleValueToXpdfObj< pName, const string & > (const string &val)
 
template ObjectsimpleValueToXpdfObj< pNull, const NullType & > (const NullType &val)
 
template ObjectsimpleValueToXpdfObj< pRef, const IndiRef & > (const IndiRef &val)
 
template<PropertyType Tp, typename T >
void simpleValueFromXpdfObj (const Object &obj, T val)
 
template<>
void simpleValueFromXpdfObj< pNull, NullType & > (const Object &, NullType &)
 
template<PropertyType Tp, typename T >
void complexValueFromXpdfObj (IProperty &ip, const Object &obj, T val)
 
template void complexValueFromXpdfObj< pArray, CArray::Value & > (IProperty &ip, const Object &obj, CArray::Value &val)
 
template void complexValueFromXpdfObj< pDict, CDict::Value & > (IProperty &ip, const Object &obj, CDict::Value &val)
 
::ObjectxpdfObjFromString (const std::string &str, XRef *xref)
 
::ObjectxpdfStreamObjFromBuffer (const CStream::Buffer &buffer, const CDict &dict)
 
int getIntFromDict (std::string name, boost::shared_ptr< CDict > dict)
 
IndiRef getRefFromDict (std::string name, boost::shared_ptr< CDict > dict)
 
std::string getStringFromDict (std::string name, boost::shared_ptr< CDict > dict)
 
std::string getNameFromDict (std::string name, boost::shared_ptr< CDict > dict)
 
std::string getDictType (boost::shared_ptr< CDict > dict)
 
boost::shared_ptr< CDictgetDictFromRef (boost::shared_ptr< IProperty > refProp)
 
boost::shared_ptr< CDictgetDictFromRef (CPdf &pdf, IndiRef ref)
 
void printProperty (boost::shared_ptr< IProperty > ip, std::ostream &out)
 
template<typename SimpleClass , PropertyType SimpleType>
bool simpleEquals (const boost::shared_ptr< IProperty > &val1, const boost::shared_ptr< IProperty > &val2) throw ()
 
boost::shared_ptr< IPropertygetReferencedObject (boost::shared_ptr< IProperty > ip)
 
boost::shared_ptr< IPropertygetIPropertyFromRectangle (const libs::Rectangle &rect)
 
void getRectangleFromProperty (const shared_ptr< IProperty > prop, libs::Rectangle &rect)
 
boost::shared_ptr< IPropertygetIPropertyFromDate (const tm *time)
 
bool checkAndReplace (boost::shared_ptr< CDict > annotDict, std::string fieldName, IProperty &fieldValue)
 
::XRefgetXRef (shared_ptr< IProperty > ip)
 
template<typename Complex , typename Container >
void getPropertyId (const boost::shared_ptr< Complex > &parent, const boost::shared_ptr< IProperty > &child, Container &container) throw ()
 
void getRectangleFromProperty (const boost::shared_ptr< IProperty > prop, libs::Rectangle &rect)
 
template<typename Container >
void getAllChildrenOfPdfObject (boost::shared_ptr< CDict > topdict, Container &cont)
 
::XRefgetXRef (boost::shared_ptr< IProperty > ip)
 
template<typename Iter >
std::string makeNamePdfValid (Iter it, Iter end)
 
std::string makeNamePdfValid (const char *str)
 
template<typename Iter >
std::string makeStringPdfValid (Iter it, Iter end)
 
std::string makeStringPdfValid (GString *str)
 
IPropertycreateObjFromXpdfObj (boost::shared_ptr< CPdf > pdf, const ::Object &obj, const IndiRef &ref)
 
IPropertycreateObjFromXpdfObj (const ::Object &obj)
 
template<PropertyType Tp, typename T >
void simpleValueFromXpdfObj (const ::Object &obj, T val)
 
::ObjectxpdfObjFromString (const std::string &str,::XRef *xref=NULL)
 
template<PropertyType Tp>
void simpleValueToString (bool val, std::string &str)
 
template<PropertyType Tp>
void simpleValueToString (int val, std::string &str)
  More...
 
template<PropertyType Tp>
void simpleValueToString (double val, std::string &str)
  More...
 
template<PropertyType Tp>
void simpleValueToString (const NullType &val, std::string &str)
  More...
 
template<PropertyType Tp>
void simpleValueToString (const IndiRef &val, std::string &str)
  More...
 
template<typename ItemType , PropertyType ItemPType, typename Value >
Value getValueFromSimple (const boost::shared_ptr< IProperty > &ip) DEPRECATED
 
template<typename ItemType >
ItemType::Value getValueFromSimple (const boost::shared_ptr< IProperty > &ip)
 
int getIntFromIProperty (const boost::shared_ptr< IProperty > &ip)
 
double getDoubleFromIProperty (const boost::shared_ptr< IProperty > &ip)
 
std::string getStringFromIProperty (const boost::shared_ptr< IProperty > &ip)
 
std::string getNameFromIProperty (const boost::shared_ptr< IProperty > &ip)
 
template<typename ItemType , PropertyType ItemPType, typename Value >
void setValueToSimple (const boost::shared_ptr< IProperty > &ip, const Value &val)
 
ostream & operator<< (ostream &stream, PageTreeNodeType nodeType)
 
shared_ptr< CDictgetPageTreeRoot (const boost::shared_ptr< CPdf > &pdf)
 
PageTreeNodeType getNodeType (const boost::shared_ptr< IProperty > &nodeProp) throw ()
 
template<typename Container >
void getKidsFromInterNode (const boost::shared_ptr< CDict > &interNodeDict, Container &container) throw ()
 
size_t getKidsCount (const boost::shared_ptr< IProperty > &interNodeProp, PageTreeNodeCountCache *cache) throw ()
 
boost::shared_ptr< CDictfindPageDict (const boost::shared_ptr< CPdf > &pdf, const boost::shared_ptr< IProperty > &pagesDict, size_t startPos, size_t pos, PageTreeNodeCountCache *cache)
 
size_t searchTreeNode (shared_ptr< const CPdf > pdf, shared_ptr< CDict > superNode, shared_ptr< CDict > node, size_t startValue, PageTreeNodeCountCache *cache)
 
size_t getNodePosition (const shared_ptr< CPdf > &pdf, const shared_ptr< IProperty > &node, PageTreeNodeCountCache *cache)
 
bool isNodeDescendant (const boost::shared_ptr< CPdf > &pdf, const IndiRef &parent, const shared_ptr< CDict > &child)
 
bool isEncrypted (const boost::shared_ptr< CPdf > &pdf)
 
size_t getNodePosition (const boost::shared_ptr< CPdf > &pdf, const boost::shared_ptr< IProperty > &node, PageTreeNodeCountCache *cache)
 
bool isNodeDescendant (const boost::shared_ptr< CPdf > &pdf, const IndiRef &parent, const boost::shared_ptr< CDict > &child)
 
template<typename CType >
boost::shared_ptr< CType > getCObjectFromRef (const boost::shared_ptr< IProperty > &refProp)
 
template<typename CType >
boost::shared_ptr< CType > getCObjectFromRef (const IndiRef &ref, const boost::shared_ptr< CPdf > &pdf)
 
template<typename Iter >
void makeStreamPdfValid (Iter it, Iter end, std::string &out)
 
template<typename IP >
boost::shared_ptr< CStreamgetCStreamFromDict (IP &ip, const std::string &key)
 
template<typename IP >
boost::shared_ptr< CStreamgetCStreamFromArray (IP &ip, size_t pos)
 
int getFiltersFromStream (const Object &obj, std::vector< std::string > &filters)
 
boost::shared_ptr
< FilterStreamWriter
lookupFilterStreamWriter (const Object &obj, FilterStreamWriter::WritersList &filters)
 
void writeObject (const ::Object &obj, StreamWriter &stream,::Ref *ref, bool indirect)
 
void stripXRefStreamFields (const Object &trailer)
 
bool checkLinearized (StreamWriter &stream, CXref *xref, Ref *ref)
 
bool isLatestRevision (const XRefWriter &xref)
 
bool canChangeTrailerEntry (const char *name)
 
bool typeSafeTrailerEntry (const char *name,::Object &value, XRef &xref)
 

Detailed Description

Namespace includes all helper functions and classes.

Typedef Documentation

Type for pdf writer observers.

Uses OperationStep as value keeper.

Definition at line 81 of file pdfwriter.h.

typedef unsigned char*(* pdfobjects::utils::stream_data_extractor)(const Object &obj, size_t &size)

Function to be used for data extracting from the given stream object. Note that implementation can apply additional filters to the stream data currently stored in the obj.stream and update object accordingly (change Filter and associated entry). Length entry doesn't have to be changed by the implementation as it is supposed to be updated by caller (because we want to prevent useless object updating when a chain of this function is called for multiple filters).
Function is called from the streamToCharBuffer function to have transparent access to the stream data without any knowledge about filters. bufferFromStreamData is the referencial implementation which provides encoded data without any filters applied (all other implementations can use this function as the base and convert returned buffer into their represenation).

Parameters
Streamobject.
sizeNumber of bytes written to the returned buffer.
Returns
Buffer (size bytes) with data (must be deallocated by caller) or NULL on error.

Definition at line 517 of file cdict.h.

Enumeration Type Documentation

Type enumeration for page tree nodes. Type of dictionary in page tree. Possible values are:

  • ErrorNode - node has bad type (it is not dictionary or reference to dictionary).
  • UnknownNode - node is dictionary but it is not possible to get node type
  • LeafNode - leaf tree node (Page dictionary).
  • InterNode - intermediate node (Pages dictionary).
  • RootNode - intermediate root node.

Implementation node:
Note that order is significant, because we assume that everything lower than LeafNode is kind of error (problem) and also that greater or equal than InterNode is intermediate node.

Enumerator
ErrorNode 
UnknownNode 
LeafNode 
InterNode 
RootNode 

Definition at line 1637 of file cpdf.h.

Function Documentation

CAnnotation::AnnotType pdfobjects::utils::annotTypeMapping ( const std::string &  typeName)

Returns CAnnotation enumeration type for given name.

Parameters
typeNameString representation of type (value of Subtype field from annotation dictionary).

Maps given string to CAnnotation::AnnotType.

See Also
CAnnotation::AnnotType
Returns
enumeration representation of annotation type or Unknown if can't recongnize given one.

Definition at line 50 of file cannotation.cc.

References StrikeOut, gui::Text, and Underline.

Referenced by pdfobjects::CAnnotation::getType().

unsigned char * pdfobjects::utils::bufferFromStream ( Stream str,
size_t  dictLength,
size_t &  size 
)

Helper function which returns data from given stream.

Parameters
strStream to read (until it returns EOF).
dictLengthInitial size reported by the stream dictionary.
sizeOutput size of the buffer.

This is low-level function which simply reads given stream from its beginning until EOF. It can be used to retrieve data from whatever Stream filter stack layer. E.g. if we want to get encoded data we can simply give stream->getBaseStream() as parameter and this function will return buffer as it is written in the file.

Returns
Buffer with stream data (size will contain number of bytes stored) or NULL on error.

Definition at line 887 of file cobject2xpdf.cc.

References Stream::getChar(), i, NULL, NULL, Stream::reset(), Stream::reset(), utilsPrintDbg, utilsPrintDbg, and utilsPrintDbg.

Referenced by convertStreamToDecodedData(), and pdfobjects::utils::NullFilterStreamWriter::null_extractor().

bool pdfobjects::utils::canChangeTrailerEntry ( const char *  name)

Checks whether trailer entry with the following name can be changed.

Parameters
nameName of the field (must be non NULL).
Returns
true if the name is not black-listed false otherwise.

Definition at line 282 of file xrefwriter.cc.

References i, i, i, i, kernelPrintDbg, and NULL.

Referenced by pdfobjects::XRefWriter::changeTrailer(), and TestCPdf::changeTrailerTC().

bool pdfobjects::utils::checkAndReplace ( boost::shared_ptr< CDict >  annotDict,
std::string  fieldName,
IProperty &  fieldValue 
)
bool pdfobjects::utils::checkLinearized ( StreamWriter stream,
CXref *  xref,
Ref ref 
)

Checks whether given stream is linearized.

Parameters
streamPdf stream to read (from the file begin).
xrefXRef instance.
refPointer to reference where to set object and generation number.

Searches first indirect object in the stream from the begining and if it is dictionary, checks whether it contains Linearized version entry. If so returns true and if given ref is not NULL, sets object and generation number. Otherwise just returns false and doesn't care for ref parameter.
This method doesn't check whether credentials are set properly. You have to do it before it is called.

Returns
true if first indirect object is Linearized dictionary, false otherwise.

Definition at line 50 of file xrefwriter.cc.

References FIRST_LINEARIZED_BLOCK, Object::free(), Object::free(), Object::free(), Object::free(), Object::free(), Object::free(), Object::free(), Object::free(), Object::free(), Object::free(), Ref::gen, Object::getDict(), Object::getInt(), Object::getInt(), Parser::getObj(), Parser::getObj(), Parser::getObj(), Parser::getObj(), Stream::getPos(), Stream::getPos(), gTrue, Object::isCmd(), Object::isDict(), Object::isEOF(), Object::isEOF(), Object::isEOF(), Object::isEOF(), Object::isInt(), Object::isInt(), Object::isNull(), BaseStream::makeSubStream(), NULL, Ref::num, gui::parser, Stream::reset(), and utilsPrintDbg.

Referenced by pdfobjects::XRefWriter::XRefWriter().

template<PropertyType Tp, typename T >
void pdfobjects::utils::complexValueFromXpdfObj ( IProperty &  ip,
const ::Object obj,
val 
)

Save real xpdf object value to val.

Parameters
ipIProperty that will be initialized by obj.
objXpdf object which holds the value.
valVariable where the value will be stored.
template<PropertyType Tp, typename T >
void pdfobjects::utils::complexValueFromXpdfObj ( IProperty &  ip,
const Object obj,
val 
)
inline

Definition at line 737 of file cobject2xpdf.cc.

template void pdfobjects::utils::complexValueFromXpdfObj< pArray, CArray::Value & > ( IProperty &  ip,
const Object obj,
CArray::Value val 
)
template void pdfobjects::utils::complexValueFromXpdfObj< pDict, CDict::Value & > ( IProperty &  ip,
const Object obj,
CDict::Value val 
)
template<typename T >
void pdfobjects::utils::complexValueToString ( const typename T::Value val,
std::string &  str 
)

Return complex xpdf object (null,number,string...) in string representation.

REMARK: It is a template function because I think stream won't be converted to string as easily as a dictionary. So we specialize these function for pArray and pDict.

Parameters
valthat will be converted to string.
strstring
template<>
void pdfobjects::utils::complexValueToString< CArray > ( const CArray::Value val,
string &  str 
)

Definition at line 276 of file cobject2string.cc.

References debug::DBG_DBG, and utilsPrintDbg.

Referenced by pdfobjects::CArray::getStringRepresentation().

template<>
void pdfobjects::utils::complexValueToString< CDict > ( const CDict::Value val,
string &  str 
)

Definition at line 305 of file cobject2string.cc.

References debug::DBG_DBG, and utilsPrintDbg.

Referenced by pdfobjects::CDict::getStringRepresentation().

unsigned char * pdfobjects::utils::convertStreamToDecodedData ( const Object obj,
size_t &  size 
)

Helper function for removing filters from the given stream object.

Parameters
objStream object.
sizeSize of returned buffer.
Returns
Buffer with raw stream data or NULL on error.

If the given obj used some filters, they are all decoded to get orignal data and the stream dictionary is updated so that it doesn't contain any filters.
Stream object stored in the given obj is not touched (because it doesn't give much sense - it returns decoded data anyway, it doesn't use dictionary to find out how to decode). Nevertheless this operation may be considered harmfull for later usage of given the object in the xpdf code paths!

Definition at line 926 of file cobject2xpdf.cc.

References bufferFromStream(), xpdf::freeXpdfObject(), Object::getInt(), Object::getStream(), Object::getStream(), i, i, Object::isInt(), NULL, NULL, Object::streamGetDict(), and utilsPrintDbg.

Referenced by pdfobjects::utils::ZlibFilterStreamWriter::deflate().

void pdfobjects::utils::createIndirectObjectStringFromString ( const IndiRef &  rf,
const std::string &  val,
std::string &  output 
)

Create text representation of an indirect object from string and IndiRef.

Parameters
rfIndiRef.
valValue of an object.
outputOutput string.

Definition at line 196 of file cobject.cc.

References pdfobjects::Specification::INDIRECT_FOOTER, and pdfobjects::Specification::INDIRECT_HEADER.

Referenced by writeObject().

IProperty* pdfobjects::utils::createObjFromXpdfObj ( boost::shared_ptr< CPdf >  pdf,
const ::Object obj,
const IndiRef &  ref 
)

Creates CObject* from xpdf object.

Parameters
pdfPdf in which the created object will live. Parameter to CObject* constructor.
objXpdf object from which the object will be created. Parameter to CObject* constructor.
refIndirect reference number of this object (or its parent).
Returns
Pointer to newly created object.
IProperty* pdfobjects::utils::createObjFromXpdfObj ( const ::Object obj)

Creates CObject* from xpdf object.

Parameters
objXpdf object from which the object will be created. Parameter to CObject* constructor.
Returns
Pointer to newly created object.
void pdfobjects::utils::dictFromXpdfObj ( CDict &  resultDict,
::Object dict 
)

This function is a slower equivalent to complexValueFromXpdfObj. But on the other hand, complexValueFromXpdfObj() needs inner dictionary container that we do not have always access to.

Parameters
resultDictDictionary.
dictXpdf object from which we init dictionary.

Definition at line 758 of file cobject2xpdf.cc.

References pdfobjects::CDict::addProperty(), createObjFromXpdfObj(), debug::DBG_DBG, Object::dictGetKey(), Object::dictGetLength(), Object::dictGetLength(), Object::dictGetValNF(), pdfobjects::XPdfObjectFactory::getInstance(), pdfobjects::CDict::getPropertyCount(), Object::getType(), Object::getType(), i, objDict, objDict, and utilsPrintDbg.

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

boost::shared_ptr< CDict > pdfobjects::utils::findPageDict ( const boost::shared_ptr< CPdf > &  pdf,
const boost::shared_ptr< IProperty > &  pagesDict,
size_t  startPos,
size_t  pos,
PageTreeNodeCountCache *  cache 
)

Helper method to find page at certain position.

Parameters
pdfPdf instance where to search.
pagesDictReference to or Page or Pages dictionary representing page node (see Pdf standard notes).
startPosStarting position for searching (see note below).
posPage position (starting from 1) to find.
cacheCache for reference to page count mapping.

Method recursively goes through page subtree starting with given page tree node until given page position is found or no such position can be found. If position can't be found under given page node, exception is thrown.
If given pagesDict is reference, uses CPdf::getIndirectProperty to get target indirect object, which should be a dictionary (otherwise throws ElementBadTypeException).
Note that this function is not able to handle cycles in page tree and if any occures, endless loop will happen.
startPos stands for position of pagesDict in whole page tree. In fact it is position of first leaf node in subtree.

Pdf standard notes:
Pdf tree structure contains of two types of page dictionaries.

  • Pages dictionary - which is just intermediate node in the tree and contains children nodes. These may be direct pages or another Pages node. It doesn't represent page itself. All children are stored in Kids array. Dictionary also contains Count information which holds number of all Page dictionaries under this node.
  • Page dictionary - leaf node which represents direct page.

This structure is rather complex but enables effective way to access arbitrary page in short time (some applications provide balanced tree form to enable very effective access).

Implementation notes:
Function tries to find page also in page tree structure which doesn't follow pdf specification. All wierd page tree elements are ignored and just those which may stand for intermediate or leaf nodes are condidered. Also doesn't use Count or Parent field information during searching. Uses getKidsCount function to get intermediate leaf nodes count. getKidsCount method requieres also cache which stores already known nodes to their counts mapping. This function just delegates given cache parameter to getPageCount and doesn't care for it much more. If it is NULL, it is not used.

Usage notes:
If searching from begining, page tree root should be used as pagesDict parameter and startPos set to 1.

Example:
shared_ptr<CDict> pageTreeRoot=getPageTreeRoot(pdf);
if(pageTreeRoot.get())
    findPageDict(pdf, pageTreeRoot, 1, posToSearch, NULL);


Searching can start also from different intermediate node than root, but startPos has to be correct position of this node in the tree (same value as returned by getNodePosition method applied on such node). This usage can be used for searching optimization when just part of the tree is searched.

Exceptions
PageNotFoundExceptionif given position couldn't be found under subtree defined by pagesDict.
ElementBadTypeExceptionif pagesDict is not dictionary or reference to dictionary.
Returns
Dereferenced page (wrapped in shared_ptr) dictionary at given position.

Definition at line 427 of file cpdf.cc.

References count, count, getKidsCount(), getKidsFromInterNode(), getNodeType(), getNodeType(), i, i, i, i, InterNode, InterNode, InterNode, pdfobjects::isDict(), pdfobjects::isRef(), pdfobjects::isRef(), LeafNode, LeafNode, LeafNode, RootNode, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, and utilsPrintDbg.

Referenced by pdfobjects::CPdf::getPage(), pdfobjects::CPdf::insertPage(), and pdfobjects::CPdf::removePage().

template<typename Container >
void pdfobjects::utils::getAllChildrenOfPdfObject ( boost::shared_ptr< CDict >  topdict,
Container &  cont 
)

Get all children of a tree like structre of pdf objects with, "Prev", Next", "First" dictionary entries. This function can be used e.g. for getting all outlines.

Parameters
topdictTop level dictionary (it won't be included in the cont).
contOutput container of all children.

Definition at line 332 of file cobjecthelpers.h.

References getCDictFromDict(), and getCDictFromDict().

Referenced by pdfobjects::CPdf::getOutlines().

template<typename IP >
boost::shared_ptr<CArray> pdfobjects::utils::getCArrayFromDict ( IP &  ip,
const std::string &  key 
)
inline

Get array from dictionary. If it is an indirect object, fetch the object.

Definition at line 982 of file cdict.h.

template<typename IP >
boost::shared_ptr<CDict> pdfobjects::utils::getCDictFromDict ( IP &  ip,
const std::string &  key 
)
inline
boost::shared_ptr<CDict> pdfobjects::utils::getCDictFromDict ( boost::shared_ptr< CDict >  dict,
const std::string &  key 
)
inline

Get dictionary from dictionary. If it is an indirect object, fetch the object.

Definition at line 992 of file cdict.h.

template<typename CType >
boost::shared_ptr<CType> pdfobjects::utils::getCObjectFromRef ( const boost::shared_ptr< IProperty > &  refProp)

Returns cobjects from given reference property.

Parameters
refPropReference property (must be pRef typed).

Gets reference value from property and dereferences indirect object from it. Uses refProp's pdf for dereference (so it has to be valid). Checks target object type and if it is correct (CType::type), casts it to given CType (uses IProperty::getSmartCObjectPtr).

Exceptions
ElementBadTypeExceptionif refProp is not CRef instance or indirect object is not CType instance.
Returns
CType instance wrapped by shared_ptr smart pointer.

Definition at line 1865 of file cpdf.h.

References pdfobjects::isRef().

template<typename CType >
boost::shared_ptr<CType> pdfobjects::utils::getCObjectFromRef ( const IndiRef &  ref,
const boost::shared_ptr< CPdf > &  pdf 
)

Returns cobjects from given reference and pdf.

Parameters
refIndirect reference.
pdfCPdf instance where to fetch.

Calls getIndirectProperty on given pdf and cast returned indirect object to given CType (if it has correct type CType::type).

Exceptions
ElementBadTypeExceptionif indirect object is not CType instance.
Returns
CType instance wrapped by shared_ptr smart pointer.

Definition at line 1896 of file cpdf.h.

template<typename IP >
boost::shared_ptr<CStream> pdfobjects::utils::getCStreamFromArray ( IP &  ip,
size_t  pos 
)
inline

Get stream from array. If it is CRef fetch the object pointed at.

Definition at line 572 of file cstream.h.

Referenced by getTestStreamContent().

template<typename IP >
boost::shared_ptr<CStream> pdfobjects::utils::getCStreamFromDict ( IP &  ip,
const std::string &  key 
)
inline

Get stream from dictionary. If it is CRef fetch the object pointed at.

Definition at line 560 of file cstream.h.

boost::shared_ptr< CDict > pdfobjects::utils::getDictFromRef ( boost::shared_ptr< IProperty >  refProp)

Gets dictionary from reference property.

Parameters
refPropReference property (must be pRef typed).

Gets reference value from property and dereferences indirect object from it. Uses refProp's pdf for dereference. Finaly casts (if indirect is dictionary) to CDict and returns.

Exceptions
ElementBadTypeExceptionif refProp is not CRef instance or indirect object is not CDict instance.
Returns
CDict instance wrapper by shared_ptr smart pointer.

Definition at line 118 of file cobjecthelpers.cc.

References pdfobjects::pDict, and pdfobjects::pRef.

boost::shared_ptr< CDict > pdfobjects::utils::getDictFromRef ( CPdf &  pdf,
IndiRef  ref 
)

Gets dictionary from reference and pdf instance.

Parameters
pdfPdf istance.
refIndirect reference.

Uses CPdf::getIndirectProperty to get dereferenced object from given reference on given pdf instance. Checks object type and if it is CDict, returns it, otherwise throws an axception.

Exceptions
ElementBadTypeExceptionif indirect object is not CDict instance.
Returns
CDict instance wrapper by shared_ptr smart pointer.

Definition at line 137 of file cobjecthelpers.cc.

References pdfobjects::CPdf::getIndirectProperty(), and pdfobjects::pDict.

std::string pdfobjects::utils::getDictType ( boost::shared_ptr< CDict >  dict)

Gets type of the dictionary.

Parameters
dictDictionary wrapped in smart pointer.

Tries to get Type field from dictionary and returns its string value. If not present, returns an empty string.

Returns
string name of the dictionary type or empty string if not able to find out.

Definition at line 104 of file cobjecthelpers.cc.

References getNameFromDict().

template<typename IP >
double pdfobjects::utils::getDoubleFromDict ( const IP &  ip,
const std::string &  id 
)
inline

Get double from dictionary.

Definition at line 700 of file cdict.h.

References getIntFromDict().

double pdfobjects::utils::getDoubleFromIProperty ( const boost::shared_ptr< IProperty > &  ip)
inline

Get double from ip.

Definition at line 629 of file cobjectsimple.h.

References pdfobjects::isInt().

int pdfobjects::utils::getFiltersFromStream ( const Object obj,
std::vector< std::string > &  filters 
)

Helper function to get all filters from the stream object.

Parameters
objStream object.
filtersContainer for filter names.
Returns
Number of the filters present in the stream or -1 if some of them is not correct.

Definition at line 64 of file pdfwriter.cc.

References count, count, count, Object::free(), Array::get(), Object::getArray(), Array::getLength(), Object::getName(), Object::getName(), i, i, Object::isArray(), Object::isName(), Object::isName(), Object::isNull(), Object::isStream(), and Object::streamGetDict().

Referenced by pdfobjects::utils::ZlibFilterStreamWriter::supportObject().

template<typename IP >
CInt::Value pdfobjects::utils::getIntFromArray ( const IP &  ip,
size_t  position 
)
inline

Get int from array.

Definition at line 473 of file carray.h.

Referenced by getDoubleFromArray().

int pdfobjects::utils::getIntFromDict ( std::string  name,
boost::shared_ptr< CDict >  dict 
)

Helper method for getting int property value from dictionary.

Parameters
nameName of the property in the dictionary.
dictDictionary where to search.

Gets property according name. Checks property type and if it is realy pInt, gets its int value which is returned.

Exceptions
ElementNotFoundExceptionif property is not found.
ElementBadTypeExceptionif property is found but doesn't contain integer value.
Returns
int value of the property.

Definition at line 41 of file cobjecthelpers.cc.

References pdfobjects::pInt.

template<typename IP >
int pdfobjects::utils::getIntFromDict ( const IP &  ip,
const std::string &  id 
)
inline

Get int from dictionary.

Definition at line 694 of file cdict.h.

Referenced by getDoubleFromDict().

int pdfobjects::utils::getIntFromIProperty ( const boost::shared_ptr< IProperty > &  ip)
inline

Get int from ip.

Definition at line 622 of file cobjectsimple.h.

Referenced by TestCPdf::indirectPropertyTC(), TestCPdf::indirectPropertyTC(), and TestCPdf::indirectPropertyTC().

boost::shared_ptr< IProperty > pdfobjects::utils::getIPropertyFromDate ( const tm *  time)

Creates property with correct pdf time representation.

Parameters
timeTime to convert.

Created property is an string with ASN.1 defined in ISO/IEC 8824 format used in pdf (see PDF specification page 133 for more information).

Definition at line 285 of file cobjecthelpers.cc.

References pdfobjects::CObjectFactory< Type >::getInstance().

Referenced by pdfobjects::CAnnotation::createAnnotation().

boost::shared_ptr< IProperty > pdfobjects::utils::getIPropertyFromRectangle ( const libs::Rectangle &  rect)

Creates property with correct pdf Rectangle representation.

Parameters
rectRectangle to convert.

Created property is an array with four elements (see PDF specification page 134 for more information).

Returns
Property (CArray) wrapped by smart pointer.

Definition at line 251 of file cobjecthelpers.cc.

References pdfobjects::CObjectFactory< Type >::getInstance(), pdfobjects::CObjectFactory< Type >::getInstance(), pdfobjects::CObjectFactory< Type >::getInstance(), pdfobjects::CObjectFactory< Type >::getInstance(), and pdfobjects::CArrayFactory::getInstance().

Referenced by pdfobjects::CAnnotation::createAnnotation(), pdfobjects::CPageAttributes::fillInherited(), and pdfobjects::CPageAttributes::fillInherited().

size_t pdfobjects::utils::getKidsCount ( const boost::shared_ptr< IProperty > &  interNodeProp,
PageTreeNodeCountCache *  cache 
)
throw (
)

Calculates number of direct pages under given node property.

Parameters
interNodePropPage tree node property (must be dictionary or reference to dictionary).
cacheCache with node reference to leaf page count (if NULL. it is not used).

Checks whether given node is LeafNode and if so, immediatelly returns with 1 (leaf contains one direct page). Otherwise tries to get node dictionary from given property. If not able to do so, returns 0, because this node is probably invalid and so it can't contain any direct page node. Then checks whether given cache parameter is non NULL and if so checks cached value for given node (uses getCachedValue function). If cache entry exists for this node, uses cached value. Otherwise collects all Kids elements from dictionary (uses getKidsFromInterNode function) and calls this function recursively on each reference element. Collected number is returned and if cache is non NULL also caches value (uses updateCache function).
Note that this function never throws.

Definition at line 368 of file cpdf.cc.

References count, count, count, getKidsFromInterNode(), getNodeType(), i, i, i, i, pdfobjects::isDict(), pdfobjects::isRef(), pdfobjects::isRef(), and LeafNode.

Referenced by pdfobjects::CPdf::consolidatePageList(), pdfobjects::CPdf::consolidatePageList(), pdfobjects::CPdf::consolidatePageTree(), findPageDict(), findPageDict(), pdfobjects::CPdf::getPageCount(), TestCPdf::pageManipulationTC(), TestCPdf::pageManipulationTC(), and searchTreeNode().

template<typename Container >
void pdfobjects::utils::getKidsFromInterNode ( const boost::shared_ptr< CDict > &  interNodeDict,
Container &  container 
)
throw (
)

Collects all kids elements from internode dictionary.

Parameters
interNodeDictIntermediate node dictionary.
containerContainer where to store kids.

Clears given container at first. Gets Kids array from given dictionary and adds all its elements to given container. If not able to do so, immediatelly returns. Given container is empty if no kid is found (or any other problem occures).
Container template type must store shared_ptr<IProperty> types and support clear and push_back methods.
Note that this function never throws.

Definition at line 185 of file cpdf.cc.

References pdfobjects::isArray(), and pdfobjects::isRef().

Referenced by pdfobjects::CPdf::consolidatePageTree(), findPageDict(), getKidsCount(), and searchTreeNode().

std::string pdfobjects::utils::getNameFromDict ( std::string  name,
boost::shared_ptr< CDict >  dict 
)

Helper method for getting name property value from dictionary.

Parameters
nameName of the property in the dictionary.
dictDictionary where to search.

Gets property according name. Checks property type and if it is realy pName, gets its string value which is returned.

Exceptions
ElementNotFoundExceptionif property is not found.
ElementBadTypeExceptionif property is found but doesn't contain string value.
Returns
std::string value of the property.

Definition at line 86 of file cobjecthelpers.cc.

References pdfobjects::pName.

template<typename IP >
std::string pdfobjects::utils::getNameFromDict ( const IP &  ip,
const std::string &  id 
)
inline

Get name from dictionary.

Definition at line 723 of file cdict.h.

Referenced by getDictType(), pdfobjects::CPageFonts::getFontIdsAndNames(), and pdfobjects::CPageFonts::getFontIdsAndNames().

std::string pdfobjects::utils::getNameFromIProperty ( const boost::shared_ptr< IProperty > &  ip)
inline

Get name from ip.

Definition at line 644 of file cobjectsimple.h.

size_t pdfobjects::utils::getNodePosition ( const boost::shared_ptr< CPdf > &  pdf,
const boost::shared_ptr< IProperty > &  node,
PageTreeNodeCountCache *  cache 
)

Gets position of given node.

Parameters
pdfPdf where to examine.
nodeNode to find (CRef or CDict instances).
cacheCache for reference to page count mapping.

Starts searching for given node from root of the page tree (returned from getPageTreeRoot function). Uses recursive searchTreeNode function for searching and provides just error handling wrapper to this function. searchTreeNode reqieres also cache which stores already known nodes to their counts mapping. This function just delegates given cache parameter to getPageCount and doesn't care for it much more. If it is NULL, it is not used.
Prefer to use this function instead of searchTreeNode if you are not sure you know what you are doing.

Exceptions
PageNotFoundExceptionIf node can't be found.
ElementBadTypeExceptionIf given node is not dictionary or reference to dictionary.
AmbiguousPageTreeExceptionif node position can't be determined bacause of page tree ambiguity (see searchTreeNode for more information).
Returns
Node position.
PageTreeNodeType pdfobjects::utils::getNodeType ( const boost::shared_ptr< IProperty > &  nodeProp)
throw (
)

Checks given node for its page tree type.

Parameters
nodePropNode property (must be dictionary or reference to dictionary).

Gets node dictionary in first step (either directly from parameter or dereference). If not able to get it, returns ErrorNode type. Then checks whether node dictionary is same as Page tree root node and if so, returns RootNode type. If not able to get root node, returns UnknownNode.
In first step compares dictionary with pageTreeRoot dictionary. If they are same (uses == operator), returns RootNode. Otherwise checks for Type field in node dictionary and if present, checks its value. It must be name object. If so and value is Page, returns LeafNode, or if value is Pages, returns InterNode. Otherwise returns (also if Type field type is not name), returns UnknownNode.
Finally tries to determine node type from existing fields. If dictionary contains Kids array, it is considered to be InterNode. Otherwise returns UnknownNode.
Note that this function never throws.

Returns
Node type.

Definition at line 104 of file cpdf.cc.

References ErrorNode, ErrorNode, getPageTreeRoot(), InterNode, InterNode, InterNode, pdfobjects::isArray(), pdfobjects::isDict(), pdfobjects::isRef(), pdfobjects::isRef(), pdfobjects::isRef(), LeafNode, RootNode, UnknownNode, and UnknownNode.

Referenced by pdfobjects::CPdf::consolidatePageList(), pdfobjects::CPdf::consolidatePageList(), pdfobjects::CPdf::consolidatePageTree(), pdfobjects::CPdf::consolidatePageTree(), findPageDict(), findPageDict(), getKidsCount(), TestCPdf::pageManipulationTC(), searchTreeNode(), and searchTreeNode().

boost::shared_ptr< CDict > pdfobjects::utils::getPageTreeRoot ( const boost::shared_ptr< CPdf > &  pdf)

Gets page tree root node dictionary.

Parameters
pdfPdf where to search.

Gets Pages field from pdf dictionary and dereference it to dictionary. If it is not reference or target object is not a dictionary, returns NULL dictionary.
Note that this function never throws.

Returns
Dictionary wrapped by shared_ptr (NULL dictionary if not found).

Definition at line 84 of file cpdf.cc.

References pdfobjects::isRef().

Referenced by getNodePosition(), getNodeType(), pdfobjects::CPdf::getPage(), pdfobjects::CPdf::getPageCount(), pdfobjects::CPdf::insertPage(), TestCPdf::pageManipulationTC(), TestCPdf::pageManipulationTC(), pdfobjects::CPdf::removePage(), and pdfobjects::CPdf::unregisterPageObservers().

template<typename Complex , typename Container >
void pdfobjects::utils::getPropertyId ( const boost::shared_ptr< Complex > &  parent,
const boost::shared_ptr< IProperty > &  child,
Container &  container 
)
throw (
)

Gets all identificators of property in parent complex type.

Parameters
parentComplex value where to search.
childProperty to search.
containerContainer, where to place all identificators (array indexes).

Uses CObjectComplex::forEach method with IdCollector functor to collect all ids to given container.
Complex template parameter stands for type of CObjectComplex where to search. This type has to provide typedef for propertyId and getAllPropertyNames, getProperty methods.
Container template parameter stands for type of storage where to place found indexes. This has to provide clear and push_back methods. Given container is cleared at start.

Definition at line 280 of file cobjecthelpers.h.

References utilsPrintDbg.

void pdfobjects::utils::getRectangleFromProperty ( const shared_ptr< IProperty >  prop,
libs::Rectangle &  rect 
)
void pdfobjects::utils::getRectangleFromProperty ( const boost::shared_ptr< IProperty >  prop,
libs::Rectangle &  rect 
)

Gets rectangle value from given property.

Parameters
propArray property with exactly 4 elements.
rectRectangle which will be filled with values stored in given property.

Array property is transformed into the given rect object.

Exceptions
CObjBadValueif given property has not valid rectangle representation.
template<typename IP >
CRef::Value pdfobjects::utils::getRefFromArray ( const IP &  ip,
size_t  position 
)
inline

Get ref from array.

Definition at line 500 of file carray.h.

IndiRef pdfobjects::utils::getRefFromDict ( std::string  name,
boost::shared_ptr< CDict >  dict 
)

Helper method for getting reference property value from dictionary.

Parameters
nameName of the property in the dictionary.
dictDictionary where to search.

Gets property according name. Checks property type and if it is realy pRef, gets its IndiRef value which is returned.

Exceptions
ElementNotFoundExceptionif property is not found.
ElementBadTypeExceptionif property is found but doesn't contain reference value.
Returns
IndiRef value of the property.

Definition at line 56 of file cobjecthelpers.cc.

References pdfobjects::pRef.

template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType pdfobjects::utils::getSimpleValueFromArray ( const boost::shared_ptr< CArray > &  array,
size_t  position 
)
inline

Get simple value from array.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
arrayArray.
positionPosition in the array.

Definition at line 393 of file carray.h.

References debug::DBG_DBG, and utilsPrintDbg.

template<typename ItemType >
ItemType::Value pdfobjects::utils::getSimpleValueFromArray ( const boost::shared_ptr< CArray > &  array,
size_t  position 
)
inline

Gets simple value from array. Gets property from given position and uses getValueFromSimple to get its simple value.

Parameters
arrayArray property.
positionIndex in array of property.
Returns
simple value of property.

Definition at line 414 of file carray.h.

References debug::DBG_DBG, and utilsPrintDbg.

template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType pdfobjects::utils::getSimpleValueFromArray ( const boost::shared_ptr< IProperty > &  array,
size_t  position 
)
inline

Get simple value from array.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
arrayArray.
positionPosition in the array.

Definition at line 432 of file carray.h.

References pdfobjects::isArray(), and pdfobjects::isArray().

template<typename ItemType >
ItemType::Value pdfobjects::utils::getSimpleValueFromArray ( const boost::shared_ptr< IProperty > &  ip,
size_t  position 
)
inline

Gets simple value from array. Checks type of given ip and if it is array, casts it to CArray and gets value of property with given position (uses getSimpleValueFromArray with CArray parameter).

Parameters
ipArray property.
positionArray index.
Exceptions
ElementBadTypeExceptionif given property is not CArray or property with given index is not ItemType.

Definition at line 459 of file carray.h.

References pdfobjects::isArray().

template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType pdfobjects::utils::getSimpleValueFromDict ( const boost::shared_ptr< CDict > &  dict,
const std::string &  id 
)
inline

Get simple value from dictionary.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
dictDictionary.
idPosition in the dictionary.

Get simple value from dictionary.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
dictDictionary.
idPosition in the dictionary.

Definition at line 591 of file cdict.h.

References getReferencedObject().

template<typename ItemType >
ItemType::Value pdfobjects::utils::getSimpleValueFromDict ( const boost::shared_ptr< CDict > &  dict,
CDict::PropertyId  id 
)
inline

Get simple value from dictionary.

Uses getReferencedObject to property with given id to get target property (if it is reference) and getValueFromSimple with target property.

Parameters
dictDictionary.
idPosition in the dictionary.

Definition at line 612 of file cdict.h.

References debug::DBG_DBG, getReferencedObject(), and utilsPrintDbg.

template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType pdfobjects::utils::getSimpleValueFromDict ( const CDict &  dict,
const std::string &  id 
)
inline

Get simple value from dictionary.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
dictDictionary.
idPosition in the dictionary.

Definition at line 629 of file cdict.h.

References pdfobjects::CDict::getProperty(), and getReferencedObject().

template<typename ItemType >
ItemType::Value pdfobjects::utils::getSimpleValueFromDict ( const CDict &  dict,
const std::string &  id 
)
inline

Get simple value from dictionary.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
dictDictionary.
idPosition in the dictionary.

Definition at line 642 of file cdict.h.

References debug::DBG_DBG, pdfobjects::CDict::getProperty(), getReferencedObject(), and utilsPrintDbg.

template<typename SimpleValueType , typename ItemType , PropertyType ItemPType>
SimpleValueType pdfobjects::utils::getSimpleValueFromDict ( const boost::shared_ptr< IProperty > &  dict,
const std::string &  id 
)
inline

Get simple value from dictionary.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
dictDictionary.
idPosition in the dictionary.

Definition at line 660 of file cdict.h.

References pdfobjects::isDict(), and pdfobjects::isDict().

template<typename ItemType >
ItemType::Value pdfobjects::utils::getSimpleValueFromDict ( const boost::shared_ptr< IProperty > &  ip,
const std::string &  id 
)
inline

Get simple value from dictionary.

Todo:
Can use MPL because ItemType and ItemPType depend on each other.!!
Parameters
dictDictionary.
idPosition in the dictionary.

Definition at line 679 of file cdict.h.

References pdfobjects::isDict().

template<typename IP >
CString::Value pdfobjects::utils::getStringFromArray ( const IP &  ip,
size_t  position 
)
inline

Get string from array.

Definition at line 494 of file carray.h.

std::string pdfobjects::utils::getStringFromDict ( std::string  name,
boost::shared_ptr< CDict >  dict 
)

Helper method for getting string property value from dictionary.

Parameters
nameName of the property in the dictionary.
dictDictionary where to search.

Gets property according name. Checks property type and if it is realy pString, gets its string value which is returned.

Exceptions
ElementNotFoundExceptionif property is not found.
ElementBadTypeExceptionif property is found but doesn't contain string value.
Returns
std::string value of the property.

Definition at line 71 of file cobjecthelpers.cc.

References pdfobjects::pString.

template<typename IP >
std::string pdfobjects::utils::getStringFromDict ( const IP &  ip,
const std::string &  id 
)
inline

Get string from dictionary.

Definition at line 715 of file cdict.h.

Referenced by pdfobjects::getOutlineText(), pdfobjects::ContentsChangeTag::getTime(), and pdfobjects::isPage().

std::string pdfobjects::utils::getStringFromIProperty ( const boost::shared_ptr< IProperty > &  ip)
inline
void pdfobjects::utils::getStringFromXpdfStream ( std::string &  str,
::Object obj 
)

Get string from xpdf stream object.

Parameters
strOutput string.
objXpdf stream object.

Definition at line 579 of file cobject2xpdf.cc.

References Object::isStream(), Object::streamClose(), Object::streamGetChar(), and Object::streamReset().

Referenced by pdfobjects::CStream::getDecodedStringRepresentation().

template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > pdfobjects::utils::getTypeFromArray ( const boost::shared_ptr< CArray > &  array,
size_t  pos 
)
inline

Get iproperty casted to specific type from array.

Parameters
arrayArray.
posPosition in the array.

Definition at line 642 of file carray.h.

References debug::DBG_DBG, getReferencedObject(), and utilsPrintDbg.

template<typename ItemType >
boost::shared_ptr<ItemType> pdfobjects::utils::getTypeFromArray ( const boost::shared_ptr< CArray > &  array,
size_t  pos 
)
inline

Get iproperty casted to specific type from array.

Parameters
arrayArray.
idPosition in the array.
Exceptions
ElementBadTypeExceptionif property doesn't have ItemType type.

Definition at line 673 of file carray.h.

References debug::DBG_DBG, debug::DBG_DBG, getReferencedObject(), utilsPrintDbg, and utilsPrintDbg.

template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > pdfobjects::utils::getTypeFromArray ( const boost::shared_ptr< IProperty > &  array,
size_t  pos 
)
inline

Get iproperty casted to specific type from array.

Parameters
arrayArray.
posPosition in the array.

Definition at line 703 of file carray.h.

References pdfobjects::isArray(), and pdfobjects::isArray().

template<typename ItemType >
boost::shared_ptr<ItemType> pdfobjects::utils::getTypeFromArray ( const boost::shared_ptr< IProperty > &  ip,
size_t  pos 
)
inline

Get iproperty casted to specific type from array.

Checks type of given property and if it pArray, casts it to CArray and uses getTypeFromArray with CArray parameter.

Parameters
arrayArray.
idPosition in the array.
Exceptions
ElementBadTypeExceptionif given property is not an array or property at given position doesn't have ItemType type.

Definition at line 731 of file carray.h.

References pdfobjects::isArray().

template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > pdfobjects::utils::getTypeFromDictionary ( const boost::shared_ptr< CDict > &  dict,
const std::string &  key 
)
inline

Get iproperty casted to specific type from dictionary.

Parameters
dictDictionary.
keyPosition in the dictionary.

Definition at line 859 of file cdict.h.

References debug::DBG_DBG, debug::DBG_DBG, getReferencedObject(), utilsPrintDbg, and utilsPrintDbg.

template<typename ItemType >
boost::shared_ptr<ItemType> pdfobjects::utils::getTypeFromDictionary ( const boost::shared_ptr< CDict > &  dict,
CDict::PropertyId  key 
)
inline

Get property from dictionary.

If property is reference, dereferences it (uses getReferencedObject function).

Parameters
dictDictionary property.
keyProperty name.
Returns
Property with give type.
Exceptions
ElementBadTypeExceptionif found (dereferenced) property has different type than given.

Definition at line 894 of file cdict.h.

References debug::DBG_DBG, debug::DBG_DBG, getReferencedObject(), utilsPrintDbg, and utilsPrintDbg.

template<typename ItemType , PropertyType ItemPType>
boost::shared_ptr< ItemType > pdfobjects::utils::getTypeFromDictionary ( const boost::shared_ptr< IProperty > &  dict,
const std::string &  key 
)
inline

Get iproperty casted to specific type from dictionary.

Parameters
dictDictionary.
keyPosition in the dictionary.

Definition at line 927 of file cdict.h.

References pdfobjects::isDict(), and pdfobjects::isDict().

template<typename ItemType >
boost::shared_ptr<ItemType> pdfobjects::utils::getTypeFromDictionary ( const boost::shared_ptr< IProperty > &  ip,
CDict::PropertyId  key 
)
inline

Gets property from dictionary.

Checks type of given ip. If it is CDict instance, casts it and calls getTypeFromDictionary with CDict parameter.

Parameters
ipDictionary property.
keyProperty name.
Returns
Property with given key and ItemType.
Exceptions
ElementBadTypeExceptionif given ip is not CDict instance or target property has not ItemType.

Definition at line 956 of file cdict.h.

References pdfobjects::isDict().

template<typename ItemType , PropertyType ItemPType, typename Value >
Value pdfobjects::utils::getValueFromSimple ( const boost::shared_ptr< IProperty > &  ip)
inline

Get simple value from simple cobject.

Parameters
ipIProperty.
Returns
Value.

Definition at line 579 of file cobjectsimple.h.

References debug::DBG_DBG, and utilsPrintDbg.

template<typename ItemType >
ItemType::Value pdfobjects::utils::getValueFromSimple ( const boost::shared_ptr< IProperty > &  ip)
inline

Get simple value from simple cobject.

Given property must have correct type (ItemType::type).

Parameters
ipIProperty.
Returns
Value.

Definition at line 605 of file cobjectsimple.h.

References debug::DBG_DBG, and utilsPrintDbg.

::XRef* pdfobjects::utils::getXRef ( shared_ptr< IProperty >  ip)

Definition at line 326 of file cobjecthelpers.cc.

References NULL.

Referenced by pdfobjects::CStreamsXpdfReader< T >::open().

::XRef* pdfobjects::utils::getXRef ( boost::shared_ptr< IProperty >  ip)

Get xref from an object.

bool pdfobjects::utils::isBinaryString ( const std::string &  val)

Definition at line 211 of file cobject2string.cc.

References i, i, i, and i.

Referenced by simpleValueToString().

bool pdfobjects::utils::isEncrypted ( const boost::shared_ptr< CPdf > &  pdf)

Checks whether file content is encrypted.

Parameters
pdfPdf instance to check.

Simple helper which asks its cross reference table.

Returns
true if file content is encrypted, false otherwise.

Definition at line 816 of file cpdf.cc.

References gTrue.

Referenced by pdfobjects::CPdf::changeIndirectProperty(), gui::QSPdf::isEncrypted(), print_info(), and TestCPdf::Test().

bool pdfobjects::utils::isNodeDescendant ( const boost::shared_ptr< CPdf > &  pdf,
const IndiRef &  parent,
const shared_ptr< CDict > &  child 
)

Definition at line 779 of file cpdf.cc.

References pdfobjects::isRef().

Referenced by pdfobjects::CPdf::consolidatePageList(), and TestCPdf::pageManipulationTC().

bool pdfobjects::utils::isNodeDescendant ( const boost::shared_ptr< CPdf > &  pdf,
const IndiRef &  parent,
const boost::shared_ptr< CDict > &  child 
)

Checks if given child is descendant of node with given reference.

Parameters
pdfPdf where to resolv referencies.
parentReference of the parent.
childDictionary of page(s) node.

Checks if child's Parent field has same reference as given one as parent parameter. If yes then child dictionary is descendant of node with parent reference. If not, dereference child's parent and continues in recursion using dereferenced parent dictionary as new child for recursion call.
NOTE: this method doesn't perform any checking of parameters and doesn't work if Parent property has not valid value (according page tree state).

Returns
true If given child belongs to parent subtree, false otherwise.
boost::shared_ptr<FilterStreamWriter> pdfobjects::utils::lookupFilterStreamWriter ( const Object obj,
FilterStreamWriter::WritersList &  filters 
)

Helper function to find the first filter writer which supports given object.

Parameters
objStream object to write.
filtersContainer of supported filter writers.
Returns
Appropriate filter writer or NULL.

Definition at line 382 of file pdfwriter.cc.

References i, i, and i.

Referenced by pdfobjects::utils::FilterStreamWriter::getInstance().

template<typename Iter >
std::string pdfobjects::utils::makeHexString ( Iter  it,
Iter  end 
)

Definition at line 220 of file cobject2string.cc.

References snprintf.

Referenced by simpleValueToString().

template<typename Iter >
std::string pdfobjects::utils::makeNamePdfValid ( Iter  it,
Iter  end 
)

Make name valid.

Beginning with PDF 1.2, any character except null (character code 0) may be included in a name by writing its 2-digit hexadecimal code, preceded by the number sign character (#); see implementation notes 3 and 4 in Appendix H. This syntax is required to represent any of the delimiter or white-space characters or the number sign character itself; it is recommended but not required for characters whose codes are outside the range 33 (!) to 126 (~). The examples shown in Table 3.3 are valid literal names in PDF 1.2 and later.

Parameters
itStart iterator.
endEnd iterator.

Definition at line 323 of file cobjectsimple.h.

References snprintf.

Referenced by makeNamePdfValid(), and simpleValueToString().

std::string pdfobjects::utils::makeNamePdfValid ( const char *  str)
inline

Make name valid.

Beginning with PDF 1.2, any character except null (character code 0) may be included in a name by writing its 2-digit hexadecimal code, preceded by the number sign character (#); see implementation notes 3 and 4 in Appendix H. This syntax is required to represent any of the delimiter or white-space characters or the number sign character itself; it is recommended but not required for characters whose codes are outside the range 33 (!) to 126 (~). The examples shown in Table 3.3 are valid literal names in PDF 1.2 and later.

Parameters
strCharacter string.

Definition at line 356 of file cobjectsimple.h.

References makeNamePdfValid().

template<typename Iter >
void pdfobjects::utils::makeStreamPdfValid ( Iter  it,
Iter  end,
std::string &  out 
)

Make stream pdf valid.

Not needed now.

Parameters
itStart insert iterator.
endEnd iterator.
outOutput valid string.

Definition at line 501 of file cstream.h.

Referenced by pdfobjects::CStream::setBuffer().

template<typename Iter >
std::string pdfobjects::utils::makeStringPdfValid ( Iter  it,
Iter  end 
)

Make string pdf valid.

Any characters may appear in a string except unbalanced parentheses and the backslash, which must be treated specially.
This includes also \0 (NUL) character, therefore we can't use standard str* functions for strings.

Parameters
itStart iterator.
endEnd iterator.

Definition at line 375 of file cobjectsimple.h.

Referenced by makeStringPdfValid(), and simpleValueToString().

std::string pdfobjects::utils::makeStringPdfValid ( GString str)
inline

Make string pdf valid.

Any characters may appear in a string except unbalanced parentheses and the backslash, which must be treated specially.

Parameters
strCharacter string.

Definition at line 405 of file cobjectsimple.h.

References GString::getCString(), GString::getLength(), and makeStringPdfValid().

bool pdfobjects::utils::objHasParent ( const IProperty &  ip,
boost::shared_ptr< IProperty > &  indiObj 
)

Returns true if object has a parent.

Exceptions
ObjInvalidOperationThrown when the object does not belong to a valid pdf.
Parameters
ipIProperty of object.
indiObjOut parameter wheren indirect object will be saved, because finding the object can be an expensive operation.

Definition at line 57 of file cobject.cc.

References pdfobjects::IProperty::getIndiRef(), pdfobjects::IProperty::getPdf(), pdfobjects::hasValidPdf(), and pdfobjects::hasValidPdf().

Referenced by pdfobjects::IProperty::dispatchChange(), and objHasParent().

bool pdfobjects::utils::objHasParent ( const IProperty &  ip)

Returns true if object has a parent.

Exceptions
ObjInvalidOperationThrown when the object does not belong to a valid pdf.
Parameters
ipIProperty of object.

Definition at line 71 of file cobject.cc.

References objHasParent().

ostream& pdfobjects::utils::operator<< ( ostream &  stream,
PageTreeNodeType  nodeType 
)

Operator for output stream with PageTreeNodeType enumeration type.

Parameters
streamStream, where to print.
nodeTypetype to print.

Prints human readable from of page tree node enumeration value.

Returns
reference to given stream.

Definition at line 60 of file cpdf.cc.

References ErrorNode, InterNode, LeafNode, RootNode, and UnknownNode.

template<typename T >
void pdfobjects::utils::parseStreamToContainer ( T &  container,
const ::Object obj 
)
template void pdfobjects::utils::parseStreamToContainer< CStream::Buffer > ( CStream::Buffer &  container,
const ::Object obj 
)
void pdfobjects::utils::printProperty ( boost::shared_ptr< IProperty >  ip,
std::ostream &  out 
)

Helper method for property printing.

Parameters
ipProperty to print.
outOutput stream, where to print (implicit value is std::cout).

Gets string representation of given property and dumps it to standard output. Checks whether this functionality is duplicated.

Definition at line 146 of file cobjecthelpers.cc.

size_t pdfobjects::utils::searchTreeNode ( shared_ptr< const CPdf >  pdf,
shared_ptr< CDict >  superNode,
shared_ptr< CDict >  node,
size_t  startValue,
PageTreeNodeCountCache *  cache 
)

Searches node in page tree structure.

Parameters
pdfPdf where to search.
superNodePage tree node where to search (may be intermediate or leaf).
nodeNode to search for.
startValuePosition of the superNode.
cacheCache for reference to page count mapping.

At first checks if node and superNode are same nodes (uses == operator to compare) and if so, returns startPos. Otherwise tries to get node type (uses getNodeType helper function). In Page case (LeafNode) returns with startValue if given nodes are same or 0 (page not found). This the end of recursion. If it is intermediate node, goes through Kids array and recursively calls this method for each element until recursion returns with non 0 result. This means the end of recursion. startValue is actualized for each Kid's element with 0 recursion return value (Leaf node element increases by 1, intermediate node element by getKidsCount value).
If node is found as direct Kids member (this means that reference of target node is direct member of Kids array), then determines if the node position is unambiguous - checks whether reference to the node is unique in Kids array. If not throws exception. This means that searchTreeNode function is not able to definitively determine node's position.
Function tries to find node position also in page tree structure which doesn't follow pdf specification. All wierd page tree elements are ignored and just those which may stand for intermediate or leaf nodes are considered. Also doesn't use Count and Parent fields information during searching.
Uses getKidsCount function internally to get intermediate leaf nodes count. getKidsCount method requieres also cache parameter which stores already known nodes to their counts mapping. This function just delegates given cache parameter to getPageCount and doesn't care for it much more. Note that if parameter is NULL, cache is not used.

Exceptions
AmbiguousPageTreeExceptionif page tree is ambiguous and node position can't be determined.
Returns
Position of the node or 0 if node couldn't be found under this superNode.

Definition at line 634 of file cpdf.cc.

References getKidsCount(), getKidsFromInterNode(), getNodeType(), getNodeType(), i, i, i, i, i, i, InterNode, InterNode, pdfobjects::isRef(), pdfobjects::isRef(), LeafNode, LeafNode, LeafNode, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, and utilsPrintDbg.

Referenced by getNodePosition().

template<typename IP >
void pdfobjects::utils::setDoubleInArray ( const IP &  ip,
size_t  position,
double  val 
)
inline

Set double in array.

Definition at line 612 of file carray.h.

References setIntInArray().

template<typename IP >
void pdfobjects::utils::setDoubleInDict ( const IP &  ip,
const std::string &  name,
double  val 
)
inline

Set double in dictioary.

Definition at line 831 of file cdict.h.

References name, and setIntInDict().

template<typename IP >
void pdfobjects::utils::setIntInArray ( const IP &  ip,
size_t  position,
int  val 
)
inline

Set int in array.

Definition at line 606 of file carray.h.

Referenced by setDoubleInArray().

template<typename IP >
void pdfobjects::utils::setIntInDict ( const IP &  ip,
const std::string &  name,
int  val 
)
inline

Set int in dictionary.

Definition at line 823 of file cdict.h.

References name.

Referenced by setDoubleInDict().

template<typename Value , typename ItemType , PropertyType ItemPType>
void pdfobjects::utils::setSimpleValueInArray ( const CArray &  array,
size_t  position,
const Value val 
)
inline

Set simple value in array. If it is a reference, set fetch it and set it to the fetched object.

Parameters
arrayArray property.
positionPosition in the array.
valValue to be written.

Definition at line 523 of file carray.h.

References debug::DBG_DBG, pdfobjects::CArray::getProperty(), getReferencedObject(), and utilsPrintDbg.

template<typename ItemType >
void pdfobjects::utils::setSimpleValueInArray ( const CArray &  array,
size_t  position,
const typename ItemType::Value val 
)
inline

Sets simple value to array element. Uses setValueToSimple function to set property value.

Parameters
arrayArray property.
positionPosition of element to set.
valSimple value to set.

Definition at line 545 of file carray.h.

References debug::DBG_DBG, pdfobjects::CArray::getProperty(), getReferencedObject(), and utilsPrintDbg.

template<typename Value , typename ItemType , PropertyType ItemPType>
void pdfobjects::utils::setSimpleValueInArray ( const IProperty &  array,
size_t  position,
const Value val 
)
inline

Set simple value in array. If it is a reference, set fetch it and set it to the fetched object.

Parameters
arrayArray property.
positionPosition in the array.
valValue to be written.

Definition at line 566 of file carray.h.

References pdfobjects::isArray(), and pdfobjects::isArray().

template<typename ItemType >
void pdfobjects::utils::setSimpleValueInArray ( const IProperty &  ip,
size_t  position,
const typename ItemType::Value val 
)
inline

Sets simple value to array element. Checks given property type and if it is pArray, casts it to CArray and calls setSimpleValueInArray with CArray parameter.

Parameters
ipArray property.
positionPosition of element to set.
valSimple value to set.
Exceptions
ElementBadTypeExceptionif given property is not CArray instance.

Definition at line 592 of file carray.h.

References pdfobjects::isArray().

template<typename Value , typename ItemType , PropertyType ItemPType>
void pdfobjects::utils::setSimpleValueInDict ( const CDict &  dict,
const std::string &  name,
const Value val 
)
inline

Set simple value in dictionary. If it is a reference, set fetch it and set it to the fetched object.

Parameters
dictDict property.
nameName of property.
valValue to be written.

Definition at line 747 of file cdict.h.

References debug::DBG_DBG, pdfobjects::CDict::getProperty(), getReferencedObject(), and utilsPrintDbg.

template<typename ItemType >
void pdfobjects::utils::setSimpleValueInDict ( const CDict &  dict,
CDict::PropertyId  name,
const typename ItemType::Value val 
)
inline

Sets value of property with given name.

Gets property with given name and dereference (uses getReferencedObject) it (if it is reference) and sets its value (uses setValueToSimple).

Parameters
dictDictionary.
nameProperty name.
valValue for property.

Definition at line 771 of file cdict.h.

References debug::DBG_DBG, pdfobjects::CDict::getProperty(), getReferencedObject(), and utilsPrintDbg.

template<typename Value , typename ItemType , PropertyType ItemPType>
void pdfobjects::utils::setSimpleValueInDict ( const IProperty &  dict,
const std::string &  name,
const Value val 
)
inline

Set simple value in dictionary. If it is a reference, set fetch it and set it to the fetched object.

Parameters
dictDict property.
nameName of property.
valValue to be written.

Definition at line 792 of file cdict.h.

References pdfobjects::isDict(), pdfobjects::isDict(), and name.

template<typename ItemType >
void pdfobjects::utils::setSimpleValueInDict ( const IProperty &  ip,
CDict::PropertyId  name,
const typename ItemType::Value val 
)
inline

Set simple value in dictionary. If it is a reference, set fetch it and set it to the fetched object.

Parameters
dictDict property.
nameName of property.
valValue to be written.

Definition at line 809 of file cdict.h.

References pdfobjects::isDict(), and name.

template<typename ItemType , PropertyType ItemPType, typename Value >
void pdfobjects::utils::setValueToSimple ( const boost::shared_ptr< IProperty > &  ip,
const Value val 
)
inline

Set simple value.

Parameters
ipIProperty.
valValue to set.

Definition at line 661 of file cobjectsimple.h.

References debug::DBG_DBG, and utilsPrintDbg.

template<typename SimpleClass , PropertyType SimpleType>
bool pdfobjects::utils::simpleEquals ( const boost::shared_ptr< IProperty > &  val1,
const boost::shared_ptr< IProperty > &  val2 
)
throw (
)

Compares two simple values.

Parameters
val1value to compare.
val2value to compare.

Helper methods for simple value comparing. Uses getValueFromSimple method to get value from property. Simple properties are same if values, which they holds are same.
SimpleClass template parameter stands for property class type (CRef, CInt, ...)
simpleType is property type - constant value returned by getType() method.

NOTE: no checking of parameters is done here.

Definition at line 169 of file cobjecthelpers.cc.

References Value, and Value.

void pdfobjects::utils::simpleValueFromString ( const std::string &  str,
bool &  val 
)

Parses string to get simple values like int, name, bool etc.

Parameters
strString to be parsed.
valDesired value.
Exceptions
ObjBadValueEThrown when the string, can't be parsed correctly.

Definition at line 55 of file cobject2string.cc.

References nocase_compare(), and nocase_compare().

Referenced by add_ref(), pdfobjects::ContentsChangeTag::getTime(), main(), main(), main(), pdfobjects::CObjectSimple< Tp >::setStringRepresentation(), and pdfobjects::CObjectSimple< Tp >::setStringRepresentation().

void pdfobjects::utils::simpleValueFromString ( const std::string &  str,
int &  val 
)

Definition at line 69 of file cobject2string.cc.

void pdfobjects::utils::simpleValueFromString ( const std::string &  str,
double &  val 
)

Definition at line 82 of file cobject2string.cc.

References objInt, objReal, objReal, and xpdfObjFromString().

void pdfobjects::utils::simpleValueFromString ( const std::string &  str,
std::string &  val 
)

Definition at line 94 of file cobject2string.cc.

void pdfobjects::utils::simpleValueFromString ( const std::string &  str,
IndiRef &  val 
)

Definition at line 100 of file cobject2string.cc.

References pdfobjects::IndiRef::gen, and pdfobjects::IndiRef::num.

template<PropertyType Tp, typename T >
void pdfobjects::utils::simpleValueFromXpdfObj ( const ::Object obj,
val 
)

Save real xpdf object value to val.

Parameters
objXpdf object which holds the value.
valVariable where the value will be stored.
template<PropertyType Tp, typename T >
void pdfobjects::utils::simpleValueFromXpdfObj ( const Object obj,
val 
)

Definition at line 715 of file cobject2xpdf.cc.

template<>
void pdfobjects::utils::simpleValueFromXpdfObj< pNull, NullType & > ( const Object ,
NullType &   
)
inline

Definition at line 726 of file cobject2xpdf.cc.

template<PropertyType Tp>
void pdfobjects::utils::simpleValueToString ( const std::string &  val,
std::string &  str 
)
template<PropertyType Tp>
void pdfobjects::utils::simpleValueToString ( bool  val,
std::string &  str 
)

Return simple xpdf object (null,number,string...) in string representation.

REMARK: String can represent more different objects, so we have to distinguish among them. This is done at compile time with use of templates, but because of this we have to make other functions also template.

Parameters
valthat will be converted to string.
strstring.
template<PropertyType Tp>
void pdfobjects::utils::simpleValueToString ( int  val,
std::string &  str 
)

template<PropertyType Tp>
void pdfobjects::utils::simpleValueToString ( double  val,
std::string &  str 
)

template<PropertyType Tp>
void pdfobjects::utils::simpleValueToString ( const NullType &  val,
std::string &  str 
)

template<PropertyType Tp>
void pdfobjects::utils::simpleValueToString ( const IndiRef &  val,
std::string &  str 
)

template<>
void pdfobjects::utils::simpleValueToString< pBool > ( bool  val,
string &  str 
)

Definition at line 125 of file cobject2string.cc.

template<>
void pdfobjects::utils::simpleValueToString< pInt > ( int  val,
string &  str 
)

Definition at line 134 of file cobject2string.cc.

References snprintf.

template void pdfobjects::utils::simpleValueToString< pName > ( const string &  val,
string &  str 
)
template<>
void pdfobjects::utils::simpleValueToString< pNull > ( const NullType &  ,
string &  str 
)

Definition at line 194 of file cobject2string.cc.

template<>
void pdfobjects::utils::simpleValueToString< pReal > ( double  val,
string &  str 
)

Definition at line 168 of file cobject2string.cc.

References snprintf, and trim_trailing_zero().

template<>
void pdfobjects::utils::simpleValueToString< pRef > ( const IndiRef &  ref,
string &  str 
)

Definition at line 203 of file cobject2string.cc.

template void pdfobjects::utils::simpleValueToString< pString > ( const string &  val,
string &  str 
)

Referenced by stringToCharBuffer().

template<PropertyType Tp, typename T >
Object * pdfobjects::utils::simpleValueToXpdfObj ( val)

Create xpdf Object which represents value.

Parameters
valValue where the value is stored.
Returns
Xpdf object where the value is stored.

Definition at line 694 of file cobject2xpdf.cc.

References pdfobjects::XPdfObjectFactory::getInstance().

template Object* pdfobjects::utils::simpleValueToXpdfObj< pBool, const bool & > ( const bool &  val)
template Object* pdfobjects::utils::simpleValueToXpdfObj< pInt, const int & > ( const int &  val)
template Object* pdfobjects::utils::simpleValueToXpdfObj< pName, const string & > ( const string &  val)
template Object* pdfobjects::utils::simpleValueToXpdfObj< pNull, const NullType & > ( const NullType &  val)
template Object* pdfobjects::utils::simpleValueToXpdfObj< pReal, const double & > ( const double &  val)
template Object* pdfobjects::utils::simpleValueToXpdfObj< pString, const string & > ( const string &  val)
size_t pdfobjects::utils::streamToCharBuffer ( const Object streamObject,
Ref ref,
CharBuffer outputBuf,
stream_data_extractor  extractor 
)

Makes a valid pdf indirect object representation of stream object.

Parameters
streamObjectXpdf object representing stream.
refReference for this indirect object.
outputBufOutput byte buffer containing complete representation.
extractorFunction to be used to extract data from the object's stream.

Allocates and fills buffer in given outputBuf with pdf object format representation of given stream object. Moreover adds indirect header and footer if ref is non NULL.
If you want some filters to be used to encode stream data, use extractor function parameter for this purpose. bufferFromStreamData used by default returns stream data without any filters applied.
Given buffer may contain NUL bytes inside. Caller should consume number of returned bytes from outputBuf.

Returns
number of bytes used in outputBuf or 0 if problem occures.

Definition at line 957 of file cobject2xpdf.cc.

References char_buffer_new(), pdfobjects::Specification::CSTREAM_FOOTER, pdfobjects::Specification::CSTREAM_FOOTER, pdfobjects::Specification::CSTREAM_FOOTER, pdfobjects::Specification::CSTREAM_FOOTER, xpdf::freeXpdfObject(), pdfobjects::XPdfObjectFactory::getInstance(), pdfobjects::XPdfObjectFactory::getInstance(), Object::getStream(), Object::getType(), Object::getType(), pdfobjects::Specification::INDIRECT_FOOTER, pdfobjects::Specification::INDIRECT_HEADER, Object::streamGetDict(), Object::streamGetDict(), utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, utilsPrintDbg, and xpdfObjToString().

Referenced by pdfobjects::utils::NullFilterStreamWriter::compress(), and pdfobjects::utils::ZlibFilterStreamWriter::compress().

template<typename ITERATOR , typename OUTITERATOR >
void pdfobjects::utils::streamToString ( const std::string &  strDict,
ITERATOR  begin,
ITERATOR  end,
OUTITERATOR  out 
)

CStream object to string

Parameters
strDictDictionary string representation.
beginBuffer begin
endBuffer end
outOutput string.

Definition at line 132 of file cobject.cc.

References pdfobjects::Specification::CSTREAM_FOOTER, pdfobjects::Specification::CSTREAM_FOOTER, pdfobjects::Specification::CSTREAM_HEADER, and pdfobjects::Specification::CSTREAM_HEADER.

Referenced by pdfobjects::CStream::getStringRepresentation().

template void pdfobjects::utils::streamToString< CStream::Buffer::const_iterator, std::back_insert_iterator< std::string > > ( const std::string &  strDict,
CStream::Buffer::const_iterator  begin,
CStream::Buffer::const_iterator  end,
std::back_insert_iterator< std::string >  out 
)
size_t pdfobjects::utils::stringToCharBuffer ( Object stringObject,
CharBuffer outputBuf 
)

Makes a valid pdf representation of xpdf string object.

Parameters
stringObjectXpdf object with objString type.
outputBufOutput buffer where final representation is stored.

This method creates correct pdf representation of given xpdf string object. It should be used for string objects which may contain NUL characters inside. Otherwise simpleValueToString method can be used.

Returns
Number of bytes stored in outputBuf.

Definition at line 157 of file cobject.cc.

References GString::append(), char_buffer_new(), Object::getString(), Object::getType(), Object::getType(), i, i, i, i, i, i, i, i, i, simpleValueToString< pString >(), utilsPrintDbg, and utilsPrintDbg.

void pdfobjects::utils::stripXRefStreamFields ( const Object trailer)

Helper function for trailer cleanup from xref stream entries.

Parameters
trailerTrailerClenaup.

Get rid all entries which could come from xref stream dictionary.

Definition at line 556 of file pdfwriter.cc.

References Object::dictDel(), Object::dictLookupNF(), Object::free(), xpdf::freeXpdfObject(), Object::getType(), i, i, i, i, NULL, and utilsPrintDbg.

Referenced by pdfobjects::utils::OldStylePdfWriter::writeTrailer().

void pdfobjects::utils::trim_trailing_zero ( char *  number_str)

Removes trailing zeros from given number in string form.

Parameters
number_strNumber in string representation.

Note that number must be in [-+]nnnn.nnnn form.

Definition at line 148 of file cobject2string.cc.

Referenced by simpleValueToString< pReal >().

bool pdfobjects::utils::typeSafeTrailerEntry ( const char *  name,
::Object value,
XRef xref 
)

Checks whether given name, value pair is valid for Trailer entry.

Parameters
nameName for the Trailer entry (must be non NULL).
valueValue to be set for Trailer entry.
xrefXref for value fetching.
Returns
true if the given pair is valid, false otherwise.

Definition at line 301 of file xrefwriter.cc.

References XRef::fetch(), Object::fetch(), pdfobjects::XPdfObjectFactory::getInstance(), pdfobjects::XPdfObjectFactory::getInstance(), Object::getRefGen(), Object::getRefNum(), Object::getType(), Object::getType(), Object::getType(), Object::getType(), Object::getType(), Object::getType(), kernelPrintDbg, kernelPrintDbg, kernelPrintDbg, kernelPrintDbg, kernelPrintDbg, objArray, objDict, objDict, objInt, and objRef.

Referenced by pdfobjects::XRefWriter::changeTrailer().

void pdfobjects::utils::writeObject ( const ::Object obj,
StreamWriter stream,
::Ref ref,
bool  indirect 
)

Helper method for xpdf object writing to the stream.

Parameters
objXpdf object to write.
refObject's reference (NULL for indirect object).
streamStream where to write.
indirectFlag for indirect object

Creates correct pdf string representation of given object, adds indirect header and footer if indirect flag is specified and writes everything to the given stream.
Given xpdf object data (like stream or string) can contain unprintable or 0 bytes.

Definition at line 421 of file pdfwriter.cc.

References char_buffer_new(), createIndirectObjectStringFromString(), createObjFromXpdfObj(), pdfobjects::utils::FilterStreamWriter::getInstance(), i, i, i, i, i, and StreamWriter::putLine().

Referenced by pdfobjects::utils::OldStylePdfWriter::writeContent(), and pdfobjects::utils::OldStylePdfWriter::writeTrailer().

::Object* pdfobjects::utils::xpdfObjFromString ( const std::string &  str,
::XRef xref = NULL 
)

Create xpdf object from string.

Parameters
strString that should represent an xpdf object.
xrefXref of actual pdf if any.
Returns
Xpdf object whose string representation is in str.
::Object* pdfobjects::utils::xpdfObjFromString ( const std::string &  str,
XRef xref 
)
void pdfobjects::utils::xpdfObjToString ( Object obj,
std::string &  str 
)

Convert xpdf object to string

Parameters
objXpdf object that will be converted.
strThis will hold the string representation of the object.

Referenced by ip_validate(), ip_validate(), operator<<(), and streamToCharBuffer().

void pdfobjects::utils::xpdfObjToString ( Object obj,
string &  str 
)

Definition at line 557 of file cobject2xpdf.cc.

References Object::getType(), objArray, objDict, and objStream.

Object * pdfobjects::utils::xpdfStreamObjFromBuffer ( const CStream::Buffer &  buffer,
const CDict &  dict 
)