Back to index

tetex-bin  3.0
Page.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // Page.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef PAGE_H
00010 #define PAGE_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include "Object.h"
00019 
00020 class Dict;
00021 class XRef;
00022 class OutputDev;
00023 class Links;
00024 class Catalog;
00025 
00026 //------------------------------------------------------------------------
00027 
00028 class PDFRectangle {
00029 public:
00030   double x1, y1, x2, y2;
00031 
00032   PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
00033   PDFRectangle(double x1A, double y1A, double x2A, double y2A)
00034     { x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
00035   GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
00036 };
00037 
00038 //------------------------------------------------------------------------
00039 // PageAttrs
00040 //------------------------------------------------------------------------
00041 
00042 class PageAttrs {
00043 public:
00044 
00045   // Construct a new PageAttrs object by merging a dictionary
00046   // (of type Pages or Page) into another PageAttrs object.  If
00047   // <attrs> is NULL, uses defaults.
00048   PageAttrs(PageAttrs *attrs, Dict *dict);
00049 
00050   // Destructor.
00051   ~PageAttrs();
00052 
00053   // Accessors.
00054   PDFRectangle *getBox() { return limitToCropBox ? &cropBox : &mediaBox; }
00055   PDFRectangle *getMediaBox() { return &mediaBox; }
00056   PDFRectangle *getCropBox() { return &cropBox; }
00057   GBool isCropped() { return haveCropBox; }
00058   PDFRectangle *getBleedBox() { return &bleedBox; }
00059   PDFRectangle *getTrimBox() { return &trimBox; }
00060   PDFRectangle *getArtBox() { return &artBox; }
00061   int getRotate() { return rotate; }
00062   GString *getLastModified()
00063     { return lastModified.isString()
00064        ? lastModified.getString() : (GString *)NULL; }
00065   Dict *getBoxColorInfo()
00066     { return boxColorInfo.isDict() ? boxColorInfo.getDict() : (Dict *)NULL; }
00067   Dict *getGroup()
00068     { return group.isDict() ? group.getDict() : (Dict *)NULL; }
00069   Stream *getMetadata()
00070     { return metadata.isStream() ? metadata.getStream() : (Stream *)NULL; }
00071   Dict *getPieceInfo()
00072     { return pieceInfo.isDict() ? pieceInfo.getDict() : (Dict *)NULL; }
00073   Dict *getSeparationInfo()
00074     { return separationInfo.isDict()
00075        ? separationInfo.getDict() : (Dict *)NULL; }
00076   Dict *getResourceDict()
00077     { return resources.isDict() ? resources.getDict() : (Dict *)NULL; }
00078 
00079 private:
00080 
00081   GBool readBox(Dict *dict, char *key, PDFRectangle *box);
00082 
00083   PDFRectangle mediaBox;
00084   PDFRectangle cropBox;
00085   GBool haveCropBox;
00086   GBool limitToCropBox;
00087   PDFRectangle bleedBox;
00088   PDFRectangle trimBox;
00089   PDFRectangle artBox;
00090   int rotate;
00091   Object lastModified;
00092   Object boxColorInfo;
00093   Object group;
00094   Object metadata;
00095   Object pieceInfo;
00096   Object separationInfo;
00097   Object resources;
00098 };
00099 
00100 //------------------------------------------------------------------------
00101 // Page
00102 //------------------------------------------------------------------------
00103 
00104 class Page {
00105 public:
00106 
00107   // Constructor.
00108   Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA);
00109 
00110   // Destructor.
00111   ~Page();
00112 
00113   // Is page valid?
00114   GBool isOk() { return ok; }
00115 
00116   // Get page parameters.
00117   PDFRectangle *getBox() { return attrs->getBox(); }
00118   PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
00119   PDFRectangle *getCropBox() { return attrs->getCropBox(); }
00120   GBool isCropped() { return attrs->isCropped(); }
00121   double getWidth() { return attrs->getBox()->x2 - attrs->getBox()->x1; }
00122   double getHeight() { return attrs->getBox()->y2 - attrs->getBox()->y1; }
00123   PDFRectangle *getBleedBox() { return attrs->getBleedBox(); }
00124   PDFRectangle *getTrimBox() { return attrs->getTrimBox(); }
00125   PDFRectangle *getArtBox() { return attrs->getArtBox(); }
00126   int getRotate() { return attrs->getRotate(); }
00127   GString *getLastModified() { return attrs->getLastModified(); }
00128   Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
00129   Dict *getGroup() { return attrs->getGroup(); }
00130   Stream *getMetadata() { return attrs->getMetadata(); }
00131   Dict *getPieceInfo() { return attrs->getPieceInfo(); }
00132   Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
00133 
00134   // Get resource dictionary.
00135   Dict *getResourceDict() { return attrs->getResourceDict(); }
00136 
00137   // Get annotations array.
00138   Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
00139 
00140   // Get contents.
00141   Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
00142 
00143   // Display a page.
00144   void display(OutputDev *out, double hDPI, double vDPI,
00145               int rotate, GBool crop,
00146               Links *links, Catalog *catalog,
00147               GBool (*abortCheckCbk)(void *data) = NULL,
00148               void *abortCheckCbkData = NULL);
00149 
00150   // Display part of a page.
00151   void displaySlice(OutputDev *out, double hDPI, double vDPI,
00152                   int rotate, GBool crop,
00153                   int sliceX, int sliceY, int sliceW, int sliceH,
00154                   Links *links, Catalog *catalog,
00155                   GBool (*abortCheckCbk)(void *data) = NULL,
00156                   void *abortCheckCbkData = NULL);
00157 
00158 private:
00159 
00160   XRef *xref;               // the xref table for this PDF file
00161   int num;                  // page number
00162   PageAttrs *attrs;         // page attributes
00163   Object annots;            // annotations array
00164   Object contents;          // page contents
00165   GBool ok;                 // true if page is valid
00166 };
00167 
00168 #endif