1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
26 //------------------------------------------------------------------------
28 //------------------------------------------------------------------------
32 xrefEntryUncompressed,
45 // Constructor. Read xref table from stream.
46 XRef(BaseStream *strA);
51 // Is xref table valid?
52 GBool isOk() { return ok; }
54 // Get the error code (if isOk() returns false).
55 int getErrorCode() { return errCode; }
57 // Set the encryption parameters.
58 void setEncryption(int permFlagsA, GBool ownerPasswordOkA,
59 Guchar *fileKeyA, int keyLengthA, int encVersionA);
61 // Is the file encrypted?
62 GBool isEncrypted() { return encrypted; }
64 // Check various permissions.
65 GBool okToPrint(GBool ignoreOwnerPW = gFalse);
66 GBool okToChange(GBool ignoreOwnerPW = gFalse);
67 GBool okToCopy(GBool ignoreOwnerPW = gFalse);
68 GBool okToAddNotes(GBool ignoreOwnerPW = gFalse);
70 // Get catalog object.
71 Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
73 // Fetch an indirect reference.
74 Object *fetch(int num, int gen, Object *obj);
76 // Return the document's Info dictionary (if any).
77 Object *getDocInfo(Object *obj);
78 Object *getDocInfoNF(Object *obj);
80 // Return the number of objects in the xref table.
81 int getNumObjects() { return size; }
83 // Return the offset of the last xref table.
84 Guint getLastXRefPos() { return lastXRefPos; }
86 // Return the catalog object reference.
87 int getRootNum() { return rootNum; }
88 int getRootGen() { return rootGen; }
90 // Get end position for a stream in a damaged file.
91 // Returns false if unknown or file is not damaged.
92 GBool getStreamEnd(Guint streamStart, Guint *streamEnd);
95 int getSize() { return size; }
96 XRefEntry *getEntry(int i) { return &entries[i]; }
97 Object *getTrailerDict() { return &trailerDict; }
101 BaseStream *str; // input stream
102 Guint start; // offset in file (to allow for garbage
103 // at beginning of file)
104 XRefEntry *entries; // xref entries
105 int size; // size of <entries> array
106 int rootNum, rootGen; // catalog dict
107 GBool ok; // true if xref table is valid
108 int errCode; // error code (if <ok> is false)
109 Object trailerDict; // trailer dictionary
110 Guint lastXRefPos; // offset of last xref table
111 Guint *streamEnds; // 'endstream' positions - only used in
113 int streamEndsLen; // number of valid entries in streamEnds
114 ObjectStream *objStr; // cached object stream
115 GBool encrypted; // true if file is encrypted
116 int permFlags; // permission bits
117 GBool ownerPasswordOk; // true if owner password is correct
118 Guchar fileKey[16]; // file decryption key
119 int keyLength; // length of key, in bytes
120 int encVersion; // encryption algorithm
122 Guint getStartXref();
123 GBool readXRef(Guint *pos);
124 GBool readXRefTable(Parser *parser, Guint *pos);
125 GBool readXRefStreamSection(Stream *xrefStr, int *w, int first, int n);
126 GBool readXRefStream(Stream *xrefStr, Guint *pos);
127 GBool constructXRef();
128 Guint strToUnsigned(char *s);