Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:49

0001 //========================================================================
0002 //
0003 // Page.h
0004 //
0005 // Copyright 1996-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
0017 // Copyright (C) 2005 Jeff Muizelaar <jeff@infidigm.net>
0018 // Copyright (C) 2006 Pino Toscano <pino@kde.org>
0019 // Copyright (C) 2006, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
0020 // Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org>
0021 // Copyright (C) 2008 Iñigo Martínez <inigomartinez@gmail.com>
0022 // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
0023 // Copyright (C) 2012, 2017, 2018, 2020, 2021, 2023 Albert Astals Cid <aacid@kde.org>
0024 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
0025 // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
0026 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0027 // Copyright (C) 2020 Oliver Sander <oliver.sander@tu-dresden.de>
0028 // Copyright (C) 2020, 2021 Nelson Benítez León <nbenitezl@gmail.com>
0029 //
0030 // To see a description of the changes please see the Changelog file that
0031 // came with your tarball or type make ChangeLog if you are building from git
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 // PageAttrs
0082 //------------------------------------------------------------------------
0083 
0084 class PageAttrs
0085 {
0086 public:
0087     // Construct a new PageAttrs object by merging a dictionary
0088     // (of type Pages or Page) into another PageAttrs object.  If
0089     // <attrs> is nullptr, uses defaults.
0090     PageAttrs(PageAttrs *attrs, Dict *dict);
0091 
0092     // Destructor.
0093     ~PageAttrs();
0094 
0095     // Accessors.
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     // Clip all other boxes to the MediaBox.
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 // Page
0137 //------------------------------------------------------------------------
0138 
0139 class POPPLER_PRIVATE_EXPORT Page
0140 {
0141 public:
0142     // Constructor.
0143     Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *attrsA, Form *form);
0144 
0145     // Destructor.
0146     ~Page();
0147 
0148     Page(const Page &) = delete;
0149     Page &operator=(const Page &) = delete;
0150 
0151     // Is page valid?
0152     bool isOk() const { return ok; }
0153 
0154     // Get page parameters.
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     // Get resource dictionary.
0177     Dict *getResourceDict();
0178     Object *getResourceDictObject();
0179     Dict *getResourceDictCopy(XRef *xrefA);
0180 
0181     // Get annotations array.
0182     Object getAnnotsObject(XRef *xrefA = nullptr) { return annotsObj.fetch(xrefA ? xrefA : xref); }
0183     // Add a new annotation to the page
0184     bool addAnnot(Annot *annot);
0185     // Remove an existing annotation from the page
0186     void removeAnnot(Annot *annot);
0187 
0188     // Return a list of links.
0189     std::unique_ptr<Links> getLinks();
0190 
0191     // Return a list of annots. It will be valid until the page is destroyed
0192     Annots *getAnnots(XRef *xrefA = nullptr);
0193 
0194     // Get contents.
0195     Object getContents() { return contents.fetch(xref); }
0196 
0197     // Get thumb.
0198     Object getThumb() { return thumb.fetch(xref); }
0199     bool loadThumb(unsigned char **data, int *width, int *height, int *rowstride);
0200 
0201     // Get transition.
0202     Object getTrans() { return trans.fetch(xref); }
0203 
0204     // Get form.
0205     std::unique_ptr<FormPageWidgets> getFormWidgets();
0206 
0207     // Get duration, the maximum length of time, in seconds,
0208     // that the page is displayed before the presentation automatically
0209     // advances to the next page
0210     double getDuration() { return duration; }
0211 
0212     // Get actions
0213     Object getActions() { return actions.fetch(xref); }
0214 
0215     enum PageAdditionalActionsType
0216     {
0217         actionOpenPage, ///< Performed when opening the page
0218         actionClosePage, ///< Performed when closing the page
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     // Display a page.
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     // Display part of a page.
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     // Get the page's default CTM.
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     // replace xref
0247     void replaceXRef(XRef *xrefA);
0248 
0249     PDFDoc *doc;
0250     XRef *xref; // the xref table for this PDF file
0251     Object pageObj; // page dictionary
0252     const Ref pageRef; // page reference
0253     int num; // page number
0254     PageAttrs *attrs; // page attributes
0255     Annots *annots; // annotations
0256     Object annotsObj; // annotations array
0257     Object contents; // page contents
0258     Object thumb; // page thumbnail
0259     Object trans; // page transition
0260     Object actions; // page additional actions
0261     double duration; // page duration
0262     bool ok; // true if page is valid
0263     mutable std::recursive_mutex mutex;
0264     // standalone widgets are special FormWidget's inside a Page that *are not*
0265     // referenced from the Catalog's Field array. That means they are standlone,
0266     // i.e. the PDF document does not have a FormField associated with them. We
0267     // create standalone FormFields to contain those special FormWidgets, as
0268     // they are 'de facto' being used to implement tooltips. See #34
0269     std::vector<FormField *> standaloneFields;
0270     void loadStandaloneFields(Annots *annotations, Form *form);
0271 };
0272 
0273 #endif