1 : //========================================================================
2 : //
3 : // Catalog.h
4 : //
5 : // Copyright 1996-2007 Glyph & Cog, LLC
6 : //
7 : //========================================================================
8 :
9 : //========================================================================
10 : //
11 : // Modified under the Poppler project - http://poppler.freedesktop.org
12 : //
13 : // All changes made under the Poppler project to this file are licensed
14 : // under GPL version 2 or later
15 : //
16 : // Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
17 : // Copyright (C) 2005, 2007, 2009-2011 Albert Astals Cid <aacid@kde.org>
18 : // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
19 : // Copyright (C) 2005, 2006, 2008 Brad Hards <bradh@frogmouth.net>
20 : // Copyright (C) 2007 Julien Rebetez <julienr@svn.gnome.org>
21 : // Copyright (C) 2008, 2011 Pino Toscano <pino@kde.org>
22 : // Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
23 : // Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
24 : // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
25 : //
26 : // To see a description of the changes please see the Changelog file that
27 : // came with your tarball or type make ChangeLog if you are building from git
28 : //
29 : //========================================================================
30 :
31 : #ifndef CATALOG_H
32 : #define CATALOG_H
33 :
34 : #ifdef USE_GCC_PRAGMAS
35 : #pragma interface
36 : #endif
37 :
38 : #include "poppler-config.h"
39 : #include "Object.h"
40 : #include "goo/GooMutex.h"
41 :
42 : #include <vector>
43 :
44 : class PDFDoc;
45 : class XRef;
46 : class Object;
47 : class Page;
48 : class PageAttrs;
49 : struct Ref;
50 : class LinkDest;
51 : class PageLabelInfo;
52 : class Form;
53 : class OCGs;
54 : class ViewerPreferences;
55 : class FileSpec;
56 :
57 : //------------------------------------------------------------------------
58 : // NameTree
59 : //------------------------------------------------------------------------
60 :
61 : class NameTree {
62 : public:
63 : NameTree();
64 : ~NameTree();
65 : void init(XRef *xref, Object *tree);
66 : GBool lookup(GooString *name, Object *obj);
67 : int numEntries() { return length; };
68 : // iterator accessor, note it returns a shallow copy, do not free the object
69 : Object getValue(int i);
70 : GooString *getName(int i);
71 :
72 : private:
73 : struct Entry {
74 : Entry(Array *array, int index);
75 : ~Entry();
76 : GooString name;
77 : Object value;
78 : void free();
79 : static int cmp(const void *key, const void *entry);
80 : };
81 :
82 : void parse(Object *tree);
83 : void addEntry(Entry *entry);
84 :
85 : XRef *xref;
86 : Object *root;
87 : Entry **entries;
88 : int size, length; // size is the number of entries in
89 : // the array of Entry*
90 : // length is the number of real Entry
91 : };
92 :
93 : //------------------------------------------------------------------------
94 : // Catalog
95 : //------------------------------------------------------------------------
96 :
97 : class Catalog {
98 : public:
99 :
100 : // Constructor.
101 : Catalog(PDFDoc *docA);
102 :
103 : // Destructor.
104 : ~Catalog();
105 :
106 : // Is catalog valid?
107 149 : GBool isOk() { return ok; }
108 :
109 : // Get number of pages.
110 : int getNumPages(GBool lock = gTrue);
111 :
112 : // Get a page.
113 : Page *getPage(int i);
114 :
115 : // Get the reference for a page object.
116 : Ref *getPageRef(int i, GBool lock = gTrue);
117 :
118 : // Return base URI, or NULL if none.
119 : GooString *getBaseURI() { return baseURI; }
120 :
121 : // Return the contents of the metadata stream, or NULL if there is
122 : // no metadata.
123 : GooString *readMetadata();
124 :
125 : // Return the structure tree root object.
126 : Object *getStructTreeRoot();
127 :
128 : // Find a page, given its object ID. Returns page number, or 0 if
129 : // not found.
130 : int findPage(int num, int gen, GBool lock = gTrue);
131 :
132 : // Find a named destination. Returns the link destination, or
133 : // NULL if <name> is not a destination.
134 : LinkDest *findDest(GooString *name);
135 :
136 : Object *getDests();
137 :
138 : // Get the number of embedded files
139 : int numEmbeddedFiles() { return getEmbeddedFileNameTree()->numEntries(); }
140 :
141 : // Get the i'th file embedded (at the Document level) in the document
142 : FileSpec *embeddedFile(int i);
143 :
144 : // Get the number of javascript scripts
145 : int numJS() { return getJSNameTree()->numEntries(); }
146 :
147 : // Get the i'th JavaScript script (at the Document level) in the document
148 : GooString *getJS(int i);
149 :
150 : // Convert between page indices and page labels.
151 : GBool labelToIndex(GooString *label, int *index);
152 : GBool indexToLabel(int index, GooString *label);
153 :
154 : Object *getOutline();
155 :
156 : Object *getAcroForm() { return &acroForm; }
157 :
158 376 : OCGs *getOptContentConfig() { return optContent; }
159 :
160 : enum FormType
161 : {
162 : NoForm,
163 : AcroForm,
164 : XfaForm
165 : };
166 :
167 : FormType getFormType();
168 : Form* getForm(GBool lock = gTrue);
169 :
170 : ViewerPreferences *getViewerPreferences();
171 :
172 : enum PageMode {
173 : pageModeNone,
174 : pageModeOutlines,
175 : pageModeThumbs,
176 : pageModeFullScreen,
177 : pageModeOC,
178 : pageModeAttach,
179 : pageModeNull
180 : };
181 : enum PageLayout {
182 : pageLayoutNone,
183 : pageLayoutSinglePage,
184 : pageLayoutOneColumn,
185 : pageLayoutTwoColumnLeft,
186 : pageLayoutTwoColumnRight,
187 : pageLayoutTwoPageLeft,
188 : pageLayoutTwoPageRight,
189 : pageLayoutNull
190 : };
191 :
192 : // Returns the page mode.
193 : PageMode getPageMode();
194 : PageLayout getPageLayout();
195 :
196 : private:
197 :
198 : // Get page label info.
199 : PageLabelInfo *getPageLabelInfo();
200 :
201 : PDFDoc *doc;
202 : XRef *xref; // the xref table for this PDF file
203 : Page **pages; // array of pages
204 : Ref *pageRefs; // object ID for each page
205 : int lastCachedPage;
206 : std::vector<Dict *> *pagesList;
207 : std::vector<Ref> *pagesRefList;
208 : std::vector<PageAttrs *> *attrsList;
209 : std::vector<int> *kidsIdxList;
210 : Form *form;
211 : ViewerPreferences *viewerPrefs;
212 : int numPages; // number of pages
213 : int pagesSize; // size of pages array
214 : Object dests; // named destination dictionary
215 : Object names; // named names dictionary
216 : NameTree *destNameTree; // named destination name-tree
217 : NameTree *embeddedFileNameTree; // embedded file name-tree
218 : NameTree *jsNameTree; // Java Script name-tree
219 : GooString *baseURI; // base URI for URI-type links
220 : Object metadata; // metadata stream
221 : Object structTreeRoot; // structure tree root dictionary
222 : Object outline; // outline dictionary
223 : Object acroForm; // AcroForm dictionary
224 : Object viewerPreferences; // ViewerPreference dictionary
225 : OCGs *optContent; // Optional Content groups
226 : GBool ok; // true if catalog is valid
227 : PageLabelInfo *pageLabelInfo; // info about page labels
228 : PageMode pageMode; // page mode
229 : PageLayout pageLayout; // page layout
230 :
231 : void createPages(); // create pages for caching
232 : GBool cachePageTree(int page); // Cache first <page> pages.
233 : Object *findDestInTree(Object *tree, GooString *name, Object *obj);
234 :
235 : Object *getNames();
236 : NameTree *getDestNameTree();
237 : NameTree *getEmbeddedFileNameTree();
238 : NameTree *getJSNameTree();
239 : #if MULTITHREADED
240 : GooMutex mutex;
241 : #endif
242 :
243 : };
244 :
245 : #endif
|