Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //========================================================================
0002 //
0003 // Catalog.h
0004 //
0005 // Copyright 1996-2007 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, 2007, 2009-2011, 2013, 2017-2022 Albert Astals Cid <aacid@kde.org>
0018 // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
0019 // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh@frogmouth.net>
0020 // Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org>
0021 // Copyright (C) 2008, 2011 Pino Toscano <pino@kde.org>
0022 // Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
0023 // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
0024 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
0025 // Copyright (C) 2013 Adrian Perez de Castro <aperez@igalia.com>
0026 // Copyright (C) 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
0027 // Copyright (C) 2013 José Aliste <jaliste@src.gnome.org>
0028 // Copyright (C) 2016 Masamichi Hosoda <trueroad@trueroad.jp>
0029 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
0030 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0031 // Copyright (C) 2020 Oliver Sander <oliver.sander@tu-dresden.de>
0032 // Copyright (C) 2020 Katarina Behrens <Katarina.Behrens@cib.de>
0033 // Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
0034 // Copyright (C) 2021 RM <rm+git@arcsin.org>
0035 //
0036 // To see a description of the changes please see the Changelog file that
0037 // came with your tarball or type make ChangeLog if you are building from git
0038 //
0039 //========================================================================
0040 
0041 #ifndef CATALOG_H
0042 #define CATALOG_H
0043 
0044 #include "poppler-config.h"
0045 #include "poppler_private_export.h"
0046 #include "Object.h"
0047 #include "Link.h"
0048 
0049 #include <memory>
0050 #include <optional>
0051 #include <vector>
0052 
0053 class PDFDoc;
0054 class XRef;
0055 class Object;
0056 class Page;
0057 class PageAttrs;
0058 struct Ref;
0059 class PageLabelInfo;
0060 class Form;
0061 class OCGs;
0062 class ViewerPreferences;
0063 class FileSpec;
0064 class StructTreeRoot;
0065 
0066 //------------------------------------------------------------------------
0067 // NameTree
0068 //------------------------------------------------------------------------
0069 
0070 class POPPLER_PRIVATE_EXPORT NameTree
0071 {
0072 public:
0073     NameTree();
0074     ~NameTree();
0075 
0076     NameTree(const NameTree &) = delete;
0077     NameTree &operator=(const NameTree &) = delete;
0078 
0079     void init(XRef *xref, Object *tree);
0080     Object lookup(const GooString *name);
0081     int numEntries() { return length; };
0082     // iterator accessor, note it returns a pointer to the internal object, do not free nor delete it
0083     Object *getValue(int i);
0084     const GooString *getName(int i) const;
0085 
0086 private:
0087     struct Entry
0088     {
0089         Entry(Array *array, int index);
0090         ~Entry();
0091         GooString name;
0092         Object value;
0093         static int cmpEntry(const void *voidEntry, const void *voidOtherEntry);
0094         static int cmp(const void *key, const void *entry);
0095     };
0096 
0097     void parse(const Object *tree, std::set<int> &seen);
0098     void addEntry(Entry *entry);
0099 
0100     XRef *xref;
0101     Entry **entries;
0102     int size, length; // size is the number of entries in
0103                       // the array of Entry*
0104                       // length is the number of real Entry
0105 };
0106 
0107 //------------------------------------------------------------------------
0108 // Catalog
0109 //------------------------------------------------------------------------
0110 
0111 class POPPLER_PRIVATE_EXPORT Catalog
0112 {
0113 public:
0114     // Constructor.
0115     explicit Catalog(PDFDoc *docA);
0116 
0117     // Destructor.
0118     ~Catalog();
0119 
0120     Catalog(const Catalog &) = delete;
0121     Catalog &operator=(const Catalog &) = delete;
0122 
0123     // Is catalog valid?
0124     bool isOk() { return ok; }
0125 
0126     // Get number of pages.
0127     int getNumPages();
0128 
0129     // Get a page.
0130     Page *getPage(int i);
0131 
0132     // Get the reference for a page object.
0133     Ref *getPageRef(int i);
0134 
0135     // Return base URI, or NULL if none.
0136     const std::optional<std::string> &getBaseURI() const { return baseURI; }
0137 
0138     // Return the contents of the metadata stream, or NULL if there is
0139     // no metadata.
0140     std::unique_ptr<GooString> readMetadata();
0141 
0142     // Return the structure tree root object.
0143     StructTreeRoot *getStructTreeRoot();
0144 
0145     // Return values from the MarkInfo dictionary as flags in a bitfield.
0146     enum MarkInfoFlags
0147     {
0148         markInfoNull = 1 << 0,
0149         markInfoMarked = 1 << 1,
0150         markInfoUserProperties = 1 << 2,
0151         markInfoSuspects = 1 << 3,
0152     };
0153     unsigned int getMarkInfo();
0154 
0155     // Find a page, given its object ID.  Returns page number, or 0 if
0156     // not found.
0157     int findPage(const Ref pageRef);
0158 
0159     // Find a named destination.  Returns the link destination, or
0160     // NULL if <name> is not a destination.
0161     std::unique_ptr<LinkDest> findDest(const GooString *name);
0162 
0163     Object *getDests();
0164 
0165     // Get the number of named destinations in name-dict
0166     int numDests();
0167 
0168     // Get the i'th named destination name in name-dict
0169     const char *getDestsName(int i);
0170 
0171     // Get the i'th named destination link destination in name-dict
0172     std::unique_ptr<LinkDest> getDestsDest(int i);
0173 
0174     // Get the number of named destinations in name-tree
0175     int numDestNameTree() { return getDestNameTree()->numEntries(); }
0176 
0177     // Get the i'th named destination name in name-tree
0178     const GooString *getDestNameTreeName(int i) { return getDestNameTree()->getName(i); }
0179 
0180     // Get the i'th named destination link destination in name-tree
0181     std::unique_ptr<LinkDest> getDestNameTreeDest(int i);
0182 
0183     // Get the number of embedded files
0184     int numEmbeddedFiles() { return getEmbeddedFileNameTree()->numEntries(); }
0185 
0186     // Get the i'th file embedded (at the Document level) in the document
0187     std::unique_ptr<FileSpec> embeddedFile(int i);
0188 
0189     // Is there an embedded file with the given name?
0190     bool hasEmbeddedFile(const std::string &fileName);
0191 
0192     // Adds and embeddedFile
0193     // If there is already an existing embedded file with the given fileName
0194     // it gets replaced, if that's not what you want check hasEmbeddedFile first
0195     void addEmbeddedFile(GooFile *file, const std::string &fileName);
0196 
0197     // Get the number of javascript scripts
0198     int numJS() { return getJSNameTree()->numEntries(); }
0199     const GooString *getJSName(int i) { return getJSNameTree()->getName(i); }
0200 
0201     // Get the i'th JavaScript script (at the Document level) in the document
0202     GooString *getJS(int i);
0203 
0204     // Convert between page indices and page labels.
0205     bool labelToIndex(GooString *label, int *index);
0206     bool indexToLabel(int index, GooString *label);
0207 
0208     Object *getOutline();
0209     // returns the existing outline or new one if it doesn't exist
0210     Object *getCreateOutline();
0211 
0212     Object *getAcroForm() { return &acroForm; }
0213     void addFormToAcroForm(const Ref formRef);
0214     void removeFormFromAcroForm(const Ref formRef);
0215     void setAcroFormModified();
0216 
0217     OCGs *getOptContentConfig() { return optContent; }
0218 
0219     int getPDFMajorVersion() const { return catalogPdfMajorVersion; }
0220     int getPDFMinorVersion() const { return catalogPdfMinorVersion; }
0221 
0222     enum FormType
0223     {
0224         NoForm,
0225         AcroForm,
0226         XfaForm
0227     };
0228 
0229     FormType getFormType();
0230     // This can return nullptr if the document is in a very damaged state
0231     Form *getCreateForm();
0232     Form *getForm();
0233 
0234     ViewerPreferences *getViewerPreferences();
0235 
0236     enum PageMode
0237     {
0238         pageModeNone,
0239         pageModeOutlines,
0240         pageModeThumbs,
0241         pageModeFullScreen,
0242         pageModeOC,
0243         pageModeAttach,
0244         pageModeNull
0245     };
0246     enum PageLayout
0247     {
0248         pageLayoutNone,
0249         pageLayoutSinglePage,
0250         pageLayoutOneColumn,
0251         pageLayoutTwoColumnLeft,
0252         pageLayoutTwoColumnRight,
0253         pageLayoutTwoPageLeft,
0254         pageLayoutTwoPageRight,
0255         pageLayoutNull
0256     };
0257 
0258     // Returns the page mode.
0259     PageMode getPageMode();
0260     PageLayout getPageLayout();
0261 
0262     enum DocumentAdditionalActionsType
0263     {
0264         actionCloseDocument, ///< Performed before closing the document
0265         actionSaveDocumentStart, ///< Performed before saving the document
0266         actionSaveDocumentFinish, ///< Performed after saving the document
0267         actionPrintDocumentStart, ///< Performed before printing the document
0268         actionPrintDocumentFinish, ///< Performed after printing the document
0269     };
0270 
0271     std::unique_ptr<LinkAction> getAdditionalAction(DocumentAdditionalActionsType type);
0272 
0273 private:
0274     // Get page label info.
0275     PageLabelInfo *getPageLabelInfo();
0276 
0277     PDFDoc *doc;
0278     XRef *xref; // the xref table for this PDF file
0279     std::vector<std::pair<std::unique_ptr<Page>, Ref>> pages;
0280     std::vector<Object> *pagesList;
0281     std::vector<Ref> *pagesRefList;
0282     std::vector<PageAttrs *> *attrsList;
0283     std::vector<int> *kidsIdxList;
0284     Form *form;
0285     ViewerPreferences *viewerPrefs;
0286     int numPages; // number of pages
0287     Object dests; // named destination dictionary
0288     Object names; // named names dictionary
0289     NameTree *destNameTree; // named destination name-tree
0290     NameTree *embeddedFileNameTree; // embedded file name-tree
0291     NameTree *jsNameTree; // Java Script name-tree
0292     std::optional<std::string> baseURI; // base URI for URI-type links
0293     Object metadata; // metadata stream
0294     StructTreeRoot *structTreeRoot; // structure tree root
0295     unsigned int markInfo; // Flags from MarkInfo dictionary
0296     Object outline; // outline dictionary
0297     Object acroForm; // AcroForm dictionary
0298     Object viewerPreferences; // ViewerPreference dictionary
0299     OCGs *optContent; // Optional Content groups
0300     bool ok; // true if catalog is valid
0301     PageLabelInfo *pageLabelInfo; // info about page labels
0302     PageMode pageMode; // page mode
0303     PageLayout pageLayout; // page layout
0304     Object additionalActions; // page additional actions
0305 
0306     bool cachePageTree(int page); // Cache first <page> pages.
0307     Object *findDestInTree(Object *tree, GooString *name, Object *obj);
0308 
0309     Object *getNames();
0310     NameTree *getDestNameTree();
0311     NameTree *getEmbeddedFileNameTree();
0312     NameTree *getJSNameTree();
0313     std::unique_ptr<LinkDest> createLinkDest(Object *obj);
0314 
0315     int catalogPdfMajorVersion = -1;
0316     int catalogPdfMinorVersion = -1;
0317 
0318     mutable std::recursive_mutex mutex;
0319 };
0320 
0321 #endif