filters

XRef.h
1//========================================================================
2//
3// XRef.h
4//
5// Copyright 1996-2002 Glyph & Cog, LLC
6//
7//========================================================================
8
9#ifndef XREF_H
10#define XREF_H
11
12#include <aconf.h>
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include "gtypes.h"
19#include "Object.h"
20
21class Dict;
22class Stream;
23
24//------------------------------------------------------------------------
25// XRef
26//------------------------------------------------------------------------
27
28struct XRefEntry {
29 Guint offset;
30 int gen;
31 GBool used;
32};
33
34class XRef {
35public:
36
37 // Constructor. Read xref table from stream.
38 XRef(BaseStream *strA, GString *ownerPassword, GString *userPassword);
39
40 // Destructor.
41 ~XRef();
42
43 // Is xref table valid?
44 GBool isOk() { return ok; }
45
46 // Get the error code (if isOk() returns false).
47 int getErrorCode() { return errCode; }
48
49 // Is the file encrypted?
50#ifndef NO_DECRYPTION
51 GBool isEncrypted() { return encrypted; }
52#else
53 GBool isEncrypted() { return gFalse; }
54#endif
55
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);
61
62 // Get catalog object.
63 Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
64
65 // Fetch an indirect reference.
66 Object *fetch(int num, int gen, Object *obj);
67
68 // Return the document's Info dictionary (if any).
69 Object *getDocInfo(Object *obj);
70 Object *getDocInfoNF(Object *obj);
71
72 // Return the number of objects in the xref table.
73 int getNumObjects() { return size; }
74
75 // Return the offset of the last xref table.
76 Guint getLastXRefPos() { return lastXRefPos; }
77
78 // Return the catalog object reference.
79 int getRootNum() { return rootNum; }
80 int getRootGen() { return rootGen; }
81
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);
85
86 // Direct access.
87 int getSize() { return size; }
88 XRefEntry *getEntry(int i) { return &entries[i]; }
89 Object *getTrailerDict() { return &trailerDict; }
90
91private:
92
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
104 // damaged files
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
114#endif
115
116 Guint readTrailer();
117 GBool readXRef(Guint *pos);
118 GBool constructXRef();
119 GBool checkEncrypted(GString *ownerPassword, GString *userPassword);
120 Guint strToUnsigned(char *s);
121};
122
123#endif