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:
15  static SDF::Obj GetArray(SDF::Obj dict, const char* key)
16  {
17  SDF::Obj found = dict.FindObj(key);
18  if(!found.IsValid())
19  {
20  found = dict.PutArray(key);
21  }
22  return found;
23  }
24 
25  static void PutNumber(SDF::Obj dict, const char* key, double num)
26  {
27  dict.PutNumber(key, num);
28  }
29  static void PutBool(SDF::Obj dict, const char* key, bool val)
30  {
31  dict.PutBool(key, val);
32  }
33  static void PutText(SDF::Obj dict, const char* key, const UString& text)
34  {
35  dict.PutText(key, text);
36  }
37  static void PutRect(SDF::Obj dict, const char* key, const Rect& rect)
38  {
39  dict.PutRect(key, rect.GetX1(), rect.GetY1(), rect.GetX2(), rect.GetY2());
40  }
41 
42  static void PushBackNumber(SDF::Obj dict, const char* key, double num)
43  {
44  SDF::Obj arr = GetArray(dict, key);
45  arr.PushBackNumber(num);
46  }
47  static void PushBackBool(SDF::Obj dict, const char* key, bool val)
48  {
49  SDF::Obj arr = GetArray(dict, key);
50  arr.PushBackBool(val);
51  }
52  static void PushBackText(SDF::Obj dict, const char* key, const UString& text)
53  {
54  SDF::Obj arr = GetArray(dict, key);
55  arr.PushBackText(text);
56  }
57  static void PushBackRect(SDF::Obj dict, const char* key, const Rect& rect)
58  {
59  SDF::Obj arr = GetArray(dict, key);
60  arr.PushBackRect(rect.GetX1(), rect.GetY1(), rect.GetX2(), rect.GetY2());
61  }
62 
64  {
65  return Rect(nums.GetAt(0).GetNumber(), nums.GetAt(1).GetNumber(),
66  nums.GetAt(2).GetNumber(), nums.GetAt(3).GetNumber());
67  }
68 
69  static void InsertRectCollection(SDF::Obj dict, const char* key,
70  const RectCollection& rects, int index)
71  {
72  SDF::Obj arr = GetArray(dict, key);
73  while(arr.Size() <= index)
74  {
75  arr.PushBackArray();
76  }
77  SDF::Obj innerArray = arr.GetAt(index);
78  for (size_t i = 0; i < rects.GetNumRects(); ++i)
79  {
80  Rect rect = rects.GetRectAt((int)i);
81  innerArray.PushBackRect(rect.GetX1(), rect.GetY1(), rect.GetX2(), rect.GetY2());
82  }
83  }
84 
85  static Rect RectFromArray(void*)
86  {
87  return Rect();
88  }
89 
90  static double ColorPtToNumber(const ColorPt& cp)
91  {
92  int num_comp = 3;
93  int red = 0;
94  int green = 0;
95  int blue = 0;
96  int alpha = 255;
97  if(num_comp == 1) {
98  red = (int)(255*cp.Get(0));
99  green = red;
100  blue = red;
101  }
102  else if(num_comp == 3 || num_comp == 4) {
103  red = (int)(255*cp.Get(0));
104  green = (int)(255*cp.Get(1));
105  blue = (int)(255*cp.Get(2));
106  }
107  if(num_comp == 4) {
108  alpha = (int)(255*cp.Get(3));
109  }
110  UInt32 num = ((0xFF&alpha) << 24)
111  | ((0xFF&red) << 16)
112  | ((0xFF&green) << 8)
113  | ((0xFF&blue) << 0);
114  return (double)num;
115  }
116  static ColorPt ColorPtFromNumber(double dnum)
117  {
118  UInt32 num = (UInt32)dnum;
119  return ColorPt(((num >> 16) & 0xFF)/255.0,
120  ((num >> 8) & 0xFF)/255.0,
121  ((num >> 0) & 0xFF)/255.0,
122  ((num >> 24)&0xFF)/255.0);
123  }
124 };
125 
126 }
127 }
128 
129 #endif // PDFTRON_H_CPPPDFOptionsBase
static SDF::Obj GetArray(SDF::Obj dict, const char *key)
Definition: OptionsBase.h:15
Obj PutBool(const char *key, bool value)
static void PutText(SDF::Obj dict, const char *key, const UString &text)
Definition: OptionsBase.h:33
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:57
static void PushBackBool(SDF::Obj dict, const char *key, bool val)
Definition: OptionsBase.h:47
static void PutBool(SDF::Obj dict, const char *key, bool val)
Definition: OptionsBase.h:29
static ColorPt ColorPtFromNumber(double dnum)
Definition: OptionsBase.h:116
Obj PutText(const char *key, const UString &value)
static Rect RectFromArray(void *)
Definition: OptionsBase.h:85
static void PushBackText(SDF::Obj dict, const char *key, const UString &text)
Definition: OptionsBase.h:52
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:37
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:90
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:25
static void InsertRectCollection(SDF::Obj dict, const char *key, const RectCollection &rects, int index)
Definition: OptionsBase.h:69
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:42
static Rect RectFromArray(SDF::Obj nums)
Definition: OptionsBase.h:63