1 : //========================================================================
2 : //
3 : // Page.h
4 : //
5 : // Copyright 1996-2003 Glyph & Cog, LLC
6 : //
7 : //========================================================================
8 :
9 : //========================================================================
10 : //
11 : // Modified under the Poppler project - http://poppler.freedesktop.org
12 : //
13 : // All changes made under the Poppler project to this file are licensed
14 : // under GPL version 2 or later
15 : //
16 : // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
17 : // Copyright (C) 2005 Jeff Muizelaar <jeff@infidigm.net>
18 : // Copyright (C) 2006 Pino Toscano <pino@kde.org>
19 : // Copyright (C) 2006, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
20 : // Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org>
21 : // Copyright (C) 2008 Iñigo Martínez <inigomartinez@gmail.com>
22 : // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
23 : // Copyright (C) 2012 Albert Astals Cid <aacid@kde.org>
24 : // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
25 : //
26 : // To see a description of the changes please see the Changelog file that
27 : // came with your tarball or type make ChangeLog if you are building from git
28 : //
29 : //========================================================================
30 :
31 : #ifndef PAGE_H
32 : #define PAGE_H
33 :
34 : #ifdef USE_GCC_PRAGMAS
35 : #pragma interface
36 : #endif
37 :
38 : #include "poppler-config.h"
39 : #include "Object.h"
40 : #include "goo/GooMutex.h"
41 :
42 : class Dict;
43 : class PDFDoc;
44 : class XRef;
45 : class OutputDev;
46 : class Links;
47 : class Annots;
48 : class Annot;
49 : class Gfx;
50 : class FormPageWidgets;
51 : class Form;
52 :
53 : //------------------------------------------------------------------------
54 :
55 : class PDFRectangle {
56 : public:
57 : double x1, y1, x2, y2;
58 :
59 : PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
60 : PDFRectangle(double x1A, double y1A, double x2A, double y2A)
61 : { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
62 : GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
63 : GBool contains(double x, double y) { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
64 : void clipTo(PDFRectangle *rect);
65 :
66 : bool operator==(const PDFRectangle &rect) const { return x1 == rect.x1 && y1 == rect.y1 && x2 == rect.x2 && y2 == rect.y2; }
67 : };
68 :
69 : //------------------------------------------------------------------------
70 : // PageAttrs
71 : //------------------------------------------------------------------------
72 :
73 : class PageAttrs {
74 : public:
75 :
76 : // Construct a new PageAttrs object by merging a dictionary
77 : // (of type Pages or Page) into another PageAttrs object. If
78 : // <attrs> is NULL, uses defaults.
79 : PageAttrs(PageAttrs *attrs, Dict *dict);
80 :
81 : // Destructor.
82 : ~PageAttrs();
83 :
84 : // Accessors.
85 149 : PDFRectangle *getMediaBox() { return &mediaBox; }
86 : PDFRectangle *getCropBox() { return &cropBox; }
87 : GBool isCropped() { return haveCropBox; }
88 : PDFRectangle *getBleedBox() { return &bleedBox; }
89 : PDFRectangle *getTrimBox() { return &trimBox; }
90 : PDFRectangle *getArtBox() { return &artBox; }
91 149 : int getRotate() { return rotate; }
92 : GooString *getLastModified()
93 : { return lastModified.isString()
94 : ? lastModified.getString() : (GooString *)NULL; }
95 : Dict *getBoxColorInfo()
96 : { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; }
97 : Dict *getGroup()
98 : { return group.isDict() ? group.getDict() : (Dict *)NULL; }
99 : Stream *getMetadata()
100 : { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; }
101 : Dict *getPieceInfo()
102 : { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; }
103 : Dict *getSeparationInfo()
104 : { return separationInfo.isDict()
105 : ? separationInfo.getDict() : (Dict *)NULL; }
106 : Dict *getResourceDict()
107 : { return resources.isDict() ? resources.getDict() : (Dict *)NULL; }
108 : void replaceResource(Object obj1)
109 : { resources.free(); obj1.copy(&resources); }
110 :
111 : // Clip all other boxes to the MediaBox.
112 : void clipBoxes();
113 :
114 : private:
115 :
116 : GBool readBox(Dict *dict, const char *key, PDFRectangle *box);
117 :
118 : PDFRectangle mediaBox;
119 : PDFRectangle cropBox;
120 : GBool haveCropBox;
121 : PDFRectangle bleedBox;
122 : PDFRectangle trimBox;
123 : PDFRectangle artBox;
124 : int rotate;
125 : Object lastModified;
126 : Object boxColorInfo;
127 : Object group;
128 : Object metadata;
129 : Object pieceInfo;
130 : Object separationInfo;
131 : Object resources;
132 : };
133 :
134 : //------------------------------------------------------------------------
135 : // Page
136 : //------------------------------------------------------------------------
137 :
138 : class Page {
139 : public:
140 :
141 : // Constructor.
142 : Page(PDFDoc *docA, int numA, Dict *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
143 :
144 : // Destructor.
145 : ~Page();
146 :
147 : // Is page valid?
148 149 : GBool isOk() { return ok; }
149 :
150 : // Get page parameters.
151 : int getNum() { return num; }
152 149 : PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
153 : PDFRectangle *getCropBox() { return attrs->getCropBox(); }
154 : GBool isCropped() { return attrs->isCropped(); }
155 : double getMediaWidth()
156 : { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; }
157 : double getMediaHeight()
158 : { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; }
159 : double getCropWidth()
160 : { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; }
161 : double getCropHeight()
162 : { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; }
163 : PDFRectangle *getBleedBox() { return attrs->getBleedBox(); }
164 : PDFRectangle *getTrimBox() { return attrs->getTrimBox(); }
165 : PDFRectangle *getArtBox() { return attrs->getArtBox(); }
166 149 : int getRotate() { return attrs->getRotate(); }
167 : GooString *getLastModified() { return attrs->getLastModified(); }
168 : Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
169 : Dict *getGroup() { return attrs->getGroup(); }
170 : Stream *getMetadata() { return attrs->getMetadata(); }
171 : Dict *getPieceInfo() { return attrs->getPieceInfo(); }
172 : Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
173 : PDFDoc *getDoc() { return doc; }
174 : Ref getRef() { return pageRef; }
175 :
176 : // Get resource dictionary.
177 : Dict *getResourceDict() { return attrs->getResourceDict(); }
178 :
179 : // Get annotations array.
180 : Object *getAnnots(Object *obj) { return annotsObj.fetch(xref, obj); }
181 : // Add a new annotation to the page
182 : void addAnnot(Annot *annot);
183 : // Remove an existing annotation from the page
184 : void removeAnnot(Annot *annot);
185 :
186 : // Return a list of links.
187 : Links *getLinks();
188 :
189 : // Return a list of annots. It will be valid until the page is destroyed
190 : Annots *getAnnots();
191 :
192 : // Get contents.
193 : Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
194 :
195 : // Get thumb.
196 : Object *getThumb(Object *obj) { return thumb.fetch(xref, obj); }
197 : GBool loadThumb(unsigned char **data, int *width, int *height, int *rowstride);
198 :
199 : // Get transition.
200 : Object *getTrans(Object *obj) { return trans.fetch(xref, obj); }
201 :
202 : // Get form.
203 : FormPageWidgets *getFormWidgets();
204 :
205 : // Get duration, the maximum length of time, in seconds,
206 : // that the page is displayed before the presentation automatically
207 : // advances to the next page
208 : double getDuration() { return duration; }
209 :
210 : // Get actions
211 : Object *getActions(Object *obj) { return actions.fetch(xref, obj); }
212 :
213 : Gfx *createGfx(OutputDev *out, double hDPI, double vDPI,
214 : int rotate, GBool useMediaBox, GBool crop,
215 : int sliceX, int sliceY, int sliceW, int sliceH,
216 : GBool printing,
217 : GBool (*abortCheckCbk)(void *data),
218 : void *abortCheckCbkData, XRef *xrefA = NULL);
219 :
220 : // Display a page.
221 : void display(OutputDev *out, double hDPI, double vDPI,
222 : int rotate, GBool useMediaBox, GBool crop,
223 : GBool printing,
224 : GBool (*abortCheckCbk)(void *data) = NULL,
225 : void *abortCheckCbkData = NULL,
226 : GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
227 : void *annotDisplayDecideCbkData = NULL,
228 : GBool copyXRef = gFalse);
229 :
230 : // Display part of a page.
231 : void displaySlice(OutputDev *out, double hDPI, double vDPI,
232 : int rotate, GBool useMediaBox, GBool crop,
233 : int sliceX, int sliceY, int sliceW, int sliceH,
234 : GBool printing,
235 : GBool (*abortCheckCbk)(void *data) = NULL,
236 : void *abortCheckCbkData = NULL,
237 : GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
238 : void *annotDisplayDecideCbkData = NULL,
239 : GBool copyXRef = gFalse);
240 :
241 : void display(Gfx *gfx);
242 :
243 : void makeBox(double hDPI, double vDPI, int rotate,
244 : GBool useMediaBox, GBool upsideDown,
245 : double sliceX, double sliceY, double sliceW, double sliceH,
246 : PDFRectangle *box, GBool *crop);
247 :
248 : void processLinks(OutputDev *out);
249 :
250 : // Get the page's default CTM.
251 : void getDefaultCTM(double *ctm, double hDPI, double vDPI,
252 : int rotate, GBool useMediaBox, GBool upsideDown);
253 :
254 : private:
255 : // replace xref
256 : void replaceXRef(XRef *xrefA);
257 :
258 : PDFDoc *doc;
259 : XRef *xref; // the xref table for this PDF file
260 : Object pageObj; // page dictionary
261 : Ref pageRef; // page reference
262 : int num; // page number
263 : PageAttrs *attrs; // page attributes
264 : Annots *annots; // annotations
265 : Object annotsObj; // annotations array
266 : Object contents; // page contents
267 : Object thumb; // page thumbnail
268 : Object trans; // page transition
269 : Object actions; // page addiction actions
270 : double duration; // page duration
271 : GBool ok; // true if page is valid
272 : #if MULTITHREADED
273 : GooMutex mutex;
274 : #endif
275 : };
276 :
277 : #endif
|