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