Coverage Report

Created: 2026-03-31 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/xpdf/Page.h
Line
Count
Source
1
//========================================================================
2
//
3
// Page.h
4
//
5
// Copyright 1996-2003 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#ifndef PAGE_H
10
#define PAGE_H
11
12
#include <aconf.h>
13
14
#include "Object.h"
15
16
class Dict;
17
class PDFDoc;
18
class XRef;
19
class OutputDev;
20
class Links;
21
class LocalParams;
22
23
//------------------------------------------------------------------------
24
25
class PDFRectangle {
26
public:
27
  double x1, y1, x2, y2;
28
29
5.18M
  PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
30
  PDFRectangle(double x1A, double y1A, double x2A, double y2A)
31
0
    { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
32
0
  GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
33
  void clipTo(PDFRectangle *rect);
34
};
35
36
//------------------------------------------------------------------------
37
// PageAttrs
38
//------------------------------------------------------------------------
39
40
class PageAttrs {
41
public:
42
43
  // Construct a new PageAttrs object by merging a dictionary
44
  // (of type Pages or Page) into another PageAttrs object.  If
45
  // <attrs> is NULL, uses defaults.
46
  PageAttrs(PageAttrs *attrs, Dict *dict, XRef *xref);
47
48
  // Construct a new PageAttrs object for an empty page (only used
49
  // when there is an error in the page tree).
50
  PageAttrs();
51
52
  // Destructor.
53
  ~PageAttrs();
54
55
  // Accessors.
56
384k
  PDFRectangle *getMediaBox() { return &mediaBox; }
57
768k
  PDFRectangle *getCropBox() { return &cropBox; }
58
0
  GBool isCropped() { return haveCropBox; }
59
0
  PDFRectangle *getBleedBox() { return &bleedBox; }
60
0
  PDFRectangle *getTrimBox() { return &trimBox; }
61
0
  PDFRectangle *getArtBox() { return &artBox; }
62
384k
  int getRotate() { return rotate; }
63
  GString *getLastModified()
64
0
    { return lastModified.isString()
65
0
  ? lastModified.getString() : (GString *)NULL; }
66
  Dict *getBoxColorInfo()
67
0
    { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; }
68
  Dict *getGroup()
69
0
    { return group.isDict() ? group.getDict() : (Dict *)NULL; }
70
  Stream *getMetadata()
71
384k
    { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; }
72
  Dict *getPieceInfo()
73
0
    { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; }
74
  Dict *getSeparationInfo()
75
0
    { return separationInfo.isDict()
76
0
  ? separationInfo.getDict() : (Dict *)NULL; }
77
0
  double getUserUnit() { return userUnit; }
78
  Dict *getResourceDict()
79
1.15M
    { return resources.isDict() ? resources.getDict() : (Dict *)NULL; }
80
81
  // Clip all other boxes to the MediaBox.
82
  void clipBoxes();
83
84
private:
85
86
  GBool readBox(Dict *dict, const char *key, PDFRectangle *box);
87
88
  PDFRectangle mediaBox;
89
  PDFRectangle cropBox;
90
  GBool haveCropBox;
91
  PDFRectangle bleedBox;
92
  PDFRectangle trimBox;
93
  PDFRectangle artBox;
94
  int rotate;
95
  Object lastModified;
96
  Object boxColorInfo;
97
  Object group;
98
  Object metadata;
99
  Object pieceInfo;
100
  Object separationInfo;
101
  double userUnit;
102
  Object resources;
103
};
104
105
//------------------------------------------------------------------------
106
// Page
107
//------------------------------------------------------------------------
108
109
class Page {
110
public:
111
112
  // Constructor.
113
  Page(PDFDoc *docA, int numA, Dict *pageDict, PageAttrs *attrsA);
114
115
  // Create an empty page (only used when there is an error in the
116
  // page tree).
117
  Page(PDFDoc *docA, int numA);
118
119
  // Destructor.
120
  ~Page();
121
122
  // Is page valid?
123
721k
  GBool isOk() { return ok; }
124
125
  // Get page parameters.
126
0
  int getNum() { return num; }
127
0
  PageAttrs *getAttrs() { return attrs; }
128
384k
  PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
129
768k
  PDFRectangle *getCropBox() { return attrs->getCropBox(); }
130
0
  GBool isCropped() { return attrs->isCropped(); }
131
  double getMediaWidth() 
132
0
    { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; }
133
  double getMediaHeight()
134
0
    { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; }
135
  double getCropWidth() 
136
0
    { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; }
137
  double getCropHeight()
138
0
    { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; }
139
0
  PDFRectangle *getBleedBox() { return attrs->getBleedBox(); }
140
0
  PDFRectangle *getTrimBox() { return attrs->getTrimBox(); }
141
0
  PDFRectangle *getArtBox() { return attrs->getArtBox(); }
142
384k
  int getRotate() { return attrs->getRotate(); }
143
0
  GString *getLastModified() { return attrs->getLastModified(); }
144
0
  Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
145
0
  Dict *getGroup() { return attrs->getGroup(); }
146
384k
  Stream *getMetadata() { return attrs->getMetadata(); }
147
0
  Dict *getPieceInfo() { return attrs->getPieceInfo(); }
148
0
  Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
149
0
  double getUserUnit() { return attrs->getUserUnit(); }
150
151
  // Get resource dictionary.
152
768k
  Dict *getResourceDict() { return attrs->getResourceDict(); }
153
154
  // Get annotations array.
155
1.94M
  Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
156
157
  // Return a list of links.
158
  Links *getLinks();
159
160
  // Get contents.
161
0
  Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
162
163
  // Get the page's thumbnail image.
164
0
  Object *getThumbnail(Object *obj) { return thumbnail.fetch(xref, obj); }
165
166
  // Display a page.
167
  void display(OutputDev *out, LocalParams *localParams,
168
         double hDPI, double vDPI,
169
         int rotate, GBool useMediaBox, GBool crop,
170
         GBool printing,
171
         GBool (*abortCheckCbk)(void *data) = NULL,
172
         void *abortCheckCbkData = NULL);
173
174
  // Display part of a page.
175
  void displaySlice(OutputDev *out, LocalParams *localParams,
176
        double hDPI, double vDPI,
177
        int rotate, GBool useMediaBox, GBool crop,
178
        int sliceX, int sliceY, int sliceW, int sliceH,
179
        GBool printing,
180
        GBool (*abortCheckCbk)(void *data) = NULL,
181
        void *abortCheckCbkData = NULL);
182
183
  void makeBox(double hDPI, double vDPI, int rotate,
184
         GBool useMediaBox, GBool upsideDown,
185
         double sliceX, double sliceY, double sliceW, double sliceH,
186
         PDFRectangle *box, GBool *crop);
187
188
  void processLinks(OutputDev *out);
189
190
  // Get the page's default CTM.
191
  void getDefaultCTM(double *ctm, double hDPI, double vDPI,
192
         int rotate, GBool useMediaBox, GBool upsideDown);
193
194
195
private:
196
197
  PDFDoc *doc;
198
  XRef *xref;     // the xref table for this PDF file
199
  int num;      // page number
200
  PageAttrs *attrs;   // page attributes
201
  Object annots;    // annotations array
202
  Object contents;    // page contents
203
  Object thumbnail;   // reference to thumbnail image
204
  GBool ok;     // true if page is valid
205
};
206
207
#endif