filters

XRef.h

00001 //========================================================================
00002 //
00003 // XRef.h
00004 //
00005 // Copyright 1996-2002 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 
00024 //------------------------------------------------------------------------
00025 // XRef
00026 //------------------------------------------------------------------------
00027 
00028 struct XRefEntry {
00029   Guint offset;
00030   int gen;
00031   GBool used;
00032 };
00033 
00034 class XRef {
00035 public:
00036 
00037   // Constructor.  Read xref table from stream.
00038   XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword);
00039 
00040   // Destructor.
00041   ~XRef();
00042 
00043   // Is xref table valid?
00044   GBool isOk() { return ok; }
00045 
00046   // Get the error code (if isOk() returns false).
00047   int getErrorCode() { return errCode; }
00048 
00049   // Is the file encrypted?
00050 #ifndef NO_DECRYPTION
00051   GBool isEncrypted() { return encrypted; }
00052 #else
00053   GBool isEncrypted() { return gFalse; }
00054 #endif
00055 
00056   // Check various permissions.
00057   GBool okToPrint(GBool ignoreOwnerPW = gFalse);
00058   GBool okToChange(GBool ignoreOwnerPW = gFalse);
00059   GBool okToCopy(GBool ignoreOwnerPW = gFalse);
00060   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse);
00061 
00062   // Get catalog object.
00063   Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
00064 
00065   // Fetch an indirect reference.
00066   Object *fetch(int num, int gen, Object *obj);
00067 
00068   // Return the document's Info dictionary (if any).
00069   Object *getDocInfo(Object *obj);
00070   Object *getDocInfoNF(Object *obj);
00071 
00072   // Return the number of objects in the xref table.
00073   int getNumObjects() { return size; }
00074 
00075   // Return the offset of the last xref table.
00076   Guint getLastXRefPos() { return lastXRefPos; }
00077 
00078   // Return the catalog object reference.
00079   int getRootNum() { return rootNum; }
00080   int getRootGen() { return rootGen; }
00081 
00082   // Get end position for a stream in a damaged file.
00083   // Returns false if unknown or file is not damaged.
00084   GBool getStreamEnd(Guint streamStart, Guint *streamEnd);
00085 
00086   // Direct access.
00087   int getSize() { return size; }
00088   XRefEntry *getEntry(int i) { return &entries[i]; }
00089   Object *getTrailerDict() { return &trailerDict; }
00090 
00091 private:
00092 
00093   BaseStream *str;      // input stream
00094   Guint start;          // offset in file (to allow for garbage
00095                 //   at beginning of file)
00096   XRefEntry *entries;       // xref entries
00097   int size;         // size of <entries> array
00098   int rootNum, rootGen;     // catalog dict
00099   GBool ok;         // true if xref table is valid
00100   int errCode;          // error code (if <ok> is false)
00101   Object trailerDict;       // trailer dictionary
00102   Guint lastXRefPos;        // offset of last xref table
00103   Guint *streamEnds;        // 'endstream' positions - only used in
00104                 //   damaged files
00105   int streamEndsLen;        // number of valid entries in streamEnds
00106 #ifndef NO_DECRYPTION
00107   GBool encrypted;      // true if file is encrypted
00108   int encVersion;       // encryption algorithm
00109   int encRevision;      // security handler revision
00110   int keyLength;        // length of key, in bytes
00111   int permFlags;        // permission bits
00112   Guchar fileKey[16];       // file decryption key
00113   GBool ownerPasswordOk;    // true if owner password is correct
00114 #endif
00115 
00116   Guint readTrailer();
00117   GBool readXRef(Guint *pos);
00118   GBool constructXRef();
00119   GBool checkEncrypted(GString *ownerPassword, GString *userPassword);
00120   Guint strToUnsigned(char *s);
00121 };
00122 
00123 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys