Coverage Report

Created: 2025-07-11 06:50

/src/xpdf-4.05/xpdf/PDFDoc.h
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// PDFDoc.h
4
//
5
// Copyright 1996-2003 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#ifndef PDFDOC_H
10
#define PDFDOC_H
11
12
#include <aconf.h>
13
14
#include <stdio.h>
15
#include "XRef.h"
16
#include "Catalog.h"
17
#include "Page.h"
18
19
class GString;
20
class BaseStream;
21
class OutputDev;
22
class Annots;
23
class Links;
24
class LinkAction;
25
class LinkDest;
26
class Outline;
27
class OutlineItem;
28
class OptionalContent;
29
class PDFCore;
30
31
//------------------------------------------------------------------------
32
// PDFDoc
33
//------------------------------------------------------------------------
34
35
class PDFDoc {
36
public:
37
38
  PDFDoc(GString *fileNameA, GString *ownerPassword = NULL,
39
   GString *userPassword = NULL, PDFCore *coreA = NULL);
40
41
#ifdef _WIN32
42
  PDFDoc(wchar_t *fileNameA, int fileNameLen, GString *ownerPassword = NULL,
43
   GString *userPassword = NULL, PDFCore *coreA = NULL);
44
#endif
45
46
  // This version takes a UTF-8 file name (which is only relevant on
47
  // Windows).
48
  PDFDoc(char *fileNameA, GString *ownerPassword = NULL,
49
   GString *userPassword = NULL, PDFCore *coreA = NULL);
50
51
  PDFDoc(BaseStream *strA, GString *ownerPassword = NULL,
52
   GString *userPassword = NULL, PDFCore *coreA = NULL);
53
54
  ~PDFDoc();
55
56
  // Was PDF document successfully opened?
57
2.28k
  GBool isOk() { return ok; }
58
59
  // Get the error code (if isOk() returns false).
60
0
  int getErrorCode() { return errCode; }
61
62
  // Get file name.
63
1.24k
  GString *getFileName() { return fileName; }
64
#ifdef _WIN32
65
  wchar_t *getFileNameU() { return fileNameU; }
66
#endif
67
68
  // Get the xref table.
69
126k
  XRef *getXRef() { return xref; }
70
71
  // Get catalog.
72
1.24k
  Catalog *getCatalog() { return catalog; }
73
74
  // Get annotations.
75
0
  Annots *getAnnots() { return annots; }
76
77
  // Get base stream.
78
0
  BaseStream *getBaseStream() { return str; }
79
80
  // Get page parameters.
81
  double getPageMediaWidth(int page)
82
0
    { return catalog->getPage(page)->getMediaWidth(); }
83
  double getPageMediaHeight(int page)
84
0
    { return catalog->getPage(page)->getMediaHeight(); }
85
  double getPageCropWidth(int page)
86
0
    { return catalog->getPage(page)->getCropWidth(); }
87
  double getPageCropHeight(int page)
88
0
    { return catalog->getPage(page)->getCropHeight(); }
89
  int getPageRotate(int page)
90
0
    { return catalog->getPage(page)->getRotate(); }
91
92
  // Get number of pages.
93
49.8k
  int getNumPages() { return catalog->getNumPages(); }
94
95
  // Return the contents of the metadata stream, or NULL if there is
96
  // no metadata.
97
0
  GString *readMetadata() { return catalog->readMetadata(); }
98
99
  // Return the structure tree root object.
100
0
  Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
101
102
  // Display a page.
103
  void displayPage(OutputDev *out, int page,
104
       double hDPI, double vDPI, int rotate,
105
       GBool useMediaBox, GBool crop, GBool printing,
106
       GBool (*abortCheckCbk)(void *data) = NULL,
107
       void *abortCheckCbkData = NULL);
108
109
  // Display a range of pages.
110
  void displayPages(OutputDev *out, int firstPage, int lastPage,
111
        double hDPI, double vDPI, int rotate,
112
        GBool useMediaBox, GBool crop, GBool printing,
113
        GBool (*abortCheckCbk)(void *data) = NULL,
114
        void *abortCheckCbkData = NULL);
115
116
  // Display part of a page.
117
  void displayPageSlice(OutputDev *out, int page,
118
      double hDPI, double vDPI, int rotate,
119
      GBool useMediaBox, GBool crop, GBool printing,
120
      int sliceX, int sliceY, int sliceW, int sliceH,
121
      GBool (*abortCheckCbk)(void *data) = NULL,
122
      void *abortCheckCbkData = NULL);
123
124
125
  // Find a page, given its object ID.  Returns page number, or 0 if
126
  // not found.
127
0
  int findPage(int num, int gen) { return catalog->findPage(num, gen); }
128
129
  // Returns the links for the current page, transferring ownership to
130
  // the caller.
131
  Links *getLinks(int page);
132
133
  // Find a named destination.  Returns the link destination, or
134
  // NULL if <name> is not a destination.
135
  LinkDest *findDest(GString *name)
136
0
    { return catalog->findDest(name); }
137
138
  // Process the links for a page.
139
  void processLinks(OutputDev *out, int page);
140
141
#ifndef DISABLE_OUTLINE
142
  // Return the outline object.
143
0
  Outline *getOutline() { return outline; }
144
145
  // Return the target page number for an outline item.  Returns 0 if
146
  // the item doesn't target a page in this PDF file.
147
  int getOutlineTargetPage(OutlineItem *outlineItem);
148
#endif
149
150
  // Return the OptionalContent object.
151
0
  OptionalContent *getOptionalContent() { return optContent; }
152
153
  // Is the file encrypted?
154
0
  GBool isEncrypted() { return xref->isEncrypted(); }
155
156
  // Check various permissions.
157
  GBool okToPrint(GBool ignoreOwnerPW = gFalse)
158
0
    { return xref->okToPrint(ignoreOwnerPW); }
159
  GBool okToChange(GBool ignoreOwnerPW = gFalse)
160
0
    { return xref->okToChange(ignoreOwnerPW); }
161
  GBool okToCopy(GBool ignoreOwnerPW = gFalse)
162
0
    { return xref->okToCopy(ignoreOwnerPW); }
163
  GBool okToAddNotes(GBool ignoreOwnerPW = gFalse)
164
0
    { return xref->okToAddNotes(ignoreOwnerPW); }
165
166
  // Is the PDF file damaged?  This checks to see if the xref table
167
  // was constructed by the repair code.
168
0
  GBool isDamaged() { return xref->isRepaired(); }
169
170
  // Is this document linearized?
171
  GBool isLinearized();
172
173
  // Return the document's Info dictionary (if any).
174
0
  Object *getDocInfo(Object *obj) { return xref->getDocInfo(obj); }
175
0
  Object *getDocInfoNF(Object *obj) { return xref->getDocInfoNF(obj); }
176
177
  // Return the PDF version specified by the file.
178
0
  double getPDFVersion() { return pdfVersion; }
179
180
  // Save this file with another name.
181
  GBool saveAs(GString *name);
182
183
  // Return a pointer to the PDFCore object.
184
22
  PDFCore *getCore() { return core; }
185
186
  // Get the list of embedded files.
187
0
  int getNumEmbeddedFiles() { return catalog->getNumEmbeddedFiles(); }
188
  Unicode *getEmbeddedFileName(int idx)
189
0
    { return catalog->getEmbeddedFileName(idx); }
190
  int getEmbeddedFileNameLength(int idx)
191
0
    { return catalog->getEmbeddedFileNameLength(idx); }
192
  GBool saveEmbeddedFile(int idx, const char *path);
193
  GBool saveEmbeddedFileU(int idx, const char *path);
194
#ifdef _WIN32
195
  GBool saveEmbeddedFile(int idx, const wchar_t *path, int pathLen);
196
#endif
197
  char *getEmbeddedFileMem(int idx, int *size);
198
199
  // Return true if the document uses JavaScript.
200
0
  GBool usesJavaScript() { return catalog->usesJavaScript(); }
201
202
203
private:
204
205
  void init(PDFCore *coreA);
206
  GBool setup(GString *ownerPassword, GString *userPassword);
207
  GBool setup2(GString *ownerPassword, GString *userPassword,
208
         GBool repairXRef);
209
  void checkHeader();
210
  GBool checkEncryption(GString *ownerPassword, GString *userPassword);
211
  GBool saveEmbeddedFile2(int idx, FILE *f);
212
213
  GString *fileName;
214
#ifdef _WIN32
215
  wchar_t *fileNameU;
216
#endif
217
  FILE *file;
218
  BaseStream *str;
219
  PDFCore *core;
220
  double pdfVersion;
221
  XRef *xref;
222
  Catalog *catalog;
223
  Annots *annots;
224
#ifndef DISABLE_OUTLINE
225
  Outline *outline;
226
#endif
227
  OptionalContent *optContent;
228
229
  GBool ok;
230
  int errCode;
231
};
232
233
#endif