]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/PDFDoc.h
ff6e359ceb784f7a72d51df9645dd9707fc51c84
[evince.git] / pdf / xpdf / PDFDoc.h
1 //========================================================================
2 //
3 // PDFDoc.h
4 //
5 // Copyright 1996-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef PDFDOC_H
10 #define PDFDOC_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include <stdio.h>
19 #include "XRef.h"
20 #include "Link.h"
21 #include "Catalog.h"
22 #include "Page.h"
23
24 class GString;
25 class BaseStream;
26 class OutputDev;
27 class Links;
28 class LinkAction;
29 class LinkDest;
30 class Outline;
31
32 //------------------------------------------------------------------------
33 // PDFDoc
34 //------------------------------------------------------------------------
35
36 class PDFDoc {
37 public:
38
39   PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
40          GString *userPassword = NULL);
41   PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
42          GString *userPassword = NULL);
43   ~PDFDoc();
44
45   // Was PDF document successfully opened?
46   GBool isOk() { return ok; }
47
48   // Get the error code (if isOk() returns false).
49   int getErrorCode() { return errCode; }
50
51   // Get file name.
52   GString *getFileName() { return fileName; }
53
54   // Get the xref table.
55   XRef *getXRef() { return xref; }
56
57   // Get catalog.
58   Catalog *getCatalog() { return catalog; }
59
60   // Get base stream.
61   BaseStream *getBaseStream() { return str; }
62
63   // Get page parameters.
64   double getPageWidth(int page)
65     { return catalog->getPage(page)->getWidth(); }
66   double getPageHeight(int page)
67     { return catalog->getPage(page)->getHeight(); }
68   int getPageRotate(int page)
69     { return catalog->getPage(page)->getRotate(); }
70
71   // Get number of pages.
72   int getNumPages() { return catalog->getNumPages(); }
73
74   // Return the contents of the metadata stream, or NULL if there is
75   // no metadata.
76   GString *readMetadata() { return catalog->readMetadata(); }
77
78   // Return the structure tree root object.
79   Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
80
81   // Display a page.
82   void displayPage(OutputDev *out, int page, double zoom,
83                    int rotate, GBool doLinks,
84                    GBool (*abortCheckCbk)(void *data) = NULL,
85                    void *abortCheckCbkData = NULL);
86
87   // Display a range of pages.
88   void displayPages(OutputDev *out, int firstPage, int lastPage,
89                     int zoom, int rotate, GBool doLinks,
90                     GBool (*abortCheckCbk)(void *data) = NULL,
91                     void *abortCheckCbkData = NULL);
92
93   // Display part of a page.
94   void displayPageSlice(OutputDev *out, int page, double zoom,
95                         int rotate, int sliceX, int sliceY,
96                         int sliceW, int sliceH,
97                         GBool (*abortCheckCbk)(void *data) = NULL,
98                         void *abortCheckCbkData = NULL);
99
100   // Find a page, given its object ID.  Returns page number, or 0 if
101   // not found.
102   int findPage(int num, int gen) { return catalog->findPage(num, gen); }
103
104   // If point <x>,<y> is in a link, return the associated action;
105   // else return NULL.
106   LinkAction *findLink(double x, double y) { return links->find(x, y); }
107
108   // Return true if <x>,<y> is in a link.
109   GBool onLink(double x, double y) { return links->onLink(x, y); }
110
111   // Find a named destination.  Returns the link destination, or
112   // NULL if <name> is not a destination.
113   LinkDest *findDest(GString *name)
114     { return catalog->findDest(name); }
115
116 #ifndef DISABLE_OUTLINE
117   // Return the outline object.
118   Outline *getOutline() { return outline; }
119 #endif
120
121   // Is the file encrypted?
122   GBool isEncrypted() { return xref->isEncrypted(); }
123
124   // Check various permissions.
125   GBool okToPrint(GBool ignoreOwnerPW = gFalse)
126     { return xref->okToPrint(ignoreOwnerPW); }
127   GBool okToChange(GBool ignoreOwnerPW = gFalse)
128     { return xref->okToChange(ignoreOwnerPW); }
129   GBool okToCopy(GBool ignoreOwnerPW = gFalse)
130     { return xref->okToCopy(ignoreOwnerPW); }
131   GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
132     { return xref->okToAddNotes(ignoreOwnerPW); }
133
134   // Is this document linearized?
135   GBool isLinearized();
136
137   // Return the document's Info dictionary (if any).
138   Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
139   Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
140
141   // Return the PDF version specified by the file.
142   double getPDFVersion() { return pdfVersion; }
143
144   // Save this file with another name.
145   GBool saveAs(GString *name);
146
147
148 private:
149
150   GBool setup(GString *ownerPassword, GString *userPassword);
151   void checkHeader();
152   void getLinks(Page *page);
153
154   GString *fileName;
155   FILE *file;
156   BaseStream *str;
157   double pdfVersion;
158   XRef *xref;
159   Catalog *catalog;
160   Links *links;
161 #ifndef DISABLE_OUTLINE
162   Outline *outline;
163 #endif
164
165
166   GBool ok;
167   int errCode;
168 };
169
170 #endif