All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OptionsBase.h
Go to the documentation of this file.
1 // This file is autogenerated: please see the codegen template "Options"
2 #ifndef PDFTRON_H_CPPPDFOptionsBase
3 #define PDFTRON_H_CPPPDFOptionsBase
4 
5 #include <SDF/ObjSet.h>
6 #include <PDF/ColorSpace.h>
7 #include <PDF/Rect.h>
8 #include <PDF/RectCollection.h>
9 
10 namespace pdftron{ namespace PDF{
11 
13 {
14 public:
16  : m_obj_set()
17  , m_dict()
18  {
19  m_dict = m_obj_set.CreateDict();
20  }
21 
22  static SDF::Obj GetArray(SDF::Obj dict, const char* key)
23  {
24  SDF::Obj found = dict.FindObj(key);
25  if(!found.IsValid())
26  {
27  found = dict.PutArray(key);
28  }
29  return found;
30  }
31 
32  static void PutNumber(SDF::Obj dict, const char* key, double num)
33  {
34  dict.PutNumber(key, num);
35  }
36  static void PutBool(SDF::Obj dict, const char* key, bool val)
37  {
38  dict.PutBool(key, val);
39  }
40  static void PutText(SDF::Obj dict, const char* key, const UString& text)
41  {
42  dict.PutText(key, text);
43  }
44  static void PutRect(SDF::Obj dict, const char* key, const Rect& rect)
45  {
46  dict.PutRect(key, rect.GetX1(), rect.GetY1(), rect.GetX2(), rect.GetY2());
47  }
48 
49  static void PushBackNumber(SDF::Obj dict, const char* key, double num)
50  {
51  SDF::Obj arr = GetArray(dict, key);
52  arr.PushBackNumber(num);
53  }
54  static void PushBackBool(SDF::Obj dict, const char* key, bool val)
55  {
56  SDF::Obj arr = GetArray(dict, key);
57  arr.PushBackBool(val);
58  }
59  static void PushBackText(SDF::Obj dict, const char* key, const UString& text)
60  {
61  SDF::Obj arr = GetArray(dict, key);
62  arr.PushBackText(text);
63  }
64  static void PushBackRect(SDF::Obj dict, const char* key, const Rect& rect)
65  {
66  SDF::Obj arr = GetArray(dict, key);
67  arr.PushBackRect(rect.GetX1(), rect.GetY1(), rect.GetX2(), rect.GetY2());
68  }
69 
71  {
72  return Rect(nums.GetAt(0).GetNumber(), nums.GetAt(1).GetNumber(),
73  nums.GetAt(2).GetNumber(), nums.GetAt(3).GetNumber());
74  }
75 
76  static void InsertRectCollection(SDF::Obj dict, const char* key,
77  const RectCollection& rects, int index)
78  {
79  SDF::Obj arr = GetArray(dict, key);
80  while(arr.Size() <= index)
81  {
82  arr.PushBackArray();
83  }
84  SDF::Obj innerArray = arr.GetAt(index);
85  for (size_t i = 0; i < rects.GetNumRects(); ++i)
86  {
87  Rect rect = rects.GetRectAt((int)i);
88  innerArray.PushBackRect(rect.GetX1(), rect.GetY1(), rect.GetX2(), rect.GetY2());
89  }
90  }
91 
92  static Rect RectFromArray(void*)
93  {
94  return Rect();
95  }
96 
97  static double ColorPtToNumber(const ColorPt& cp)
98  {
99  int num_comp = 3;
100  int red = 0;
101  int green = 0;
102  int blue = 0;
103  int alpha = 255;
104  if(num_comp == 1) {
105  red = (int)(255*cp.Get(0));
106  green = red;
107  blue = red;
108  }
109  else if(num_comp == 3 || num_comp == 4) {
110  red = (int)(255*cp.Get(0));
111  green = (int)(255*cp.Get(1));
112  blue = (int)(255*cp.Get(2));
113  }
114  if(num_comp == 4) {
115  alpha = (int)(255*cp.Get(3));
116  }
117  UInt32 num = ((0xFF&alpha) << 24)
118  | ((0xFF&red) << 16)
119  | ((0xFF&green) << 8)
120  | ((0xFF&blue) << 0);
121  return (double)num;
122  }
123  static ColorPt ColorPtFromNumber(double dnum)
124  {
125  UInt32 num = (UInt32)dnum;
126  return ColorPt(((num >> 16) & 0xFF)/255.0,
127  ((num >> 8) & 0xFF)/255.0,
128  ((num >> 0) & 0xFF)/255.0,
129  ((num >> 24)&0xFF)/255.0);
130  }
131 
132  // @cond PRIVATE_DOC
133  #ifndef SWIGHIDDEN
134  const SDF::Obj& GetInternalObj() const
135  {
136  return m_dict;
137  }
138  SDF::Obj& GetInternalObj()
139  {
140  return m_dict;
141  }
142 
143 protected:
144 
145  SDF::ObjSet m_obj_set;
146  SDF::Obj m_dict;
147  #endif
148  // @endcond
149 };
150 
151 }
152 }
153 
154 #endif // PDFTRON_H_CPPPDFOptionsBase
static SDF::Obj GetArray(SDF::Obj dict, const char *key)
Definition: OptionsBase.h:22
Obj PutBool(const char *key, bool value)
static void PutText(SDF::Obj dict, const char *key, const UString &text)
Definition: OptionsBase.h:40
double GetY1() const
Obj PutNumber(const char *key, double value)
Obj PushBackRect(double x1, double y1, double x2, double y2)
static void PushBackRect(SDF::Obj dict, const char *key, const Rect &rect)
Definition: OptionsBase.h:64
static void PushBackBool(SDF::Obj dict, const char *key, bool val)
Definition: OptionsBase.h:54
static void PutBool(SDF::Obj dict, const char *key, bool val)
Definition: OptionsBase.h:36
static ColorPt ColorPtFromNumber(double dnum)
Definition: OptionsBase.h:123
Obj PutText(const char *key, const UString &value)
static Rect RectFromArray(void *)
Definition: OptionsBase.h:92
static void PushBackText(SDF::Obj dict, const char *key, const UString &text)
Definition: OptionsBase.h:59
double GetX2() const
double GetY2() const
Obj PushBackBool(bool value)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
Rect GetRectAt(size_t index) const
Obj PushBackNumber(double value)
static void PutRect(SDF::Obj dict, const char *key, const Rect &rect)
Definition: OptionsBase.h:44
Obj PutRect(const char *key, double x1, double y1, double x2, double y2)
double GetX1() const
Obj PushBackText(const UString &value)
static double ColorPtToNumber(const ColorPt &cp)
Definition: OptionsBase.h:97
Obj PutArray(const char *key)
double Get(int colorant_index) const
Obj FindObj(const char *key)
static void PutNumber(SDF::Obj dict, const char *key, double num)
Definition: OptionsBase.h:32
static void InsertRectCollection(SDF::Obj dict, const char *key, const RectCollection &rects, int index)
Definition: OptionsBase.h:76
bool IsValid() const
size_t Size() const
Obj GetAt(size_t index) const
double GetNumber() const
static void PushBackNumber(SDF::Obj dict, const char *key, double num)
Definition: OptionsBase.h:49
static Rect RectFromArray(SDF::Obj nums)
Definition: OptionsBase.h:70