1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | #include "PDFPageInputDriver.h"
|
21 | #include "PDFPageInput.h"
|
22 | #include "PDFDictionaryDriver.h"
|
23 | #include "ConstructorsHolder.h"
|
24 |
|
25 | using namespace v8;
|
26 |
|
27 | PDFPageInputDriver::PDFPageInputDriver()
|
28 | {
|
29 | PageInput = NULL;
|
30 | }
|
31 |
|
32 | PDFPageInputDriver::~PDFPageInputDriver()
|
33 | {
|
34 | delete PageInput;
|
35 | }
|
36 |
|
37 | DEF_SUBORDINATE_INIT(PDFPageInputDriver::Init)
|
38 | {
|
39 | CREATE_ISOLATE_CONTEXT;
|
40 |
|
41 | Local<FunctionTemplate> t = NEW_FUNCTION_TEMPLATE_EXTERNAL(New);
|
42 |
|
43 | t->SetClassName(NEW_STRING("PDFPageInput"));
|
44 | t->InstanceTemplate()->SetInternalFieldCount(1);
|
45 |
|
46 | SET_PROTOTYPE_METHOD(t, "getDictionary", GetDictionary);
|
47 | SET_PROTOTYPE_METHOD(t, "getMediaBox", GetMediaBox);
|
48 | SET_PROTOTYPE_METHOD(t, "getCropBox", GetCropBox);
|
49 | SET_PROTOTYPE_METHOD(t, "getTrimBox", GetTrimBox);
|
50 | SET_PROTOTYPE_METHOD(t, "getBleedBox", GetBleedBox);
|
51 | SET_PROTOTYPE_METHOD(t, "getArtBox", GetArtBox);
|
52 | SET_PROTOTYPE_METHOD(t, "getRotate", GetRotate);
|
53 |
|
54 |
|
55 | EXPOSE_EXTERNAL_FOR_INIT(ConstructorsHolder, holder)
|
56 | SET_CONSTRUCTOR(holder->PDFPageInput_constructor, t);
|
57 | }
|
58 |
|
59 | METHOD_RETURN_TYPE PDFPageInputDriver::New(const ARGS_TYPE& args)
|
60 | {
|
61 | CREATE_ISOLATE_CONTEXT;
|
62 | CREATE_ESCAPABLE_SCOPE;
|
63 | EXPOSE_EXTERNAL_ARGS(ConstructorsHolder, externalHolder)
|
64 |
|
65 | PDFPageInputDriver* element = new PDFPageInputDriver();
|
66 | element->holder = externalHolder;
|
67 | element->Wrap(args.This());
|
68 | SET_FUNCTION_RETURN_VALUE(args.This())
|
69 | }
|
70 |
|
71 | METHOD_RETURN_TYPE PDFPageInputDriver::GetDictionary(const ARGS_TYPE& args)
|
72 | {
|
73 | CREATE_ISOLATE_CONTEXT;
|
74 | CREATE_ESCAPABLE_SCOPE;
|
75 |
|
76 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
77 |
|
78 | if(!element->PageInput)
|
79 | {
|
80 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
81 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
82 | }
|
83 |
|
84 | Local<Value> newInstance;
|
85 |
|
86 | newInstance = element->holder->GetNewPDFDictionary();
|
87 | ObjectWrap::Unwrap<PDFDictionaryDriver>(newInstance->TO_OBJECT())->TheObject = element->PageInputDictionary;
|
88 | SET_FUNCTION_RETURN_VALUE(newInstance)
|
89 | }
|
90 |
|
91 | METHOD_RETURN_TYPE PDFPageInputDriver::GetMediaBox(const ARGS_TYPE& args)
|
92 | {
|
93 | CREATE_ISOLATE_CONTEXT;
|
94 | CREATE_ESCAPABLE_SCOPE;
|
95 |
|
96 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
97 |
|
98 | if(!element->PageInput)
|
99 | {
|
100 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
101 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
102 | }
|
103 | else
|
104 | SET_FUNCTION_RETURN_VALUE(GetArrayForPDFRectangle(element->PageInput->GetMediaBox()))
|
105 | }
|
106 |
|
107 | Local<Value> PDFPageInputDriver::GetArrayForPDFRectangle(const PDFRectangle& inRectangle)
|
108 | {
|
109 | CREATE_ISOLATE_CONTEXT;
|
110 | CREATE_ESCAPABLE_SCOPE;
|
111 |
|
112 | Local<Array> result = NEW_ARRAY(4);
|
113 |
|
114 | result->Set(GET_CURRENT_CONTEXT, NEW_NUMBER(0),NEW_NUMBER(inRectangle.LowerLeftX));
|
115 | result->Set(GET_CURRENT_CONTEXT, NEW_NUMBER(1),NEW_NUMBER(inRectangle.LowerLeftY));
|
116 | result->Set(GET_CURRENT_CONTEXT, NEW_NUMBER(2),NEW_NUMBER(inRectangle.UpperRightX));
|
117 | result->Set(GET_CURRENT_CONTEXT, NEW_NUMBER(3),NEW_NUMBER(inRectangle.UpperRightY));
|
118 | return CLOSE_SCOPE(result);
|
119 |
|
120 | }
|
121 | METHOD_RETURN_TYPE PDFPageInputDriver::GetCropBox(const ARGS_TYPE& args)
|
122 | {
|
123 | CREATE_ISOLATE_CONTEXT;
|
124 | CREATE_ESCAPABLE_SCOPE;
|
125 |
|
126 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
127 |
|
128 | if (!element->PageInput)
|
129 | {
|
130 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
131 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
132 | }
|
133 | else
|
134 | SET_FUNCTION_RETURN_VALUE(GetArrayForPDFRectangle(element->PageInput->GetCropBox()))
|
135 | }
|
136 |
|
137 | METHOD_RETURN_TYPE PDFPageInputDriver::GetTrimBox(const ARGS_TYPE& args)
|
138 | {
|
139 | CREATE_ISOLATE_CONTEXT;
|
140 | CREATE_ESCAPABLE_SCOPE;
|
141 |
|
142 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
143 |
|
144 | if (!element->PageInput)
|
145 | {
|
146 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
147 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
148 | }
|
149 | else
|
150 | SET_FUNCTION_RETURN_VALUE(GetArrayForPDFRectangle(element->PageInput->GetTrimBox()))
|
151 | }
|
152 |
|
153 | METHOD_RETURN_TYPE PDFPageInputDriver::GetBleedBox(const ARGS_TYPE& args)
|
154 | {
|
155 | CREATE_ISOLATE_CONTEXT;
|
156 | CREATE_ESCAPABLE_SCOPE;
|
157 |
|
158 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
159 |
|
160 | if (!element->PageInput)
|
161 | {
|
162 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
163 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
164 | }
|
165 | else
|
166 | SET_FUNCTION_RETURN_VALUE(GetArrayForPDFRectangle(element->PageInput->GetBleedBox()))
|
167 | }
|
168 |
|
169 | METHOD_RETURN_TYPE PDFPageInputDriver::GetArtBox(const ARGS_TYPE& args)
|
170 | {
|
171 | CREATE_ISOLATE_CONTEXT;
|
172 | CREATE_ESCAPABLE_SCOPE;
|
173 |
|
174 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
175 |
|
176 | if (!element->PageInput)
|
177 | {
|
178 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
179 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
180 | }
|
181 | else
|
182 | SET_FUNCTION_RETURN_VALUE(GetArrayForPDFRectangle(element->PageInput->GetArtBox()))
|
183 | }
|
184 |
|
185 | METHOD_RETURN_TYPE PDFPageInputDriver::GetRotate(const ARGS_TYPE& args)
|
186 | {
|
187 | CREATE_ISOLATE_CONTEXT;
|
188 | CREATE_ESCAPABLE_SCOPE;
|
189 |
|
190 | PDFPageInputDriver* element = ObjectWrap::Unwrap<PDFPageInputDriver>(args.This());
|
191 |
|
192 | if (!element->PageInput)
|
193 | {
|
194 | THROW_EXCEPTION("page input not initialized. create one using the PDFReader.parsePage");
|
195 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
196 | }
|
197 | else
|
198 | SET_FUNCTION_RETURN_VALUE(NEW_NUMBER(element->PageInput->GetRotate()))
|
199 | } |
\ | No newline at end of file |