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

XRef.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // XRef.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef XREF_H
00010 #define XREF_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include "gtypes.h"
00019 #include "Object.h"
00020 
00021 class Dict;
00022 class Stream;
00023 namespace xpdf 
00024 {
00025   class Parser;
00026 }
00027 
00028 
00029 class ObjectStream;
00030 
00031 //------------------------------------------------------------------------
00032 // XRef
00033 //------------------------------------------------------------------------
00034 
00035 enum XRefEntryType {
00036   xrefEntryFree,
00037   xrefEntryUncompressed,
00038   xrefEntryCompressed
00039 };
00040 
00041 struct XRefEntry {
00042   Guint offset;
00043   int gen;
00044   XRefEntryType type;
00045 };
00046 
00047 class XRef {
00048 public:
00049 
00050   // Constructor.  Read xref table from stream.
00051   XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword);
00052 
00053   // Destructor.
00054   ~XRef();
00055 
00056   // Is xref table valid?
00057   GBool isOk() { return ok; }
00058 
00059   // Get the error code (if isOk() returns false).
00060   int getErrorCode() { return errCode; }
00061 
00062   // Is the file encrypted?
00063 #ifndef NO_DECRYPTION
00064   GBool isEncrypted() { return encrypted; }
00065 #else
00066   GBool isEncrypted() { return gFalse; }
00067 #endif
00068 
00069   // Check various permissions.
00070   GBool okToPrint(GBool ignoreOwnerPW = gFalse);
00071   GBool okToChange(GBool ignoreOwnerPW = gFalse);
00072   GBool okToCopy(GBool ignoreOwnerPW = gFalse);
00073   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse);
00074 
00075   // Get catalog object.
00076   Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
00077 
00078   // Fetch an indirect reference.
00079   Object *fetch(int num, int gen, Object *obj);
00080 
00081   // Return the document's Info dictionary (if any).
00082   Object *getDocInfo(Object *obj);
00083   Object *getDocInfoNF(Object *obj);
00084 
00085   // Return the number of objects in the xref table.
00086   int getNumObjects() { return size; }
00087 
00088   // Return the offset of the last xref table.
00089   Guint getLastXRefPos() { return lastXRefPos; }
00090 
00091   // Return the catalog object reference.
00092   int getRootNum() { return rootNum; }
00093   int getRootGen() { return rootGen; }
00094 
00095   // Get end position for a stream in a damaged file.
00096   // Returns false if unknown or file is not damaged.
00097   GBool getStreamEnd(Guint streamStart, Guint *streamEnd);
00098 
00099   // Direct access.
00100   int getSize() { return size; }
00101   XRefEntry *getEntry(int i) { return &entries[i]; }
00102   Object *getTrailerDict() { return &trailerDict; }
00103 
00104 private:
00105 
00106   BaseStream *str;              // input stream
00107   Guint start;                  // offset in file (to allow for garbage
00108                                 //   at beginning of file)
00109   XRefEntry *entries;           // xref entries
00110   int size;                     // size of <entries> array
00111   int rootNum, rootGen;         // catalog dict
00112   GBool ok;                     // true if xref table is valid
00113   int errCode;                  // error code (if <ok> is false)
00114   Object trailerDict;           // trailer dictionary
00115   Guint lastXRefPos;            // offset of last xref table
00116   Guint *streamEnds;            // 'endstream' positions - only used in
00117                                 //   damaged files
00118   int streamEndsLen;            // number of valid entries in streamEnds
00119   ObjectStream *objStr;         // cached object stream
00120 #ifndef NO_DECRYPTION
00121   GBool encrypted;              // true if file is encrypted
00122   int encVersion;               // encryption algorithm
00123   int encRevision;              // security handler revision
00124   int keyLength;                // length of key, in bytes
00125   int permFlags;                // permission bits
00126   Guchar fileKey[16];           // file decryption key
00127   GBool ownerPasswordOk;        // true if owner password is correct
00128 #endif
00129 
00130   Guint getStartXref();
00131   GBool readXRef(Guint *pos);
00132   GBool readXRefTable(xpdf::Parser *parser, Guint *pos);
00133   GBool readXRefStreamSection(Stream *xrefStr, int *w, int first, int n);
00134   GBool readXRefStream(Stream *xrefStr, Guint *pos);
00135   GBool constructXRef();
00136   GBool checkEncrypted(GString *ownerPassword, GString *userPassword);
00137   Guint strToUnsigned(char *s);
00138 };
00139 
00140 #endif

Generated on Wed Nov 3 12:59:08 2004 for Lemur Toolkit by doxygen1.2.18