]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 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 <config.h> | |
13 | ||
14 | #ifdef USE_GCC_PRAGMAS | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "Object.h" | |
19 | ||
20 | class Dict; | |
21 | class XRef; | |
22 | class OutputDev; | |
23 | class Links; | |
24 | class Catalog; | |
25 | ||
26 | //------------------------------------------------------------------------ | |
27 | ||
28 | class PDFRectangle { | |
29 | public: | |
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 | ||
42 | class PageAttrs { | |
43 | public: | |
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 *getMediaBox() { return &mediaBox; } | |
55 | PDFRectangle *getCropBox() { return &cropBox; } | |
56 | GBool isCropped() { return haveCropBox; } | |
57 | PDFRectangle *getBleedBox() { return &bleedBox; } | |
58 | PDFRectangle *getTrimBox() { return &trimBox; } | |
59 | PDFRectangle *getArtBox() { return &artBox; } | |
60 | int getRotate() { return rotate; } | |
61 | GString *getLastModified() | |
62 | { return lastModified.isString() | |
63 | ? lastModified.getString() : (GString *)NULL; } | |
64 | Dict *getBoxColorInfo() | |
65 | { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; } | |
66 | Dict *getGroup() | |
67 | { return group.isDict() ? group.getDict() : (Dict *)NULL; } | |
68 | Stream *getMetadata() | |
69 | { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; } | |
70 | Dict *getPieceInfo() | |
71 | { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; } | |
72 | Dict *getSeparationInfo() | |
73 | { return separationInfo.isDict() | |
74 | ? separationInfo.getDict() : (Dict *)NULL; } | |
75 | Dict *getResourceDict() | |
76 | { return resources.isDict() ? resources.getDict() : (Dict *)NULL; } | |
77 | ||
78 | private: | |
79 | ||
80 | GBool readBox(Dict *dict, char *key, PDFRectangle *box); | |
81 | ||
82 | PDFRectangle mediaBox; | |
83 | PDFRectangle cropBox; | |
84 | GBool haveCropBox; | |
85 | PDFRectangle bleedBox; | |
86 | PDFRectangle trimBox; | |
87 | PDFRectangle artBox; | |
88 | int rotate; | |
89 | Object lastModified; | |
90 | Object boxColorInfo; | |
91 | Object group; | |
92 | Object metadata; | |
93 | Object pieceInfo; | |
94 | Object separationInfo; | |
95 | Object resources; | |
96 | }; | |
97 | ||
98 | //------------------------------------------------------------------------ | |
99 | // Page | |
100 | //------------------------------------------------------------------------ | |
101 | ||
102 | class Page { | |
103 | public: | |
104 | ||
105 | // Constructor. | |
106 | Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA); | |
107 | ||
108 | // Destructor. | |
109 | ~Page(); | |
110 | ||
111 | // Is page valid? | |
112 | GBool isOk() { return ok; } | |
113 | ||
114 | // Get page parameters. | |
115 | PDFRectangle *getMediaBox() { return attrs->getMediaBox(); } | |
116 | PDFRectangle *getCropBox() { return attrs->getCropBox(); } | |
117 | GBool isCropped() { return attrs->isCropped(); } | |
118 | double getMediaWidth() | |
119 | { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; } | |
120 | double getMediaHeight() | |
121 | { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; } | |
122 | double getCropWidth() | |
123 | { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; } | |
124 | double getCropHeight() | |
125 | { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; } | |
126 | PDFRectangle *getBleedBox() { return attrs->getBleedBox(); } | |
127 | PDFRectangle *getTrimBox() { return attrs->getTrimBox(); } | |
128 | PDFRectangle *getArtBox() { return attrs->getArtBox(); } | |
129 | int getRotate() { return attrs->getRotate(); } | |
130 | GString *getLastModified() { return attrs->getLastModified(); } | |
131 | Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); } | |
132 | Dict *getGroup() { return attrs->getGroup(); } | |
133 | Stream *getMetadata() { return attrs->getMetadata(); } | |
134 | Dict *getPieceInfo() { return attrs->getPieceInfo(); } | |
135 | Dict *getSeparationInfo() { return attrs->getSeparationInfo(); } | |
136 | ||
137 | // Get resource dictionary. | |
138 | Dict *getResourceDict() { return attrs->getResourceDict(); } | |
139 | ||
140 | // Get annotations array. | |
141 | Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); } | |
142 | ||
143 | // Get contents. | |
144 | Object *getContents(Object *obj) { return contents.fetch(xref, obj); } | |
145 | ||
146 | // Display a page. | |
147 | void display(OutputDev *out, double hDPI, double vDPI, | |
148 | int rotate, GBool useMediaBox, GBool crop, | |
149 | Links *links, Catalog *catalog, | |
150 | GBool (*abortCheckCbk)(void *data) = NULL, | |
151 | void *abortCheckCbkData = NULL); | |
152 | ||
153 | // Display part of a page. | |
154 | void displaySlice(OutputDev *out, double hDPI, double vDPI, | |
155 | int rotate, GBool useMediaBox, GBool crop, | |
156 | int sliceX, int sliceY, int sliceW, int sliceH, | |
157 | Links *links, Catalog *catalog, | |
158 | GBool (*abortCheckCbk)(void *data) = NULL, | |
159 | void *abortCheckCbkData = NULL); | |
160 | ||
161 | // Get the page's default CTM. | |
162 | void getDefaultCTM(double *ctm, double hDPI, double vDPI, | |
163 | int rotate, GBool upsideDown); | |
164 | ||
165 | private: | |
166 | ||
167 | XRef *xref; // the xref table for this PDF file | |
168 | int num; // page number | |
169 | PageAttrs *attrs; // page attributes | |
170 | Object annots; // annotations array | |
171 | Object contents; // page contents | |
172 | GBool ok; // true if page is valid | |
173 | }; | |
174 | ||
175 | #endif |