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 #if MULTITHREADED
19 #include "GMutex.h"
20 #endif
21 #include "CharTypes.h"
22 
23 class GList;
24 class PDFDoc;
25 class XRef;
26 class Object;
27 class Page;
28 class PageAttrs;
29 struct Ref;
30 class LinkDest;
31 class PageTreeNode;
32 class PageLabelNode;
33 class AcroForm;
34 class TextString;
35 
36 //------------------------------------------------------------------------
37 // Catalog
38 //------------------------------------------------------------------------
39 
40 class Catalog {
41 public:
42 
43   // Constructor.
44   Catalog(PDFDoc *docA);
45 
46   // Destructor.
47   ~Catalog();
48 
49   // Is catalog valid?
isOk()50   GBool isOk() { return ok; }
51 
52   // Get number of pages.
getNumPages()53   int getNumPages() { return numPages; }
54 
55   // Get a page.
56   Page *getPage(int i);
57 
58   // Get the reference for a page object.
59   Ref *getPageRef(int i);
60 
61   // Remove a page from the catalog.  (It can be reloaded later by
62   // calling getPage).
63   void doneWithPage(int i);
64 
65   // Return base URI, or NULL if none.
getBaseURI()66   GString *getBaseURI() { return baseURI; }
67 
68   // Return the contents of the metadata stream, or NULL if there is
69   // no metadata.
70   GString *readMetadata();
71 
72   // Return the structure tree root object.
getStructTreeRoot()73   Object *getStructTreeRoot() { return &structTreeRoot; }
74 
75   // Find a page, given its object ID.  Returns page number, or 0 if
76   // not found.
77   int findPage(int num, int gen);
78 
79   // Find a named destination.  Returns the link destination, or
80   // NULL if <name> is not a destination.
81   LinkDest *findDest(GString *name);
82 
getDests()83   Object *getDests() { return &dests; }
84 
getNameTree()85   Object *getNameTree() { return &nameTree; }
86 
getOutline()87   Object *getOutline() { return &outline; }
88 
getAcroForm()89   Object *getAcroForm() { return &acroForm; }
90 
getForm()91   AcroForm *getForm() { return form; }
92 
getNeedsRendering()93   GBool getNeedsRendering() { return needsRendering; }
94 
getOCProperties()95   Object *getOCProperties() { return &ocProperties; }
96 
97   // Return the DestOutputProfile stream, or NULL if there isn't one.
98   Object *getDestOutputProfile(Object *destOutProf);
99 
100   // Get the list of embedded files.
101   int getNumEmbeddedFiles();
102   Unicode *getEmbeddedFileName(int idx);
103   int getEmbeddedFileNameLength(int idx);
104   Object *getEmbeddedFileStreamRef(int idx);
105   Object *getEmbeddedFileStreamObj(int idx, Object *strObj);
106 
107   // Return true if the document has page labels.
hasPageLabels()108   GBool hasPageLabels() { return pageLabels != NULL; }
109 
110   // Get the page label for page number [pageNum].  Returns NULL if
111   // the PDF file doesn't have page labels.
112   TextString *getPageLabel(int pageNum);
113 
114   // Returns the page number corresponding to [pageLabel].  Returns -1
115   // if there is no matching page label, or if the document doesn't
116   // have page labels.
117   int getPageNumFromPageLabel(TextString *pageLabel);
118 
getViewerPreferences()119   Object *getViewerPreferences() { return &viewerPrefs; }
120 
121 private:
122 
123   PDFDoc *doc;
124   XRef *xref;			// the xref table for this PDF file
125   PageTreeNode *pageTree;	// the page tree
126   Page **pages;			// array of pages
127   Ref *pageRefs;		// object ID for each page
128 #if MULTITHREADED
129   GMutex pageMutex;
130 #endif
131   int numPages;			// number of pages
132   Object dests;			// named destination dictionary
133   Object nameTree;		// name tree
134   GString *baseURI;		// base URI for URI-type links
135   Object metadata;		// metadata stream
136   Object structTreeRoot;	// structure tree root dictionary
137   Object outline;		// outline dictionary
138   Object acroForm;		// AcroForm dictionary
139   GBool needsRendering;		// NeedsRendering flag
140   AcroForm *form;		// parsed form
141   Object ocProperties;		// OCProperties dictionary
142   GList *embeddedFiles;		// embedded file list [EmbeddedFile]
143   GList *pageLabels;		// page labels [PageLabelNode]
144   Object viewerPrefs;		// ViewerPreferences object
145   GBool ok;			// true if catalog is valid
146 
147   Object *findDestInTree(Object *tree, GString *name, Object *obj);
148   GBool readPageTree(Object *catDict);
149   int countPageTree(Object *pagesObj);
150   void loadPage(int pg);
151   void loadPage2(int pg, int relPg, PageTreeNode *node);
152   void readEmbeddedFileList(Dict *catDict);
153   void readEmbeddedFileTree(Object *node);
154   void readFileAttachmentAnnots(Object *pageNodeRef,
155 				char *touchedObjs);
156   void readEmbeddedFile(Object *fileSpec, Object *name1);
157   void readPageLabelTree(Object *root);
158   void readPageLabelTree2(Object *node);
159   PageLabelNode *findPageLabel(int pageNum);
160   GString *makeRomanNumeral(int num, GBool uppercase);
161   GString *makeLetterLabel(int num, GBool uppercase);
162   GBool convertPageLabelToInt(TextString *pageLabel, int prefixLength,
163 			      char style, int *n);
164 };
165 
166 #endif
167