Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

pdf::core::CFile Class Reference

a PDF file. More...

#include <File.hh>

List of all members.

Public Types

Public Methods

Private Types

Private Attributes


Detailed Description

a PDF file.

the PDF file class contains a list of PDF referenced objects. objects are added to the file to register an object identifier and become a referenced object. the main purpose of this class is to generate identifier number of the objects.


Member Typedef Documentation

typedef std::vector<boost::shared_ptr<CRefObj> > pdf::core::CFile::CObjVec [private]
 

just shortcut

typedef CObjVec::const_iterator pdf::core::CFile::iterator
 

immutable iterator

typedef CObjVec::value_type pdf::core::CFile::value_type
 

shortcut


Constructor & Destructor Documentation

pdf::core::CFile::CFile  
 

constructor do nothing

00041 {
00042 }

pdf::core::CFile::~CFile  
 

destructor also do nothing

00047 {
00048 }


Member Function Documentation

const CObjRef pdf::core::CFile::AddObj CObject   object
 

this function will register an identifier to an object and add it to the file. the identifier is base on the number of object added. the reference to the object is returned.

Returns:
the reference to the object

00057 {
00058     CRefObj *ref = new CRefObj( m_objects.size( ) + 1, object ) ;
00059     m_objects.push_back( boost::shared_ptr<CRefObj>( ref ) ) ;
00060     
00061     return ref->GetRef( ) ;
00062 }

std::ostream & pdf::core::CFile::Write std::ostream &    file,
const CObjRef   catalog,
const CObjRef   doc_info
const
 

write the whole PDF file into a output stream. this function will write all the PDF file header, the PDF objects it contains and the PDF trailer to the file.

Parameters:
file  the output stream. can be any stream except standard output.
catalog  the reference of the PDF catalog object. it must appear in the trailer.
doc_info  a reference to the PDF document info dictionary. it is optional. if it is null, the document has no info dictionary.
Exceptions:
pdf::util::CFileError  object if file.tellp() returns -1. using byte stream (e.g. cout, pipes/fifo or sockets) as file will cause this. use normal file instead.

00080 {
00081     using namespace std ;
00082 
00083     // PDF version string
00084     file << "%PDF-1.4" << endl ;
00085     
00086     // write a 4 byte binary data comment
00087     char comment[] = "%\xfa\xce\xbe\xad" ;
00088     file << comment << endl ;
00089 
00090     std::vector<int> offsets ;
00091 
00092     for ( iterator i = m_objects.begin( ) ; i != m_objects.end( ) ; ++i )
00093     {
00094         streampos p = file.tellp( ) ;
00095         
00096         // if we tellp( ) fails, throw exception
00097         if ( p == streampos( -1 ) )
00098             throw util::CFileError( "cannot get offset of output file" ) ;
00099         
00100         // save the file position
00101         offsets.push_back( p ) ;
00102         
00103         // write the object to the file
00104         file << **i ;
00105     }
00106 
00107     streampos xref_offset = file.tellp( ) ;
00108     if ( xref_offset == streampos( -1 ) )
00109             throw util::CFileError( "cannot get offset of output file" ) ;
00110         
00111     file << "xref\n0 " << offsets.size( ) + 1
00112          << "\n0000000000 65535 f \n" ;
00113         
00114     for ( std::vector<int>::iterator i = offsets.begin( ) ;
00115                                      i != offsets.end( ) ; ++i )
00116     {
00117         file << setw( 10 ) << setfill( '0' ) << *i
00118              << " 00000 n \n" ;
00119     }
00120 
00121     CDictionary trailer ;
00122     trailer.AddPair( "Size", new CNumber( offsets.size( ) + 1 ) ) ;
00123     trailer.AddPair( "Root", catalog.Dup( ) ) ;
00124 
00125     if ( doc_info != 0 )
00126         trailer.AddPair( "Info", doc_info->Dup( ) ) ;
00127 
00128     file << "trailer\n" << trailer << endl ;
00129 
00130     file << "startxref" << endl
00131          << xref_offset << endl
00132          << "%%EOF" << endl ;
00133 
00134     return file ;
00135 }

CObject * pdf::core::CFile::operator[] const CObjRef   ref
 

access to the contained objects via its identifier.

00140 {
00141     CObjVec::size_type index = ref.ID( ) - 1 ;
00142     assert( index >= 0 && index < m_objects.size( ) ) ;
00143 
00144     return m_objects[index].get( ) ;
00145 }

const CObject * pdf::core::CFile::operator[] const CObjRef   ref const
 

access to the contained objects via its identifier.

00150 {
00151     CObjVec::size_type index = ref.ID( ) - 1 ;
00152     assert( index >= 0 && index < m_objects.size( ) ) ;
00153 
00154     return m_objects[index].get( ) ;
00155 }


Member Data Documentation

CObjVec pdf::core::CFile::m_objects [private]
 

the list of objects


The documentation for this class was generated from the following files:
Generated on Sun Feb 2 09:17:12 2003 for libpdf++ by doxygen1.2.16