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; } getMediaBox()130 PDFRectangle *getMediaBox() { return attrs->getMediaBox(); } getCropBox()131 PDFRectangle *getCropBox() { return attrs->getCropBox(); } isCropped()132 GBool isCropped() { return attrs->isCropped(); } getMediaWidth()133 double getMediaWidth() 134 { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; } getMediaHeight()135 double getMediaHeight() 136 { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; } getCropWidth()137 double getCropWidth() 138 { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; } getCropHeight()139 double getCropHeight() 140 { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; } getBleedBox()141 PDFRectangle *getBleedBox() { return attrs->getBleedBox(); } getTrimBox()142 PDFRectangle *getTrimBox() { return attrs->getTrimBox(); } getArtBox()143 PDFRectangle *getArtBox() { return attrs->getArtBox(); } getRotate()144 int getRotate() { return attrs->getRotate(); } getLastModified()145 GString *getLastModified() { return attrs->getLastModified(); } getBoxColorInfo()146 Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); } getGroup()147 Dict *getGroup() { return attrs->getGroup(); } getMetadata()148 Stream *getMetadata() { return attrs->getMetadata(); } getPieceInfo()149 Dict *getPieceInfo() { return attrs->getPieceInfo(); } getSeparationInfo()150 Dict *getSeparationInfo() { return attrs->getSeparationInfo(); } getUserUnit()151 double getUserUnit() { return attrs->getUserUnit(); } 152 153 // Get resource dictionary. getResourceDict()154 Dict *getResourceDict() { return attrs->getResourceDict(); } 155 156 // Get annotations array. getAnnots(Object * obj)157 Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); } 158 159 // Return a list of links. 160 Links *getLinks(); 161 162 // Get contents. getContents(Object * obj)163 Object *getContents(Object *obj) { return contents.fetch(xref, obj); } 164 165 // Display a page. 166 void display(OutputDev *out, double hDPI, double vDPI, 167 int rotate, GBool useMediaBox, GBool crop, 168 GBool printing, 169 GBool (*abortCheckCbk)(void *data) = NULL, 170 void *abortCheckCbkData = NULL); 171 172 // Display part of a page. 173 void displaySlice(OutputDev *out, double hDPI, double vDPI, 174 int rotate, GBool useMediaBox, GBool crop, 175 int sliceX, int sliceY, int sliceW, int sliceH, 176 GBool printing, 177 GBool (*abortCheckCbk)(void *data) = NULL, 178 void *abortCheckCbkData = NULL); 179 180 void makeBox(double hDPI, double vDPI, int rotate, 181 GBool useMediaBox, GBool upsideDown, 182 double sliceX, double sliceY, double sliceW, double sliceH, 183 PDFRectangle *box, GBool *crop); 184 185 void processLinks(OutputDev *out); 186 187 // Get the page's default CTM. 188 void getDefaultCTM(double *ctm, double hDPI, double vDPI, 189 int rotate, GBool useMediaBox, GBool upsideDown); 190 191 private: 192 193 PDFDoc *doc; 194 XRef *xref; // the xref table for this PDF file 195 int num; // page number 196 PageAttrs *attrs; // page attributes 197 Object annots; // annotations array 198 Object contents; // page contents 199 GBool ok; // true if page is valid 200 }; 201 202 #endif 203