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 PDFDoc; 22 class XRef; 23 class OutputDev; 24 class Links; 25 26 //------------------------------------------------------------------------ 27 28 class PDFRectangle { 29 public: 30 double x1, y1, x2, y2; 31 PDFRectangle()32 PDFRectangle() { x1 = y1 = x2 = y2 = 0; } PDFRectangle(double x1A,double y1A,double x2A,double y2A)33 PDFRectangle(double x1A, double y1A, double x2A, double y2A) 34 { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; } isValid()35 GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; } 36 void clipTo(PDFRectangle *rect); 37 }; 38 39 //------------------------------------------------------------------------ 40 // PageAttrs 41 //------------------------------------------------------------------------ 42 43 class PageAttrs { 44 public: 45 46 // Construct a new PageAttrs object by merging a dictionary 47 // (of type Pages or Page) into another PageAttrs object. If 48 // <attrs> is NULL, uses defaults. 49 PageAttrs(PageAttrs *attrs, Dict *dict); 50 51 // Construct a new PageAttrs object for an empty page (only used 52 // when there is an error in the page tree). 53 PageAttrs(); 54 55 // Destructor. 56 ~PageAttrs(); 57 58 // Accessors. getMediaBox()59 PDFRectangle *getMediaBox() { return &mediaBox; } getCropBox()60 PDFRectangle *getCropBox() { return &cropBox; } isCropped()61 GBool isCropped() { return haveCropBox; } getBleedBox()62 PDFRectangle *getBleedBox() { return &bleedBox; } getTrimBox()63 PDFRectangle *getTrimBox() { return &trimBox; } getArtBox()64 PDFRectangle *getArtBox() { return &artBox; } getRotate()65 int getRotate() { return rotate; } getLastModified()66 GString *getLastModified() 67 { return lastModified.isString() 68 ? lastModified.getString() : (GString *)NULL; } getBoxColorInfo()69 Dict *getBoxColorInfo() 70 { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; } getGroup()71 Dict *getGroup() 72 { return group.isDict() ? group.getDict() : (Dict *)NULL; } getMetadata()73 Stream *getMetadata() 74 { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; } getPieceInfo()75 Dict *getPieceInfo() 76 { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; } getSeparationInfo()77 Dict *getSeparationInfo() 78 { return separationInfo.isDict() 79 ? separationInfo.getDict() : (Dict *)NULL; } getUserUnit()80 double getUserUnit() { return userUnit; } getResourceDict()81 Dict *getResourceDict() 82 { return resources.isDict() ? resources.getDict() : (Dict *)NULL; } 83 84 // Clip all other boxes to the MediaBox. 85 void clipBoxes(); 86 87 private: 88 89 GBool readBox(Dict *dict, const char *key, PDFRectangle *box); 90 91 PDFRectangle mediaBox; 92 PDFRectangle cropBox; 93 GBool haveCropBox; 94 PDFRectangle bleedBox; 95 PDFRectangle trimBox; 96 PDFRectangle artBox; 97 int rotate; 98 Object lastModified; 99 Object boxColorInfo; 100 Object group; 101 Object metadata; 102 Object pieceInfo; 103 Object separationInfo; 104 double userUnit; 105 Object resources; 106 }; 107 108 //------------------------------------------------------------------------ 109 // Page 110 //------------------------------------------------------------------------ 111 112 class Page { 113 public: 114 115 // Constructor. 116 Page(PDFDoc *docA, int numA, Dict *pageDict, PageAttrs *attrsA); 117 118 // Create an empty page (only used when there is an error in the 119 // page tree). 120 Page(PDFDoc *docA, int numA); 121 122 // Destructor. 123 ~Page(); 124 125 // Is page valid? isOk()126 GBool isOk() { return ok; } 127 128 // Get page parameters. getNum()129 int getNum() { return num; } getAttrs()130 PageAttrs *getAttrs() { return attrs; } getMediaBox()131 PDFRectangle *getMediaBox() { return attrs->getMediaBox(); } getCropBox()132 PDFRectangle *getCropBox() { return attrs->getCropBox(); } isCropped()133 GBool isCropped() { return attrs->isCropped(); } getMediaWidth()134 double getMediaWidth() 135 { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; } getMediaHeight()136 double getMediaHeight() 137 { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; } getCropWidth()138 double getCropWidth() 139 { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; } getCropHeight()140 double getCropHeight() 141 { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; } getBleedBox()142 PDFRectangle *getBleedBox() { return attrs->getBleedBox(); } getTrimBox()143 PDFRectangle *getTrimBox() { return attrs->getTrimBox(); } getArtBox()144 PDFRectangle *getArtBox() { return attrs->getArtBox(); } getRotate()145 int getRotate() { return attrs->getRotate(); } getLastModified()146 GString *getLastModified() { return attrs->getLastModified(); } getBoxColorInfo()147 Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); } getGroup()148 Dict *getGroup() { return attrs->getGroup(); } getMetadata()149 Stream *getMetadata() { return attrs->getMetadata(); } getPieceInfo()150 Dict *getPieceInfo() { return attrs->getPieceInfo(); } getSeparationInfo()151 Dict *getSeparationInfo() { return attrs->getSeparationInfo(); } getUserUnit()152 double getUserUnit() { return attrs->getUserUnit(); } 153 154 // Get resource dictionary. getResourceDict()155 Dict *getResourceDict() { return attrs->getResourceDict(); } 156 157 // Get annotations array. getAnnots(Object * obj)158 Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); } 159 160 // Return a list of links. 161 Links *getLinks(); 162 163 // Get contents. getContents(Object * obj)164 Object *getContents(Object *obj) { return contents.fetch(xref, obj); } 165 166 // Get the page's thumbnail image. getThumbnail(Object * obj)167 Object *getThumbnail(Object *obj) { return thumbnail.fetch(xref, obj); } 168 169 // Display a page. 170 void display(OutputDev *out, double hDPI, double vDPI, 171 int rotate, GBool useMediaBox, GBool crop, 172 GBool printing, 173 GBool (*abortCheckCbk)(void *data) = NULL, 174 void *abortCheckCbkData = NULL); 175 176 // Display part of a page. 177 void displaySlice(OutputDev *out, double hDPI, double vDPI, 178 int rotate, GBool useMediaBox, GBool crop, 179 int sliceX, int sliceY, int sliceW, int sliceH, 180 GBool printing, 181 GBool (*abortCheckCbk)(void *data) = NULL, 182 void *abortCheckCbkData = NULL); 183 184 void makeBox(double hDPI, double vDPI, int rotate, 185 GBool useMediaBox, GBool upsideDown, 186 double sliceX, double sliceY, double sliceW, double sliceH, 187 PDFRectangle *box, GBool *crop); 188 189 void processLinks(OutputDev *out); 190 191 // Get the page's default CTM. 192 void getDefaultCTM(double *ctm, double hDPI, double vDPI, 193 int rotate, GBool useMediaBox, GBool upsideDown); 194 195 private: 196 197 PDFDoc *doc; 198 XRef *xref; // the xref table for this PDF file 199 int num; // page number 200 PageAttrs *attrs; // page attributes 201 Object annots; // annotations array 202 Object contents; // page contents 203 Object thumbnail; // reference to thumbnail image 204 GBool ok; // true if page is valid 205 }; 206 207 #endif 208