File indexing completed on 2025-12-10 10:23:45
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
0036
0037
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
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
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;
0103
0104
0105 };
0106
0107
0108
0109
0110
0111 class POPPLER_PRIVATE_EXPORT Catalog
0112 {
0113 public:
0114
0115 explicit Catalog(PDFDoc *docA);
0116
0117
0118 ~Catalog();
0119
0120 Catalog(const Catalog &) = delete;
0121 Catalog &operator=(const Catalog &) = delete;
0122
0123
0124 bool isOk() { return ok; }
0125
0126
0127 int getNumPages();
0128
0129
0130 Page *getPage(int i);
0131
0132
0133 Ref *getPageRef(int i);
0134
0135
0136 const std::optional<std::string> &getBaseURI() const { return baseURI; }
0137
0138
0139
0140 std::unique_ptr<GooString> readMetadata();
0141
0142
0143 StructTreeRoot *getStructTreeRoot();
0144
0145
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
0156
0157 int findPage(const Ref pageRef);
0158
0159
0160
0161 std::unique_ptr<LinkDest> findDest(const GooString *name);
0162
0163 Object *getDests();
0164
0165
0166 int numDests();
0167
0168
0169 const char *getDestsName(int i);
0170
0171
0172 std::unique_ptr<LinkDest> getDestsDest(int i);
0173
0174
0175 int numDestNameTree() { return getDestNameTree()->numEntries(); }
0176
0177
0178 const GooString *getDestNameTreeName(int i) { return getDestNameTree()->getName(i); }
0179
0180
0181 std::unique_ptr<LinkDest> getDestNameTreeDest(int i);
0182
0183
0184 int numEmbeddedFiles() { return getEmbeddedFileNameTree()->numEntries(); }
0185
0186
0187 std::unique_ptr<FileSpec> embeddedFile(int i);
0188
0189
0190 bool hasEmbeddedFile(const std::string &fileName);
0191
0192
0193
0194
0195 void addEmbeddedFile(GooFile *file, const std::string &fileName);
0196
0197
0198 int numJS() { return getJSNameTree()->numEntries(); }
0199 const GooString *getJSName(int i) { return getJSNameTree()->getName(i); }
0200
0201
0202 GooString *getJS(int i);
0203
0204
0205 bool labelToIndex(GooString *label, int *index);
0206 bool indexToLabel(int index, GooString *label);
0207
0208 Object *getOutline();
0209
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
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
0259 PageMode getPageMode();
0260 PageLayout getPageLayout();
0261
0262 enum DocumentAdditionalActionsType
0263 {
0264 actionCloseDocument,
0265 actionSaveDocumentStart,
0266 actionSaveDocumentFinish,
0267 actionPrintDocumentStart,
0268 actionPrintDocumentFinish,
0269 };
0270
0271 std::unique_ptr<LinkAction> getAdditionalAction(DocumentAdditionalActionsType type);
0272
0273 private:
0274
0275 PageLabelInfo *getPageLabelInfo();
0276
0277 PDFDoc *doc;
0278 XRef *xref;
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;
0287 Object dests;
0288 Object names;
0289 NameTree *destNameTree;
0290 NameTree *embeddedFileNameTree;
0291 NameTree *jsNameTree;
0292 std::optional<std::string> baseURI;
0293 Object metadata;
0294 StructTreeRoot *structTreeRoot;
0295 unsigned int markInfo;
0296 Object outline;
0297 Object acroForm;
0298 Object viewerPreferences;
0299 OCGs *optContent;
0300 bool ok;
0301 PageLabelInfo *pageLabelInfo;
0302 PageMode pageMode;
0303 PageLayout pageLayout;
0304 Object additionalActions;
0305
0306 bool cachePageTree(int page);
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