1 //========================================================================
2 //
3 // Catalog.h
4 //
5 // Copyright 1996-2007 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 #ifndef CATALOG_H
10 #define CATALOG_H
11 
12 #include <aconf.h>
13 
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17 
18 #include "CharTypes.h"
19 
20 class GList;
21 class PDFDoc;
22 class XRef;
23 class Object;
24 class Page;
25 class PageAttrs;
26 struct Ref;
27 class LinkDest;
28 class PageTreeNode;
29 class Form;
30 
31 //------------------------------------------------------------------------
32 // Catalog
33 //------------------------------------------------------------------------
34 
35 class Catalog {
36 public:
37 
38   // Constructor.
39   Catalog(PDFDoc *docA);
40 
41   // Destructor.
42   ~Catalog();
43 
44   // Is catalog valid?
isOk()45   GBool isOk() { return ok; }
46 
47   // Get number of pages.
getNumPages()48   int getNumPages() { return numPages; }
49 
50   // Get a page.
51   Page *getPage(int i);
52 
53   // Get the reference for a page object.
54   Ref *getPageRef(int i);
55 
56   // Remove a page from the catalog.  (It can be reloaded later by
57   // calling getPage).
58   void doneWithPage(int i);
59 
60   // Return base URI, or NULL if none.
getBaseURI()61   GString *getBaseURI() { return baseURI; }
62 
63   // Return the contents of the metadata stream, or NULL if there is
64   // no metadata.
65   GString *readMetadata();
66 
67   // Return the structure tree root object.
getStructTreeRoot()68   Object *getStructTreeRoot() { return &structTreeRoot; }
69 
70   // Find a page, given its object ID.  Returns page number, or 0 if
71   // not found.
72   int findPage(int num, int gen);
73 
74   // Find a named destination.  Returns the link destination, or
75   // NULL if <name> is not a destination.
76   LinkDest *findDest(GString *name);
77 
getDests()78   Object *getDests() { return &dests; }
79 
getNameTree()80   Object *getNameTree() { return &nameTree; }
81 
getOutline()82   Object *getOutline() { return &outline; }
83 
getAcroForm()84   Object *getAcroForm() { return &acroForm; }
85 
getForm()86   Form *getForm() { return form; }
87 
getOCProperties()88   Object *getOCProperties() { return &ocProperties; }
89 
90   // Get the list of embedded files.
91   int getNumEmbeddedFiles();
92   Unicode *getEmbeddedFileName(int idx);
93   int getEmbeddedFileNameLength(int idx);
94   Object *getEmbeddedFileStreamRef(int idx);
95   Object *getEmbeddedFileStreamObj(int idx, Object *strObj);
96 
97 private:
98 
99   PDFDoc *doc;
100   XRef *xref;			// the xref table for this PDF file
101   PageTreeNode *pageTree;	// the page tree
102   Page **pages;			// array of pages
103   Ref *pageRefs;		// object ID for each page
104   int numPages;			// number of pages
105   int pagesSize;		// size of pages array
106   Object dests;			// named destination dictionary
107   Object nameTree;		// name tree
108   GString *baseURI;		// base URI for URI-type links
109   Object metadata;		// metadata stream
110   Object structTreeRoot;	// structure tree root dictionary
111   Object outline;		// outline dictionary
112   Object acroForm;		// AcroForm dictionary
113   Form *form;			// parsed form
114   Object ocProperties;		// OCProperties dictionary
115   GList *embeddedFiles;		// embedded file list [EmbeddedFile]
116   GBool ok;			// true if catalog is valid
117 
118   Object *findDestInTree(Object *tree, GString *name, Object *obj);
119   GBool readPageTree(Object *catDict);
120   int countPageTree(Object *pagesObj);
121   void loadPage(int pg);
122   void loadPage2(int pg, int relPg, PageTreeNode *node);
123   void readEmbeddedFileList(Dict *catDict);
124   void readEmbeddedFileTree(Object *node);
125   void readFileAttachmentAnnots(Object *pageNodeRef,
126 				char *touchedObjs);
127   void readEmbeddedFile(Object *fileSpec, Object *name1);
128 };
129 
130 #endif
131