1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
24 //------------------------------------------------------------------------
26 //------------------------------------------------------------------------
37 // Constructor. Read xref table from stream.
38 XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword);
43 // Is xref table valid?
44 GBool isOk() { return ok; }
46 // Get the error code (if isOk() returns false).
47 int getErrorCode() { return errCode; }
49 // Is the file encrypted?
51 GBool isEncrypted() { return encrypted; }
53 GBool isEncrypted() { return gFalse; }
56 // Check various permissions.
57 GBool okToPrint(GBool ignoreOwnerPW = gFalse);
58 GBool okToChange(GBool ignoreOwnerPW = gFalse);
59 GBool okToCopy(GBool ignoreOwnerPW = gFalse);
60 GBool okToAddNotes(GBool ignoreOwnerPW = gFalse);
62 // Get catalog object.
63 Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
65 // Fetch an indirect reference.
66 Object *fetch(int num, int gen, Object *obj);
68 // Return the document's Info dictionary (if any).
69 Object *getDocInfo(Object *obj);
70 Object *getDocInfoNF(Object *obj);
72 // Return the number of objects in the xref table.
73 int getNumObjects() { return size; }
75 // Return the offset of the last xref table.
76 Guint getLastXRefPos() { return lastXRefPos; }
78 // Return the catalog object reference.
79 int getRootNum() { return rootNum; }
80 int getRootGen() { return rootGen; }
82 // Get end position for a stream in a damaged file.
83 // Returns false if unknown or file is not damaged.
84 GBool getStreamEnd(Guint streamStart, Guint *streamEnd);
87 int getSize() { return size; }
88 XRefEntry *getEntry(int i) { return &entries[i]; }
89 Object *getTrailerDict() { return &trailerDict; }
93 BaseStream *str; // input stream
94 Guint start; // offset in file (to allow for garbage
95 // at beginning of file)
96 XRefEntry *entries; // xref entries
97 int size; // size of <entries> array
98 int rootNum, rootGen; // catalog dict
99 GBool ok; // true if xref table is valid
100 int errCode; // error code (if <ok> is false)
101 Object trailerDict; // trailer dictionary
102 Guint lastXRefPos; // offset of last xref table
103 Guint *streamEnds; // 'endstream' positions - only used in
105 int streamEndsLen; // number of valid entries in streamEnds
106 #ifndef NO_DECRYPTION
107 GBool encrypted; // true if file is encrypted
108 int encVersion; // encryption algorithm
109 int encRevision; // security handler revision
110 int keyLength; // length of key, in bytes
111 int permFlags; // permission bits
112 Guchar fileKey[16]; // file decryption key
113 GBool ownerPasswordOk; // true if owner password is correct
117 GBool readXRef(Guint *pos);
118 GBool constructXRef();
119 GBool checkEncrypted(GString *ownerPassword, GString *userPassword);
120 Guint strToUnsigned(char *s);