Initial revision
[swftools.git] / pdf2swf / xpdf / XRef.h
1 //========================================================================
2 //
3 // XRef.h
4 //
5 // Copyright 1996 Derek B. Noonburg
6 //
7 //========================================================================
8
9 #ifndef XREF_H
10 #define XREF_H
11
12 #ifdef __GNUC__
13 #pragma interface
14 #endif
15
16 #include "gtypes.h"
17 #include "Object.h"
18
19 class Dict;
20 class Stream;
21
22 //------------------------------------------------------------------------
23 // XRef
24 //------------------------------------------------------------------------
25
26 struct XRefEntry {
27   int offset;
28   int gen;
29   GBool used;
30 };
31
32 class XRef {
33 public:
34
35   // Constructor.  Read xref table from stream.
36   XRef(BaseStream *str, GString *userPassword);
37
38   // Destructor.
39   ~XRef();
40
41   // Is xref table valid?
42   GBool isOk() { return ok; }
43
44   // Is the file encrypted?
45 #ifndef NO_DECRYPTION
46   GBool isEncrypted() { return encrypted; }
47 #else
48   GBool isEncrypted() { return gFalse; }
49 #endif
50
51   // Check various permissions.
52   GBool okToPrint();
53   GBool okToChange();
54   GBool okToCopy();
55   GBool okToAddNotes();
56
57   // Get catalog object.
58   Object *getCatalog(Object *obj) { return fetch(rootNum, rootGen, obj); }
59
60   // Fetch an indirect reference.
61   Object *fetch(int num, int gen, Object *obj);
62
63   // Return the document's Info dictionary (if any).
64   Object *getDocInfo(Object *obj);
65
66   // Return the number of objects in the xref table.
67   int getNumObjects() { return size; }
68
69   // Return the offset of the last xref table.
70   int getLastXRefPos() { return lastXRefPos; }
71
72   // Return the catalog object reference.
73   int getRootNum() { return rootNum; }
74   int getRootGen() { return rootGen; }
75
76   // Get end position for a stream in a damaged file.
77   // Returns -1 if unknown or file is not damaged.
78   int getStreamEnd(int start);
79
80 private:
81
82   BaseStream *str;              // input stream
83   int start;                    // offset in file (to allow for garbage
84                                 //   at beginning of file)
85   XRefEntry *entries;           // xref entries
86   int size;                     // size of <entries> array
87   int rootNum, rootGen;         // catalog dict
88   GBool ok;                     // true if xref table is valid
89   Object trailerDict;           // trailer dictionary
90   int lastXRefPos;              // offset of last xref table
91   int *streamEnds;              // 'endstream' positions - only used in
92                                 //   damaged files
93   int streamEndsLen;            // number of valid entries in streamEnds
94 #ifndef NO_DECRYPTION
95   GBool encrypted;              // true if file is encrypted
96   int permFlags;                // permission bits
97   Guchar fileKey[16];           // file decryption key
98 #endif
99
100   int readTrailer();
101   GBool readXRef(int *pos);
102   GBool constructXRef();
103   GBool checkEncrypted(GString *userPassword);
104 };
105
106 //------------------------------------------------------------------------
107 // The global xref table
108 //------------------------------------------------------------------------
109
110 extern XRef *xref;
111
112 #endif