~ubuntu-branches/ubuntu/hoary/libextractor/hoary

« back to all changes in this revision

Viewing changes to src/plugins/pdf/XRef.h

  • Committer: Bazaar Package Importer
  • Author(s): Glenn McGrath
  • Date: 2004-06-26 12:59:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040626125902-w97jpn43hsk7tcde
Tags: upstream-0.3.3
ImportĀ upstreamĀ versionĀ 0.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 *strA, GString *ownerPassword, 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(GBool ignoreOwnerPW = gFalse);
 
53
  GBool okToChange(GBool ignoreOwnerPW = gFalse);
 
54
  GBool okToCopy(GBool ignoreOwnerPW = gFalse);
 
55
  GBool okToAddNotes(GBool ignoreOwnerPW = gFalse);
 
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 streamStart);
 
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 encVersion;               // encryption algorithm
 
97
  int encRevision;              // security handler revision
 
98
  int keyLength;                // length of key, in bytes
 
99
  int permFlags;                // permission bits
 
100
  Guchar fileKey[16];           // file decryption key
 
101
  GBool ownerPasswordOk;        // true if owner password is correct
 
102
#endif
 
103
 
 
104
  int readTrailer();
 
105
  GBool readXRef(int *pos);
 
106
  GBool constructXRef();
 
107
  GBool checkEncrypted(GString *ownerPassword, GString *userPassword);
 
108
};
 
109
 
 
110
//------------------------------------------------------------------------
 
111
// The global xref table
 
112
//------------------------------------------------------------------------
 
113
 
 
114
extern XRef *xref;
 
115
 
 
116
#endif