1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        pdfobjects.h
3 // Purpose:
4 // Author:      Ulrich Telle
5 // Created:     2006-10-12
6 // Copyright:   (c) Ulrich Telle
7 // Licence:     wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 /// \file pdfobjects.h Interfaces of the wxPdfObject classes
11 
12 #ifndef _PDF_OBJECTS_H_
13 #define _PDF_OBJECTS_H_
14 
15 // wxWidgets headers
16 #include <wx/dynarray.h>
17 #include <wx/mstream.h>
18 #include <wx/string.h>
19 
20 // wxPdfDocument headers
21 #include "wx/pdfdocdef.h"
22 
23 #define OBJTYPE_NULL         1
24 #define OBJTYPE_BOOLEAN      2
25 #define OBJTYPE_NUMBER       3
26 #define OBJTYPE_STRING       4
27 #define OBJTYPE_NAME         5
28 #define OBJTYPE_ARRAY        6
29 #define OBJTYPE_DICTIONARY   7
30 #define OBJTYPE_STREAM       8
31 #define OBJTYPE_INDIRECT     9
32 
33 /// Class representing a base PDF object. (For internal use only)
34 class WXDLLIMPEXP_PDFDOC wxPdfObject
35 {
36 public:
37   /// Constructor
38   wxPdfObject(int type);
39 
40   /// Destructor
41   virtual ~wxPdfObject();
42 
43   /// Get the type of the object
GetType()44   int GetType() { return m_type; }
45 
46   /// Set object and generation number
47   void SetObjNum(int objNum, int objGen = 0);
48 
49   /// Get object number
GetNumber()50   int GetNumber() { return m_objNum; }
51 
52   /// Get generation number
GetGeneration()53   int GetGeneration() { return m_objGen; }
54 
55   /// Set actual object id
SetActualId(int actualId)56   void SetActualId(int actualId) { m_actualId = actualId; }
57 
58   // Get actual object id
GetActualId()59   int GetActualId() { return m_actualId; }
60 
61   /// Flag this object as created through a indirect reference
SetCreatedIndirect(bool indirect)62   void SetCreatedIndirect(bool indirect) { m_indirect = indirect; }
63 
64   /// Check whether this object was created through a indirect reference
IsCreatedIndirect()65   bool IsCreatedIndirect() { return m_indirect; }
66 
67   /// Check whether this object can be in an object stream
68   bool CanBeInObjStm();
69 
70   /// Checks whether this is a wxPdfNull object.
IsNull()71   bool IsNull() { return (m_type == OBJTYPE_NULL); }
72 
73   /// Checks whether this is a wxPdfBoolean object.
IsBoolean()74   bool IsBoolean() { return (m_type == OBJTYPE_BOOLEAN); }
75 
76   /// Checks whether this is a wxPdfNumber object.
IsNumber()77   bool IsNumber() { return (m_type == OBJTYPE_NUMBER); }
78 
79   /// Checks whether this is a wxPdfString object.
IsString()80   bool IsString() { return (m_type == OBJTYPE_STRING); }
81 
82   /// Checks whether this is a wxPdfName object.
IsName()83   bool IsName() { return (m_type == OBJTYPE_NAME); }
84 
85   /// Checks whether this is a wxPdfArray object.
IsArray()86   bool IsArray() { return (m_type == OBJTYPE_ARRAY); }
87 
88   /// Checks whether this is a wxPdfDictionary object.
IsDictionary()89   bool IsDictionary() { return (m_type == OBJTYPE_DICTIONARY); }
90 
91   /// Checks whether this PdfObject is of the type PdfStream.
IsStream()92   bool IsStream() { return (m_type == OBJTYPE_STREAM); }
93 
94   /// Checks if this is an indirect object.
IsIndirect()95   bool IsIndirect() { return (m_type == OBJTYPE_INDIRECT); }
96 
97 protected:
98   int  m_type;     ///< Object type
99   int  m_objNum;   ///< Object number
100   int  m_objGen;   ///< Object generation
101   int  m_actualId; ///< Actual object id
102   bool m_indirect; ///< Flag whether created through indirect reference
103 };
104 
105 /// Class representing a null object. (For internal use only)
106 class WXDLLIMPEXP_PDFDOC wxPdfNull : public wxPdfObject
107 {
108 public:
109   /// Constructor
110   wxPdfNull();
111 
112   /// Destructor
113   virtual ~wxPdfNull();
114 };
115 
116 /// Class representing an indirect reference object. (For internal use only)
117 class WXDLLIMPEXP_PDFDOC wxPdfIndirectReference : public wxPdfObject
118 {
119 public:
120   /// Constructor
121   wxPdfIndirectReference(int number, int generation = 0);
122 
123   /// Destructor
124   virtual ~wxPdfIndirectReference();
125 };
126 
127 /// Class representing a literal object. (For internal use only)
128 class WXDLLIMPEXP_PDFDOC wxPdfLiteral : public wxPdfObject
129 {
130 public:
131   /// Constructor
132   wxPdfLiteral(int type, const wxString& value);
133 
134   /// Destructor
135   virtual ~wxPdfLiteral();
136 
137   /// Get string value of the literal
GetValue()138   wxString GetValue() { return m_value; };
139 
140 private:
141   wxString m_value; ///< Value of the literal
142 };
143 
144 /// Class representing a boolean object. (For internal use only)
145 class WXDLLIMPEXP_PDFDOC wxPdfBoolean : public wxPdfObject
146 {
147 public:
148   /// Constructor
149   wxPdfBoolean(bool value);
150 
151   /// Constructor
152   virtual ~wxPdfBoolean();
153 
154   /// Get boolean value
GetValue()155   bool GetValue() { return m_value; };
156 
157   /// Get boolean value as string
158   wxString GetAsString();
159 
160 private:
161   bool m_value;  ///< Boolean value
162 };
163 
164 /// Class representing a normal string object. (For internal use only)
165 class WXDLLIMPEXP_PDFDOC wxPdfString : public wxPdfObject
166 {
167 public:
168   /// Constructor
169   wxPdfString(const wxString& value);
170 
171   /// Destructor
172   virtual ~wxPdfString();
173 
174   /// Get value of the string
GetValue()175   wxString GetValue() { return m_value; };
176 
177   /// Set hexadecimal string flag
SetIsHexString(bool isHexString)178   void SetIsHexString(bool isHexString) { m_isHexString = isHexString; }
179 
180   /// Check whether string is hexadecimal
IsHexString()181   bool IsHexString() const { return m_isHexString; }
182 
183 private:
184   wxString m_value; ///< Value of the string
185   bool m_isHexString; ///< Flag whether string is a hexadecimal string
186 };
187 
188 /// Class representing a numeric object. (For internal use only)
189 class WXDLLIMPEXP_PDFDOC wxPdfNumber : public wxPdfObject
190 {
191 public:
192   /// Constructor (value as string)
193   wxPdfNumber(const wxString& value);
194 
195   /// Constructor (value as integer)
196   wxPdfNumber(int value);
197 
198   /// Constructor (value as floating point)
199   wxPdfNumber(double value);
200 
201   /// Destructor
202   virtual ~wxPdfNumber();
203 
204   /// Get value as floating point
GetValue()205   double GetValue() { return m_value; }
206 
207   /// Get value as integer
GetInt()208   int GetInt() { return (int) m_value; }
209 
210   /// Get value as string
GetAsString()211   wxString GetAsString() { return m_string; }
212 
213   /// Check whether value is integer
IsInt()214   bool IsInt() { return m_isInt; }
215 
216 private:
217   double   m_value;   ///< Numeric value
218   wxString m_string;  ///< String representation of numeric value
219   bool     m_isInt;   ///< Flag whether value is integer
220 };
221 
222 /// Class representing a name object. (For internal use only)
223 class WXDLLIMPEXP_PDFDOC wxPdfName : public wxPdfObject
224 {
225 public:
226   /// Default constructor
227   wxPdfName();
228 
229   /// Constructor
230   wxPdfName(const wxString& name);
231 
232   /// Destructor
233   virtual ~wxPdfName();
234 
235   /// Get name
GetName()236   wxString GetName() { return m_name; };
237 
238 private:
239   wxString m_name; ///< Name value
240 };
241 
242 /// Class representing an array object. (For internal use only)
243 class WXDLLIMPEXP_PDFDOC wxPdfArray : public wxPdfObject
244 {
245 public:
246   /// Constructor
247   wxPdfArray();
248 
249   /// Destructor
250   virtual ~wxPdfArray();
251 
252   /// Append an object to the array
253   void Add(wxPdfObject* obj);
254 
255   /// Append an integer value to the array
256   void Add(int value);
257 
258   /// Append a floating point value to the array
259   void Add(double value);
260 
261   /// Get the array element with the given index
262   wxPdfObject* Get(size_t index);
263 
264   /// Get the size of the array
GetSize()265   size_t GetSize() { return m_array.GetCount(); }
266 
267 private:
268   wxArrayPtrVoid m_array; ///< Array of objects
269 };
270 
271 /// Hash map class for dictionaries. (For internal use only)
272 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxPdfObject*, wxPdfDictionaryMap, class WXDLLIMPEXP_PDFDOC);
273 
274 /// Class representing a dictionary object. (For internal use only)
275 class WXDLLIMPEXP_PDFDOC wxPdfDictionary : public wxPdfObject
276 {
277 public:
278   /// Constructor
279   wxPdfDictionary();
280 
281   /// Constructor
282   wxPdfDictionary(const wxString& type);
283 
284   /// Destructor
285   virtual ~wxPdfDictionary();
286 
287   /// Add a (name,value) pair to the dictionary
288   void Put(wxPdfName* key, wxPdfObject* value);
289 
290   /// Add a (name,value) pair to the dictionary
291   void Put(const wxString& key, wxPdfObject* value);
292 
293   /// Get the value identified by the given key
294   wxPdfObject* Get(const wxString& key);
295 
296   /// Get the dictionary map
GetHashMap()297   wxPdfDictionaryMap* GetHashMap() { return m_hashMap; }
298 
299 private:
300   wxPdfDictionaryMap* m_hashMap; ///< Dictionary map
301 };
302 
303 /// Class representing a stream object. (For internal use only)
304 class WXDLLIMPEXP_PDFDOC wxPdfStream : public wxPdfObject
305 {
306 public:
307   /// Default constructor
308   wxPdfStream();
309 
310   /// Constructor
311   wxPdfStream(off_t offset);
312 
313   /// Destructor
314   virtual ~wxPdfStream();
315 
316   /// Get the offset of the stream data
GetOffset()317   off_t GetOffset() { return m_offset; }
318 
319   /// Set the associated stream dictionary
SetDictionary(wxPdfDictionary * dictionary)320   void SetDictionary(wxPdfDictionary* dictionary) { m_dictionary = dictionary; }
321 
322   /// Get the associated stream dictionary
GetDictionary()323   wxPdfDictionary* GetDictionary() { return m_dictionary; }
324 
325   /// Set the stream data buffer
SetBuffer(wxMemoryOutputStream * buffer)326   void SetBuffer(wxMemoryOutputStream* buffer) { m_buffer = buffer; }
327 
328   /// Get the stream data buffer
GetBuffer()329   wxMemoryOutputStream* GetBuffer() { return m_buffer; }
330 
331   /// Get a value identified by the given key from the associated dictionary
332   wxPdfObject* Get(const wxString& key);
333 
334   /// Set flag whether an object stream has already read the object index
SetHasObjOffsets(bool hasObjOffsets)335   void SetHasObjOffsets(bool hasObjOffsets) { m_hasObjOffsets = hasObjOffsets; }
336 
337   /// Get flag whether the offsets of objects in an object stream are available
HasObjOffsets()338   bool HasObjOffsets() { return m_hasObjOffsets; }
339 
340   /// Get a pointer to the object offsets array
GetObjOffsets()341   wxArrayInt* GetObjOffsets() { return &m_objOffsets; }
342 
343   /// Get the offset of an object in the object stream
344   int GetObjOffset(int index) const;
345 
346 private:
347   off_t                 m_offset;        ///< Offset of the stream data
348   wxPdfDictionary*      m_dictionary;    ///< Associated stream dictionary
349   wxMemoryOutputStream* m_buffer;        ///< Stream data buffer
350   bool                  m_hasObjOffsets; ///< Flag whether the stream is an object stream
351   wxArrayInt            m_objOffsets;    ///< Object offsets in object stream
352 };
353 
354 /// Class representing a queue of objects. (For internal use only)
355 class WXDLLIMPEXP_PDFDOC wxPdfObjectQueue
356 {
357 public:
358   /// Constructor
359   wxPdfObjectQueue(int originalId = 0, int actualObjectId = 0, wxPdfObject* object = NULL);
360 
361   /// Destructor
~wxPdfObjectQueue()362   virtual ~wxPdfObjectQueue() {}
363 
364   /// Get original object id
GetOriginalObjectId()365   int GetOriginalObjectId() const { return m_originalObjectId; }
366 
367   /// Get actual object id
GetActualObjectId()368   int GetActualObjectId() const { return m_actualObjectId; }
369 
370   /// Get associated object
GetObject()371   wxPdfObject* GetObject() const { return m_object; }
372 
373   /// Set associated object
SetObject(wxPdfObject * object)374   void SetObject(wxPdfObject* object) { m_object = object; }
375 
376   /// Get next queue entry
GetNext()377   wxPdfObjectQueue* GetNext() const { return m_next; }
378 
379   /// Set next queue entry
SetNext(wxPdfObjectQueue * next)380   void SetNext(wxPdfObjectQueue* next) { m_next = next; }
381 
382 private:
383   int               m_originalObjectId; ///< Original object number
384   int               m_actualObjectId;   ///< Actual object number
385   wxPdfObject*      m_object;           ///< Associated object
386   wxPdfObjectQueue* m_next;             ///< Pointer to next queue entry
387 };
388 
389 /// Hashmap class for object queue entries (For internal use only)
390 WX_DECLARE_HASH_MAP_WITH_DECL(long, wxPdfObjectQueue*, wxIntegerHash, wxIntegerEqual, wxPdfObjectMap, class WXDLLIMPEXP_PDFDOC);
391 
392 /// Hashmap class for object queue entries (For internal use only)
393 WX_DECLARE_HASH_MAP_WITH_DECL(long, wxPdfObject*, wxIntegerHash, wxIntegerEqual, wxPdfObjStmMap, class WXDLLIMPEXP_PDFDOC);
394 
395 #endif
396 
397