]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/Page.h
New file with some random thoughts.
[evince.git] / pdf / xpdf / Page.h
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 #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 class Annots;
26 class Annot;
27
28 //------------------------------------------------------------------------
29
30 class PDFRectangle {
31 public:
32   double x1, y1, x2, y2;
33
34   PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
35   PDFRectangle(double x1A, double y1A, double x2A, double y2A)
36     { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
37   GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
38 };
39
40 //------------------------------------------------------------------------
41 // PageAttrs
42 //------------------------------------------------------------------------
43
44 class PageAttrs {
45 public:
46
47   // Construct a new PageAttrs object by merging a dictionary
48   // (of type Pages or Page) into another PageAttrs object.  If
49   // <attrs> is NULL, uses defaults.
50   PageAttrs(PageAttrs *attrs, Dict *dict);
51
52   // Destructor.
53   ~PageAttrs();
54
55   // Accessors.
56   PDFRectangle *getBox() { return limitToCropBox ? &cropBox : &mediaBox; }
57   PDFRectangle *getMediaBox() { return &mediaBox; }
58   PDFRectangle *getCropBox() { return &cropBox; }
59   GBool isCropped() { return haveCropBox; }
60   PDFRectangle *getBleedBox() { return &bleedBox; }
61   PDFRectangle *getTrimBox() { return &trimBox; }
62   PDFRectangle *getArtBox() { return &artBox; }
63   int getRotate() { return rotate; }
64   GString *getLastModified()
65     { return lastModified.isString()
66         ? lastModified.getString() : (GString *)NULL; }
67   Dict *getBoxColorInfo()
68     { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; }
69   Dict *getGroup()
70     { return group.isDict() ? group.getDict() : (Dict *)NULL; }
71   Stream *getMetadata()
72     { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; }
73   Dict *getPieceInfo()
74     { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; }
75   Dict *getSeparationInfo()
76     { return separationInfo.isDict()
77         ? separationInfo.getDict() : (Dict *)NULL; }
78   Dict *getResourceDict()
79     { return resources.isDict() ? resources.getDict() : (Dict *)NULL; }
80
81 private:
82
83   GBool readBox(Dict *dict, char *key, PDFRectangle *box);
84
85   PDFRectangle mediaBox;
86   PDFRectangle cropBox;
87   GBool haveCropBox;
88   GBool limitToCropBox;
89   PDFRectangle bleedBox;
90   PDFRectangle trimBox;
91   PDFRectangle artBox;
92   int rotate;
93   Object lastModified;
94   Object boxColorInfo;
95   Object group;
96   Object metadata;
97   Object pieceInfo;
98   Object separationInfo;
99   Object resources;
100 };
101
102 //------------------------------------------------------------------------
103 // Page
104 //------------------------------------------------------------------------
105
106 class Page {
107 public:
108
109   // Constructor.
110   Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA);
111
112   // Destructor.
113   ~Page();
114
115   // Is page valid?
116   GBool isOk() { return ok; }
117
118   // Get page parameters.
119   PDFRectangle *getBox() { return attrs->getBox(); }
120   PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
121   PDFRectangle *getCropBox() { return attrs->getCropBox(); }
122   GBool isCropped() { return attrs->isCropped(); }
123   double getWidth() { return attrs->getBox()->x2 - attrs->getBox()->x1; }
124   double getHeight() { return attrs->getBox()->y2 - attrs->getBox()->y1; }
125   PDFRectangle *getBleedBox() { return attrs->getBleedBox(); }
126   PDFRectangle *getTrimBox() { return attrs->getTrimBox(); }
127   PDFRectangle *getArtBox() { return attrs->getArtBox(); }
128   int getRotate() { return attrs->getRotate(); }
129   GString *getLastModified() { return attrs->getLastModified(); }
130   Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
131   Dict *getGroup() { return attrs->getGroup(); }
132   Stream *getMetadata() { return attrs->getMetadata(); }
133   Dict *getPieceInfo() { return attrs->getPieceInfo(); }
134   Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
135
136   // Get resource dictionary.
137   Dict *getResourceDict() { return attrs->getResourceDict(); }
138
139   // Get annotations array.
140   Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
141
142   // Get contents.
143   Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
144
145   // Get thumb.
146   Object *getThumb(Object *obj) { return thumb.fetch(xref, obj); }
147
148   // Display a page.
149   void display(OutputDev *out, double hDPI, double vDPI,
150                int rotate, GBool crop,
151                Links *links, Catalog *catalog,
152                GBool (*abortCheckCbk)(void *data) = NULL,
153                void *abortCheckCbkData = NULL,
154                GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
155                void *annotDisplayDecideCbkData = NULL);
156
157   // Display part of a page.
158   void displaySlice(OutputDev *out, double hDPI, double vDPI,
159                     int rotate, GBool crop,
160                     int sliceX, int sliceY, int sliceW, int sliceH,
161                     Links *links, Catalog *catalog,
162                     GBool (*abortCheckCbk)(void *data) = NULL,
163                     void *abortCheckCbkData = NULL,
164                     GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL,
165                     void *annotDisplayDecideCbkData = NULL);
166
167 private:
168
169   XRef *xref;                   // the xref table for this PDF file
170   int num;                      // page number
171   PageAttrs *attrs;             // page attributes
172   Object annots;                // annotations array
173   Object contents;              // page contents
174   Object thumb;                 // page thumbnail
175   GBool ok;                     // true if page is valid
176 };
177
178 #endif