- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
12 class OptionsBase
13 {
14 public:
15 OptionsBase()
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
70 static Rect RectFromArray(SDF::Obj nums)
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
pdftron::PDF::OptionsBase::GetArray
static SDF::Obj GetArray(SDF::Obj dict, const char *key)
Definition: OptionsBase.h:22
pdftron::SDF::Obj::PutBool
Obj PutBool(const char *key, bool value)
pdftron::PDF::OptionsBase::PutText
static void PutText(SDF::Obj dict, const char *key, const UString &text)
Definition: OptionsBase.h:40
pdftron::PDF::Rect::GetY1
double GetY1() const
pdftron::SDF::Obj::PutNumber
Obj PutNumber(const char *key, double value)
pdftron::SDF::Obj::PushBackRect
Obj PushBackRect(double x1, double y1, double x2, double y2)
pdftron::PDF::ColorPt
Definition: ColorSpace.h:20
pdftron::PDF::OptionsBase::PushBackRect
static void PushBackRect(SDF::Obj dict, const char *key, const Rect &rect)
Definition: OptionsBase.h:64
pdftron::PDF::OptionsBase::PushBackBool
static void PushBackBool(SDF::Obj dict, const char *key, bool val)
Definition: OptionsBase.h:54
pdftron::PDF::OptionsBase::PutBool
static void PutBool(SDF::Obj dict, const char *key, bool val)
Definition: OptionsBase.h:36
ColorSpace.h
pdftron::PDF::OptionsBase::ColorPtFromNumber
static ColorPt ColorPtFromNumber(double dnum)
Definition: OptionsBase.h:123
pdftron::SDF::Obj::PutText
Obj PutText(const char *key, const UString &value)
pdftron::PDF::OptionsBase::RectFromArray
static Rect RectFromArray(void *)
Definition: OptionsBase.h:92
pdftron::PDF::Rect
Definition: Rect.h:28
pdftron::PDF::OptionsBase::PushBackText
static void PushBackText(SDF::Obj dict, const char *key, const UString &text)
Definition: OptionsBase.h:59
pdftron::PDF::Rect::GetX2
double GetX2() const
pdftron::PDF::Rect::GetY2
double GetY2() const
pdftron::SDF::Obj::PushBackBool
Obj PushBackBool(bool value)
pdftron::SDF::Obj::PushBackArray
Obj PushBackArray()
pdftron::UInt32
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
pdftron::PDF::RectCollection::GetRectAt
Rect GetRectAt(size_t index) const
Definition: RectCollection.h:26
pdftron::PDF::OptionsBase::OptionsBase
OptionsBase()
Definition: OptionsBase.h:15
pdftron::PDF::RectCollection
Definition: RectCollection.h:9
pdftron::SDF::Obj::PushBackNumber
Obj PushBackNumber(double value)
pdftron::PDF::OptionsBase::PutRect
static void PutRect(SDF::Obj dict, const char *key, const Rect &rect)
Definition: OptionsBase.h:44
pdftron::SDF::Obj::PutRect
Obj PutRect(const char *key, double x1, double y1, double x2, double y2)
pdftron::PDF::Rect::GetX1
double GetX1() const
pdftron::SDF::Obj::PushBackText
Obj PushBackText(const UString &value)
pdftron::PDF::OptionsBase::ColorPtToNumber
static double ColorPtToNumber(const ColorPt &cp)
Definition: OptionsBase.h:97
pdftron::SDF::Obj::PutArray
Obj PutArray(const char *key)
pdftron::PDF::ColorPt::Get
double Get(int colorant_index) const
pdftron::SDF::Obj::FindObj
Obj FindObj(const char *key)
pdftron::PDF::RectCollection::GetNumRects
size_t GetNumRects() const
Definition: RectCollection.h:32
pdftron::PDF::OptionsBase
Definition: OptionsBase.h:12
pdftron::PDF::OptionsBase::PutNumber
static void PutNumber(SDF::Obj dict, const char *key, double num)
Definition: OptionsBase.h:32
ObjSet.h
Rect.h
pdftron::PDF::OptionsBase::InsertRectCollection
static void InsertRectCollection(SDF::Obj dict, const char *key, const RectCollection &rects, int index)
Definition: OptionsBase.h:76
pdftron::SDF::Obj::IsValid
bool IsValid() const
pdftron::SDF::Obj
Definition: Obj.h:40
RectCollection.h
pdftron::SDF::Obj::Size
size_t Size() const
pdftron::SDF::Obj::GetAt
Obj GetAt(size_t index) const
pdftron::SDF::Obj::GetNumber
double GetNumber() const
pdftron::UString
Definition: UString.h:27
pdftron::PDF::OptionsBase::PushBackNumber
static void PushBackNumber(SDF::Obj dict, const char *key, double num)
Definition: OptionsBase.h:49
pdftron::PDF::OptionsBase::RectFromArray
static Rect RectFromArray(SDF::Obj nums)
Definition: OptionsBase.h:70