Coverage Report

Created: 2026-02-04 06:14

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