File indexing completed on 2025-12-10 10:23:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef PAGE_H
0036 #define PAGE_H
0037
0038 #include <memory>
0039 #include <mutex>
0040
0041 #include "poppler-config.h"
0042 #include "Object.h"
0043 #include "poppler_private_export.h"
0044
0045 class Dict;
0046 class PDFDoc;
0047 class XRef;
0048 class OutputDev;
0049 class Links;
0050 class LinkAction;
0051 class Annots;
0052 class Annot;
0053 class Gfx;
0054 class FormPageWidgets;
0055 class Form;
0056 class FormField;
0057
0058
0059
0060 class PDFRectangle
0061 {
0062 public:
0063 double x1, y1, x2, y2;
0064
0065 PDFRectangle() { x1 = y1 = x2 = y2 = 0; }
0066 PDFRectangle(double x1A, double y1A, double x2A, double y2A)
0067 {
0068 x1 = x1A;
0069 y1 = y1A;
0070 x2 = x2A;
0071 y2 = y2A;
0072 }
0073 bool isValid() const { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
0074 bool contains(double x, double y) const { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
0075 void clipTo(PDFRectangle *rect);
0076
0077 bool operator==(const PDFRectangle &rect) const { return x1 == rect.x1 && y1 == rect.y1 && x2 == rect.x2 && y2 == rect.y2; }
0078 };
0079
0080
0081
0082
0083
0084 class PageAttrs
0085 {
0086 public:
0087
0088
0089
0090 PageAttrs(PageAttrs *attrs, Dict *dict);
0091
0092
0093 ~PageAttrs();
0094
0095
0096 const PDFRectangle *getMediaBox() const { return &mediaBox; }
0097 const PDFRectangle *getCropBox() const { return &cropBox; }
0098 bool isCropped() const { return haveCropBox; }
0099 const PDFRectangle *getBleedBox() const { return &bleedBox; }
0100 const PDFRectangle *getTrimBox() const { return &trimBox; }
0101 const PDFRectangle *getArtBox() const { return &artBox; }
0102 int getRotate() const { return rotate; }
0103 const GooString *getLastModified() const { return lastModified.isString() ? lastModified.getString() : nullptr; }
0104 Dict *getBoxColorInfo() { return boxColorInfo.isDict() ? boxColorInfo.getDict() : nullptr; }
0105 Dict *getGroup() { return group.isDict() ? group.getDict() : nullptr; }
0106 Stream *getMetadata() { return metadata.isStream() ? metadata.getStream() : nullptr; }
0107 Dict *getPieceInfo() { return pieceInfo.isDict() ? pieceInfo.getDict() : nullptr; }
0108 Dict *getSeparationInfo() { return separationInfo.isDict() ? separationInfo.getDict() : nullptr; }
0109 Dict *getResourceDict() { return resources.isDict() ? resources.getDict() : nullptr; }
0110 Object *getResourceDictObject() { return &resources; }
0111 void replaceResource(Object &&obj1) { resources = std::move(obj1); }
0112
0113
0114 void clipBoxes();
0115
0116 private:
0117 bool readBox(Dict *dict, const char *key, PDFRectangle *box);
0118
0119 PDFRectangle mediaBox;
0120 PDFRectangle cropBox;
0121 bool haveCropBox;
0122 PDFRectangle bleedBox;
0123 PDFRectangle trimBox;
0124 PDFRectangle artBox;
0125 int rotate;
0126 Object lastModified;
0127 Object boxColorInfo;
0128 Object group;
0129 Object metadata;
0130 Object pieceInfo;
0131 Object separationInfo;
0132 Object resources;
0133 };
0134
0135
0136
0137
0138
0139 class POPPLER_PRIVATE_EXPORT Page
0140 {
0141 public:
0142
0143 Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
0144
0145
0146 ~Page();
0147
0148 Page(const Page &) = delete;
0149 Page &operator=(const Page &) = delete;
0150
0151
0152 bool isOk() const { return ok; }
0153
0154
0155 int getNum() const { return num; }
0156 const PDFRectangle *getMediaBox() const { return attrs->getMediaBox(); }
0157 const PDFRectangle *getCropBox() const { return attrs->getCropBox(); }
0158 bool isCropped() const { return attrs->isCropped(); }
0159 double getMediaWidth() const { return attrs->getMediaBox()->x2 - attrs->getMediaBox()->x1; }
0160 double getMediaHeight() const { return attrs->getMediaBox()->y2 - attrs->getMediaBox()->y1; }
0161 double getCropWidth() const { return attrs->getCropBox()->x2 - attrs->getCropBox()->x1; }
0162 double getCropHeight() const { return attrs->getCropBox()->y2 - attrs->getCropBox()->y1; }
0163 const PDFRectangle *getBleedBox() const { return attrs->getBleedBox(); }
0164 const PDFRectangle *getTrimBox() const { return attrs->getTrimBox(); }
0165 const PDFRectangle *getArtBox() const { return attrs->getArtBox(); }
0166 int getRotate() const { return attrs->getRotate(); }
0167 const GooString *getLastModified() const { return attrs->getLastModified(); }
0168 Dict *getBoxColorInfo() { return attrs->getBoxColorInfo(); }
0169 Dict *getGroup() { return attrs->getGroup(); }
0170 Stream *getMetadata() { return attrs->getMetadata(); }
0171 Dict *getPieceInfo() { return attrs->getPieceInfo(); }
0172 Dict *getSeparationInfo() { return attrs->getSeparationInfo(); }
0173 PDFDoc *getDoc() { return doc; }
0174 Ref getRef() { return pageRef; }
0175
0176
0177 Dict *getResourceDict();
0178 Object *getResourceDictObject();
0179 Dict *getResourceDictCopy(XRef *xrefA);
0180
0181
0182 Object getAnnotsObject(XRef *xrefA = nullptr) { return annotsObj.fetch(xrefA ? xrefA : xref); }
0183
0184 bool addAnnot(Annot *annot);
0185
0186 void removeAnnot(Annot *annot);
0187
0188
0189 std::unique_ptr<Links> getLinks();
0190
0191
0192 Annots *getAnnots(XRef *xrefA = nullptr);
0193
0194
0195 Object getContents() { return contents.fetch(xref); }
0196
0197
0198 Object getThumb() { return thumb.fetch(xref); }
0199 bool loadThumb(unsigned char **data, int *width, int *height, int *rowstride);
0200
0201
0202 Object getTrans() { return trans.fetch(xref); }
0203
0204
0205 std::unique_ptr<FormPageWidgets> getFormWidgets();
0206
0207
0208
0209
0210 double getDuration() { return duration; }
0211
0212
0213 Object getActions() { return actions.fetch(xref); }
0214
0215 enum PageAdditionalActionsType
0216 {
0217 actionOpenPage,
0218 actionClosePage,
0219 };
0220
0221 std::unique_ptr<LinkAction> getAdditionalAction(PageAdditionalActionsType type);
0222
0223 Gfx *createGfx(OutputDev *out, double hDPI, double vDPI, int rotate, bool useMediaBox, bool crop, int sliceX, int sliceY, int sliceW, int sliceH, bool printing, bool (*abortCheckCbk)(void *data), void *abortCheckCbkData,
0224 XRef *xrefA = nullptr);
0225
0226
0227 void display(OutputDev *out, double hDPI, double vDPI, int rotate, bool useMediaBox, bool crop, bool printing, bool (*abortCheckCbk)(void *data) = nullptr, void *abortCheckCbkData = nullptr,
0228 bool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = nullptr, void *annotDisplayDecideCbkData = nullptr, bool copyXRef = false);
0229
0230
0231 void displaySlice(OutputDev *out, double hDPI, double vDPI, int rotate, bool useMediaBox, bool crop, int sliceX, int sliceY, int sliceW, int sliceH, bool printing, bool (*abortCheckCbk)(void *data) = nullptr,
0232 void *abortCheckCbkData = nullptr, bool (*annotDisplayDecideCbk)(Annot *annot, void *user_data) = nullptr, void *annotDisplayDecideCbkData = nullptr, bool copyXRef = false);
0233
0234 void display(Gfx *gfx);
0235
0236 void makeBox(double hDPI, double vDPI, int rotate, bool useMediaBox, bool upsideDown, double sliceX, double sliceY, double sliceW, double sliceH, PDFRectangle *box, bool *crop);
0237
0238 void processLinks(OutputDev *out);
0239
0240
0241 void getDefaultCTM(double *ctm, double hDPI, double vDPI, int rotate, bool useMediaBox, bool upsideDown);
0242
0243 bool hasStandaloneFields() const { return !standaloneFields.empty(); }
0244
0245 private:
0246
0247 void replaceXRef(XRef *xrefA);
0248
0249 PDFDoc *doc;
0250 XRef *xref;
0251 Object pageObj;
0252 const Ref pageRef;
0253 int num;
0254 PageAttrs *attrs;
0255 Annots *annots;
0256 Object annotsObj;
0257 Object contents;
0258 Object thumb;
0259 Object trans;
0260 Object actions;
0261 double duration;
0262 bool ok;
0263 mutable std::recursive_mutex mutex;
0264
0265
0266
0267
0268
0269 std::vector<FormField *> standaloneFields;
0270 void loadStandaloneFields(Annots *annotations, Form *form);
0271 };
0272
0273 #endif