1 //========================================================================
5 // Copyright 1996-2002 Glyph & Cog, LLC
7 //========================================================================
22 //------------------------------------------------------------------------
24 //------------------------------------------------------------------------
35 // Constructor. Read xref table from stream.
36 XRef(BaseStream
*strA
, GString
*ownerPassword
, GString
*userPassword
);
41 // Is xref table valid?
42 GBool
isOk() { return ok
; }
44 // Get the error code (if isOk() returns false).
45 int getErrorCode() { return errCode
; }
47 // Is the file encrypted?
49 GBool
isEncrypted() { return encrypted
; }
51 GBool
isEncrypted() { return gFalse
; }
54 // Check various permissions.
55 GBool
okToPrint(GBool ignoreOwnerPW
= gFalse
);
56 GBool
okToChange(GBool ignoreOwnerPW
= gFalse
);
57 GBool
okToCopy(GBool ignoreOwnerPW
= gFalse
);
58 GBool
okToAddNotes(GBool ignoreOwnerPW
= gFalse
);
60 // Get catalog object.
61 Object
*getCatalog(Object
*obj
) { return fetch(rootNum
, rootGen
, obj
); }
63 // Fetch an indirect reference.
64 Object
*fetch(int num
, int gen
, Object
*obj
);
66 // Return the document's Info dictionary (if any).
67 Object
*getDocInfo(Object
*obj
);
68 Object
*getDocInfoNF(Object
*obj
);
70 // Return the number of objects in the xref table.
71 int getNumObjects() { return size
; }
73 // Return the offset of the last xref table.
74 Guint
getLastXRefPos() { return lastXRefPos
; }
76 // Return the catalog object reference.
77 int getRootNum() { return rootNum
; }
78 int getRootGen() { return rootGen
; }
80 // Get end position for a stream in a damaged file.
81 // Returns false if unknown or file is not damaged.
82 GBool
getStreamEnd(Guint streamStart
, Guint
*streamEnd
);
86 BaseStream
*str
; // input stream
87 Guint start
; // offset in file (to allow for garbage
88 // at beginning of file)
89 XRefEntry
*entries
; // xref entries
90 int size
; // size of <entries> array
91 int rootNum
, rootGen
; // catalog dict
92 GBool ok
; // true if xref table is valid
93 int errCode
; // error code (if <ok> is false)
94 Object trailerDict
; // trailer dictionary
95 Guint lastXRefPos
; // offset of last xref table
96 Guint
*streamEnds
; // 'endstream' positions - only used in
98 int streamEndsLen
; // number of valid entries in streamEnds
100 GBool encrypted
; // true if file is encrypted
101 int encVersion
; // encryption algorithm
102 int encRevision
; // security handler revision
103 int keyLength
; // length of key, in bytes
104 int permFlags
; // permission bits
105 Guchar fileKey
[16]; // file decryption key
106 GBool ownerPasswordOk
; // true if owner password is correct
110 GBool
readXRef(Guint
*pos
);
111 GBool
constructXRef();
112 GBool
checkEncrypted(GString
*ownerPassword
, GString
*userPassword
);
113 Guint
strToUnsigned(char *s
);