2376cb496bae7aced45b98be6d5d7777bf007dbd
[swftools.git] / pdf2swf / 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
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 *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
79 private:
80
81   GBool readBox(Dict *dict, 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
104 class Page {
105 public:
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 hDPI, double vDPI,
145                int rotate, GBool crop,
146                Links *links, Catalog *catalog,
147                GBool (*abortCheckCbk)(void *data) = NULL,
148                void *abortCheckCbkData = NULL);
149
150   // Display part of a page.
151   void displaySlice(OutputDev *out, double hDPI, double vDPI,
152                     int rotate, GBool crop,
153                     int sliceX, int sliceY, int sliceW, int sliceH,
154                     Links *links, Catalog *catalog,
155                     GBool (*abortCheckCbk)(void *data) = NULL,
156                     void *abortCheckCbkData = NULL);
157
158 private:
159
160   XRef *xref;                   // the xref table for this PDF file
161   int num;                      // page number
162   PageAttrs *attrs;             // page attributes
163   Object annots;                // annotations array
164   Object contents;              // page contents
165   GBool ok;                     // true if page is valid
166 };
167
168 #endif