All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Obj.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPSDFSDFObj
6 #define PDFTRON_H_CPPSDFSDFObj
7 
8 #include <Common/Exception.h>
9 #include <Common/UString.h>
10 #include <Common/Matrix2D.h>
11 #include <Filters/FilterWriter.h>
12 #include <Filters/Filter.h>
13 
14 
15 namespace pdftron {
16  namespace SDF {
17 
18 class DictIterator;
19 
40 class Obj
41 {
42 public:
43 
44  // Common methods for all objects -----------------------------------------------
45 
49  enum Type
50  {
59  };
60 
65  Type GetType () const;
66 
71  bool IsBool () const;
72 
77  bool IsNumber () const;
78 
83  bool IsNull () const;
84 
89  bool IsString () const;
90 
95  bool IsName () const;
96 
102  bool IsIndirect () const;
103 
109  bool IsContainer () const;
110 
115  bool IsDict () const;
116 
121  bool IsArray () const;
122 
127  bool IsStream () const;
128 
133  class SDFDoc& GetDoc () const;
134 
140  void Write(Filters::FilterWriter& stream);
141 
155  size_t Size () const;
156 
157  // Indirect Methods -------------------------------------------------------------
158 
164  UInt32 GetObjNum () const;
165 
171  UInt16 GetGenNum () const;
172 
178  size_t GetOffset () const;
179 
184  bool IsFree () const;
185 
193  void SetMark (bool mark);
194 
199  bool IsMarked () const;
200 
205  bool IsLoaded () const;
206 
211  bool IsValid () const;
212 
213  // Boolean Specific Methods ----------------------------------------------------
214 
219  bool GetBool () const;
220 
225  void SetBool (bool b);
226 
227  // Number Specific Methods -----------------------------------------------------
228 
233  double GetNumber () const;
234 
239  void SetNumber (double n);
240 
241 
242  // String Specific Methods -----------------------------------------------------
243 
258 #ifdef SWIG
259  std::vector<unsigned char> GetBuffer () const;
260 #else
261  const UChar* GetBuffer () const;
262 #endif
263 
272  std::vector<unsigned char> GetRawBuffer() const;
273 
289  UString GetAsPDFText() const;
290 
291 #ifndef SWIG
292  void GetAsPDFText(UString& out_str) const;
293 #endif
294 
302  void SetString(const UChar* value, size_t size);
303 
309  void SetString(const UString& str);
310 
311  // Name Specific Methods -------------------------------------------------------
312 
317  const char* GetName () const;
318 
323  void SetName (const char* name);
324 
325 
326  // Dictionary Specific Methods -------------------------------------------------
327 
344 
366  DictIterator Find (const char* key);
367 
377  Obj FindObj (const char* key);
378 
388  DictIterator Get (const char* key);
389 
402  Obj PutName (const char* key, const char* name);
403 
415  Obj PutArray (const char* key);
416 
429  Obj PutBool (const char* key, bool value);
430 
441  Obj PutDict (const char* key);
442 
455  Obj PutNumber (const char* key, double value);
456 
469  Obj PutString (const char* key, const char* value);
470 
484  Obj PutString (const char* key, const char* value, int size);
485 
499  Obj PutText(const char* key, const UString& value);
500 
507  void PutNull (const char* key);
508 
518  Obj Put(const char* key, Obj obj);
519 
534  Obj PutRect (const char* key, double x1, double y1, double x2, double y2);
535 
548  Obj PutMatrix(const char* key, const Common::Matrix2D& value);
549 
555  void Erase (const char* key);
556 
562  void Erase (DictIterator pos);
563 
572  bool Rename (const char* old_key, const char* new_key);
573 
574 
575  // Array Specific Methods ------------------------------------------------------
576 
583  Obj GetAt (size_t index) const;
584 
596  Obj InsertName (size_t pos, const char* name);
597 
608  Obj InsertArray (size_t pos);
609 
621  Obj InsertBool (size_t pos, bool value);
622 
633  Obj InsertDict (size_t pos);
634 
646  Obj InsertNumber (size_t pos, double value);
647 
659  Obj InsertString (size_t pos, const char* value);
660 
674  Obj InsertString (size_t pos, const char* value, int size);
675 
688  Obj InsertText(size_t pos, const UString& value);
689 
698  Obj InsertNull(size_t pos);
699 
711  Obj Insert(size_t pos, Obj obj);
712 
726  Obj InsertRect (size_t pos, double x1, double y1, double x2, double y2);
727 
739  Obj InsertMatrix(size_t pos, const Common::Matrix2D& value);
740 
747  Obj PushBackName (const char* name);
748 
754  Obj PushBackArray ();
755 
762  Obj PushBackBool (bool value);
763 
769  Obj PushBackDict ();
770 
777  Obj PushBackNumber (double value);
778 
785  Obj PushBackString (const char* value);
786 
795  Obj PushBackString (const char* value, int size);
796 
804  Obj PushBackText (const UString& value);
805 
811  Obj PushBackNull ();
812 
821  Obj PushBack(Obj obj);
822 
832  Obj PushBackRect (double x1, double y1, double x2, double y2);
833 
841  Obj PushBackMatrix(const Common::Matrix2D& value);
842 
852  void EraseAt (size_t pos);
853 
854 
855  // Stream Specific Methods -----------------------------------------------------
856 
861  size_t GetRawStreamLength () const;
862 
868  Filters::Filter GetRawStream (bool decrypt) const;
869 
875 
880 #ifndef SWIG
881  void SetStreamData(
882  const char* data,
883  const size_t data_size,
884  Filters::Filter filter_chain = Filters::Filter() );
885 #endif
886  void SetStreamData( const std::vector<unsigned char>& data,
887  Filters::Filter filter_chain = Filters::Filter() );
888 
889 
890  // Support methods ----------------------------------------------------------------
891 
892  Obj() : mp_obj(0) {}
893  Obj(const Obj& c) : mp_obj(c.mp_obj) {}
894  Obj& operator=(const Obj& c) {mp_obj=c.mp_obj; return *this;}
895 
899  operator bool () { return mp_obj!=0;}
900 
907  bool IsEqual(const Obj& to) const;
908  bool operator ==(const Obj& to) const;
909  bool operator <(const Obj& to) const { return mp_obj < to.mp_obj; }
910 
911  //for xamarin use only
912  static Obj* CreateInternal(ptrdiff_t impl);
913  ptrdiff_t GetHandleInternal();
914 
915  // @cond PRIVATE_DOC
916  #ifndef SWIGHIDDEN
917  Obj(TRN_Obj impl);
918  TRN_Obj mp_obj;
919 private:
920  mutable TRN_SDFDoc temp_doc;
921  #endif
922  // @endcond
923 };
924 
925 
926 
927  }; // namespace SDF
928 }; // namespace pdftron
929 
930 
931 
932 #include <Impl/SDFDoc.inl>
933 
934 #endif // PDFTRON_H_CPPSDFSDFObj
Type GetType() const
UString GetAsPDFText() const
bool IsContainer() const
void Erase(const char *key)
bool IsIndirect() const
TRN_UInt16 UInt16
Definition: BasicTypes.h:14
Obj PutBool(const char *key, bool value)
Obj PushBackString(const char *value)
UInt16 GetGenNum() const
Obj PutNumber(const char *key, double value)
Obj PushBackRect(double x1, double y1, double x2, double y2)
bool IsDict() const
void PutNull(const char *key)
bool Rename(const char *old_key, const char *new_key)
Obj Put(const char *key, Obj obj)
Obj InsertDict(size_t pos)
Obj InsertArray(size_t pos)
bool IsNumber() const
void SetName(const char *name)
bool IsFree() const
bool operator<(const Obj &to) const
Definition: Obj.h:909
bool IsLoaded() const
ptrdiff_t GetHandleInternal()
Obj PutText(const char *key, const UString &value)
DictIterator Get(const char *key)
const char * GetName() const
DictIterator Find(const char *key)
Obj(const Obj &c)
Definition: Obj.h:893
Obj PushBackMatrix(const Common::Matrix2D &value)
Obj InsertNull(size_t pos)
bool IsName() const
DictIterator GetDictIterator()
Filters::Filter GetDecodedStream() const
Obj PushBack(Obj obj)
std::vector< unsigned char > GetRawBuffer() const
Obj PutDict(const char *key)
UInt32 GetObjNum() const
bool IsString() const
Obj PushBackBool(bool value)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
void Write(Filters::FilterWriter &stream)
Obj InsertBool(size_t pos, bool value)
Obj InsertRect(size_t pos, double x1, double y1, double x2, double y2)
Filters::Filter GetRawStream(bool decrypt) const
Obj PutString(const char *key, const char *value)
TRN_UChar UChar
Definition: BasicTypes.h:12
size_t GetRawStreamLength() const
bool IsStream() const
Obj InsertNumber(size_t pos, double value)
Obj PushBackNumber(double value)
Obj InsertString(size_t pos, const char *value)
bool IsArray() const
Obj PutRect(const char *key, double x1, double y1, double x2, double y2)
Obj PutMatrix(const char *key, const Common::Matrix2D &value)
bool GetBool() const
bool IsBool() const
Obj PushBackText(const UString &value)
void SetMark(bool mark)
Obj InsertName(size_t pos, const char *name)
bool IsNull() const
void SetString(const UChar *value, size_t size)
Obj InsertMatrix(size_t pos, const Common::Matrix2D &value)
Obj PutArray(const char *key)
void EraseAt(size_t pos)
Obj Insert(size_t pos, Obj obj)
Obj PutName(const char *key, const char *name)
bool IsMarked() const
Obj FindObj(const char *key)
bool operator==(const Obj &to) const
void SetNumber(double n)
Obj InsertText(size_t pos, const UString &value)
bool IsValid() const
Obj PushBackName(const char *name)
size_t Size() const
size_t GetOffset() const
Obj GetAt(size_t index) const
void SetBool(bool b)
double GetNumber() const
Obj & operator=(const Obj &c)
Definition: Obj.h:894
const UChar * GetBuffer() const
static Obj * CreateInternal(ptrdiff_t impl)
void SetStreamData(const char *data, const size_t data_size, Filters::Filter filter_chain=Filters::Filter())
bool IsEqual(const Obj &to) const
class SDFDoc & GetDoc() const