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 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 // 23 // To see a description of the changes please see the Changelog file that 24 // came with your tarball or type make ChangeLog if you are building from git 25 // 26 //======================================================================== 27 28 #ifndef PAGE_H 29 #define PAGE_H 30 31 #ifdef USE_GCC_PRAGMAS 32 #pragma interface 33 #endif 34 35 #include "Object.h" 36 37 class Dict; 38 class XRef; 39 class OutputDev; 40 class Links; 41 class Catalog; 42 class Annots; 43 class Annot; 44 class Gfx; 45 class FormPageWidgets; 46 class Form; 47 48 //------------------------------------------------------------------------ 49 50 class PDFRectangle { 51 public: 52 double x1, y1, x2, y2; 53 PDFRectangle()54 PDFRectangle() { x1 = y1 = x2 = y2 = 0; } PDFRectangle(double x1A,double y1A,double x2A,double y2A)55 PDFRectangle(double x1A, double y1A, double x2A, double y2A) 56 { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; } isValid()57 GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; } 58 void clipTo(PDFRectangle *rect); 59 }; 60 61 //------------------------------------------------------------------------ 62 // PageAttrs 63 //------------------------------------------------------------------------ 64 65 class PageAttrs { 66 public: 67 68 // Construct a new PageAttrs object by merging a dictionary 69 // (of type Pages or Page) into another PageAttrs object. If 70 // <attrs> is NULL, uses defaults. 71 PageAttrs(PageAttrs *attrs, Dict *dict); 72 73 // Destructor. 74 ~PageAttrs(); 75 76 // Accessors. getMediaBox()77 PDFRectangle *getMediaBox() { return &mediaBox; } getCropBox()78 PDFRectangle *getCropBox() { return &cropBox; } isCropped()79 GBool isCropped() { return haveCropBox; } getBleedBox()80 PDFRectangle *getBleedBox() { return &bleedBox; } getTrimBox()81 PDFRectangle *getTrimBox() { return &trimBox; } getArtBox()82 PDFRectangle *getArtBox() { return &artBox; } getRotate()83 int getRotate() { return rotate; } getLastModified()84 GooString *getLastModified() 85 { return lastModified.isString() 86 ? lastModified.getString() : (GooString *)NULL; } getBoxColorInfo()87 Dict *getBoxColorInfo() 88 { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; } getGroup()89 Dict *getGroup() 90 { return group.isDict() ? group.getDict() : (Dict *)NULL; } getMetadata()91 Stream *getMetadata() 92 { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; } getPieceInfo()93 Dict *getPieceInfo() 94 { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; } getSeparationInfo()95 Dict *getSeparationInfo() 96 { return separationInfo.isDict() 97 ? separationInfo.getDict() : (Dict *)NULL; } getResourceDict()98 Dict *getResourceDict() 99 { return resources.isDict() ? resources.getDict() : (Dict *)NULL; } 100 101 private: 102 103 GBool readBox(Dict *dict, char *key, PDFRectangle *box); 104 105 PDFRectangle mediaBox; 106 PDFRectangle cropBox; 107 GBool haveCropBox; 108 PDFRectangle bleedBox; 109 PDFRectangle trimBox; 110 PDFRectangle artBox; 111 int rotate; 112 Object lastModified; 113 Object boxColorInfo; 114 Object group; 115 Object metadata; 116 Object pieceInfo; 117 Object separationInfo; 118 Object resources; 119 }; 120 121 //------------------------------------------------------------------------ 122 // Page 123 //------------------------------------------------------------------------ 124 125 class Page { 126 public: 127 128 // Constructor. 129 Page(XRef *xrefA, int numA, Dict *pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form); 130 131 // Destructor. 132 ~Page(); 133 134 // Is page valid? isOk()135 GBool isOk() { return ok; } 136 137 // Get page parameters. getNum()138 int getNum() { return num; } getMediaBox()139 PDFRectangle *getMediaBox() { return attrs->getMediaBox(); } getCropBox()140 PDFRectangle *getCropBox() { return attrs->getCropBox(); } isCropped()141 GBool isCropped() { return attrs->isCropped(); } getMediaWidth()142 double getMediaWidth() 143 { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; } getMediaHeight()144 double getMediaHeight() 145 { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; } getCropWidth()146 double getCropWidth() 147 { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; } getCropHeight()148 double getCropHeight() 149 { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; } getBleedBox()150 PDFRectangle *getBleedBox() { return attrs->getBleedBox(); } getTrimBox()151 PDFRectangle *getTrimBox() { return attrs->getTrimBox(); } getArtBox()152 PDFRectangle *getArtBox() { return attrs->getArtBox(); } getRotate()153 int getRotate() { return attrs->getRotate(); } getLastModified()154 GooString *getLastModified() { return attrs->getLastModified(); } getBoxColorInfo()155 Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); } getGroup()156 Dict *getGroup() { return attrs->getGroup(); } getMetadata()157 Stream *getMetadata() { return attrs->getMetadata(); } getPieceInfo()158 Dict *getPieceInfo() { return attrs->getPieceInfo(); } getSeparationInfo()159 Dict *getSeparationInfo() { return attrs->getSeparationInfo(); } 160 161 // Get resource dictionary. getResourceDict()162 Dict *getResourceDict() { return attrs->getResourceDict(); } 163 164 // Get annotations array. getAnnots(Object * obj)165 Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); } 166 // Add a new annotation to the page 167 void addAnnot(Annot *annot); 168 169 // Return a list of links. 170 Links *getLinks(Catalog *catalog); 171 172 // Return a list of annots. Ownership is transferred to the caller. 173 Annots *getAnnots(Catalog *catalog); 174 175 // Get contents. getContents(Object * obj)176 Object *getContents(Object *obj) { return contents.fetch(xref, obj); } 177 178 // Get thumb. getThumb(Object * obj)179 Object *getThumb(Object *obj) { return thumb.fetch(xref, obj); } 180 GBool loadThumb(unsigned char **data, int *width, int *height, int *rowstride); 181 182 // Get transition. getTrans(Object * obj)183 Object *getTrans(Object *obj) { return trans.fetch(xref, obj); } 184 185 // Get form. getPageWidgets()186 FormPageWidgets *getPageWidgets() { return pageWidgets; } 187 188 // Get duration, the maximum length of time, in seconds, 189 // that the page is displayed before the presentation automatically 190 // advances to the next page getDuration()191 double getDuration() { return duration; } 192 193 // Get actions getActions(Object * obj)194 Object *getActions(Object *obj) { return actions.fetch(xref, obj); } 195 196 Gfx *createGfx(OutputDev *out, double hDPI, double vDPI, 197 int rotate, GBool useMediaBox, GBool crop, 198 int sliceX, int sliceY, int sliceW, int sliceH, 199 GBool printing, Catalog *catalog, 200 GBool (*abortCheckCbk)(void *data), 201 void *abortCheckCbkData, 202 GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data), 203 void *annotDisplayDecideCbkData); 204 205 // Display a page. 206 void display(OutputDev *out, double hDPI, double vDPI, 207 int rotate, GBool useMediaBox, GBool crop, 208 GBool printing, Catalog *catalog, 209 GBool (*abortCheckCbk)(void *data) = NULL, 210 void *abortCheckCbkData = NULL, 211 GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL, 212 void *annotDisplayDecideCbkData = NULL); 213 214 // Display part of a page. 215 void displaySlice(OutputDev *out, double hDPI, double vDPI, 216 int rotate, GBool useMediaBox, GBool crop, 217 int sliceX, int sliceY, int sliceW, int sliceH, 218 GBool printing, Catalog *catalog, 219 GBool (*abortCheckCbk)(void *data) = NULL, 220 void *abortCheckCbkData = NULL, 221 GBool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = NULL, 222 void *annotDisplayDecideCbkData = NULL); 223 224 void display(Gfx *gfx); 225 226 void makeBox(double hDPI, double vDPI, int rotate, 227 GBool useMediaBox, GBool upsideDown, 228 double sliceX, double sliceY, double sliceW, double sliceH, 229 PDFRectangle *box, GBool *crop); 230 231 void processLinks(OutputDev *out, Catalog *catalog); 232 233 // Get the page's default CTM. 234 void getDefaultCTM(double *ctm, double hDPI, double vDPI, 235 int rotate, GBool useMediaBox, GBool upsideDown); 236 237 private: 238 239 XRef *xref; // the xref table for this PDF file 240 Object pageObj; // page dictionary 241 Ref pageRef; // page reference 242 int num; // page number 243 PageAttrs *attrs; // page attributes 244 Object annots; // annotations array 245 Object contents; // page contents 246 FormPageWidgets *pageWidgets; // the form for that page 247 Object thumb; // page thumbnail 248 Object trans; // page transition 249 Object actions; // page addiction actions 250 double duration; // page duration 251 GBool ok; // true if page is valid 252 }; 253 254 #endif 255