Page.h
1//========================================================================
2//
3// Page.h
4//
5// Copyright 1996-2002 Glyph & Cog, LLC
6//
7//========================================================================
8
9#ifndef PAGE_H
10#define PAGE_H
11
12#include <aconf.h>
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include "Object.h"
19
20class Dict;
21class XRef;
22class OutputDev;
23class Links;
24class Catalog;
25
26//------------------------------------------------------------------------
27
28class PDFRectangle {
29public:
30 double x1, y1, x2, y2;
31
32 PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
33 PDFRectangle(double x1A, double y1A, double x2A, double y2A)
34 { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
35 GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
36};
37
38//------------------------------------------------------------------------
39// PageAttrs
40//------------------------------------------------------------------------
41
42class PageAttrs {
43public:
44
45 // Construct a new PageAttrs object by merging a dictionary
46 // (of type Pages or Page) into another PageAttrs object. If
47 // <attrs> is NULL, uses defaults.
48 PageAttrs(PageAttrs *attrs, Dict *dict);
49
50 // Destructor.
51 ~PageAttrs();
52
53 // Accessors.
54 PDFRectangle *getBox() { return limitToCropBox ? &cropBox : &mediaBox; }
55 PDFRectangle *getMediaBox() { return &mediaBox; }
56 PDFRectangle *getCropBox() { return &cropBox; }
57 GBool isCropped() { return haveCropBox; }
58 PDFRectangle *getBleedBox() { return &bleedBox; }
59 PDFRectangle *getTrimBox() { return &trimBox; }
60 PDFRectangle *getArtBox() { return &artBox; }
61 int getRotate() { return rotate; }
62 GString *getLastModified()
63 { return lastModified.isString()
64 ? lastModified.getString() : (GString *)NULL; }
65 Dict *getBoxColorInfo()
66 { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; }
67 Dict *getGroup()
68 { return group.isDict() ? group.getDict() : (Dict *)NULL; }
69 Stream *getMetadata()
70 { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; }
71 Dict *getPieceInfo()
72 { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; }
73 Dict *getSeparationInfo()
74 { return separationInfo.isDict()
75 ? separationInfo.getDict() : (Dict *)NULL; }
76 Dict *getResourceDict()
77 { return resources.isDict() ? resources.getDict() : (Dict *)NULL; }
78
79private:
80
81 GBool readBox(Dict *dict, const char *key, PDFRectangle *box);
82
83 PDFRectangle mediaBox;
84 PDFRectangle cropBox;
85 GBool haveCropBox;
86 GBool limitToCropBox;
87 PDFRectangle bleedBox;
88 PDFRectangle trimBox;
89 PDFRectangle artBox;
90 int rotate;
91 Object lastModified;
92 Object boxColorInfo;
93 Object group;
94 Object metadata;
95 Object pieceInfo;
96 Object separationInfo;
97 Object resources;
98};
99
100//------------------------------------------------------------------------
101// Page
102//------------------------------------------------------------------------
103
104class Page {
105public:
106
107 // Constructor.
108 Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA);
109
110 // Destructor.
111 ~Page();
112
113 // Is page valid?
114 GBool isOk() { return ok; }
115
116 // Get page parameters.
117 PDFRectangle *getBox() { return attrs->getBox(); }
118 PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
119 PDFRectangle *getCropBox() { return attrs->getCropBox(); }
120 GBool isCropped() { return attrs->isCropped(); }
121 double getWidth() { return attrs->getBox()->x2 - attrs->getBox()->x1; }
122 double getHeight() { return attrs->getBox()->y2 - attrs->getBox()->y1; }
123 PDFRectangle *getBleedBox() { return attrs->getBleedBox(); }
124 PDFRectangle *getTrimBox() { return attrs->getTrimBox(); }
125 PDFRectangle *getArtBox() { return attrs->getArtBox(); }
126 int getRotate() { return attrs->getRotate(); }
127 GString *getLastModified() { return attrs->getLastModified(); }
128 Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
129 Dict *getGroup() { return attrs->getGroup(); }
130 Stream *getMetadata() { return attrs->getMetadata(); }
131 Dict *getPieceInfo() { return attrs->getPieceInfo(); }
132 Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
133
134 // Get resource dictionary.
135 Dict *getResourceDict() { return attrs->getResourceDict(); }
136
137 // Get annotations array.
138 Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
139
140 // Get contents.
141 Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
142
143 // Display a page.
144 void display(OutputDev *out, double dpi, int rotate,
145 Links *links, Catalog *catalog,
146 GBool (*abortCheckCbk)(void *data) = NULL,
147 void *abortCheckCbkData = NULL);
148
149 // Display part of a page.
150 void displaySlice(OutputDev *out, double dpi, int rotate,
151 int sliceX, int sliceY, int sliceW, int sliceH,
152 Links *links, Catalog *catalog,
153 GBool (*abortCheckCbk)(void *data) = NULL,
154 void *abortCheckCbkData = NULL);
155
156private:
157
158 XRef *xref; // the xref table for this PDF file
159 int num; // page number
160 PageAttrs *attrs; // page attributes
161 Object annots; // annotations array
162 Object contents; // page contents
163 GBool ok; // true if page is valid
164};
165
166#endif