1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | #include "ResourcesDictionaryDriver.h"
|
22 | #include "ResourcesDictionary.h"
|
23 | #include "ImageXObjectDriver.h"
|
24 | #include "ConstructorsHolder.h"
|
25 |
|
26 | using namespace v8;
|
27 |
|
28 |
|
29 | DEF_SUBORDINATE_INIT(ResourcesDictionaryDriver::Init)
|
30 | {
|
31 | CREATE_ISOLATE_CONTEXT;
|
32 |
|
33 | Local<FunctionTemplate> t = NEW_FUNCTION_TEMPLATE_EXTERNAL(New);
|
34 |
|
35 | t->SetClassName(NEW_STRING("ResourcesDictionary"));
|
36 | t->InstanceTemplate()->SetInternalFieldCount(1);
|
37 |
|
38 | SET_PROTOTYPE_METHOD(t, "addFormXObjectMapping", AddFormXObjectMapping);
|
39 | SET_PROTOTYPE_METHOD(t, "addImageXObjectMapping", AddImageXObjectMapping);
|
40 | SET_PROTOTYPE_METHOD(t, "addProcsetResource", AddProcsetResource);
|
41 | SET_PROTOTYPE_METHOD(t, "addExtGStateMapping", AddExtGStateMapping);
|
42 | SET_PROTOTYPE_METHOD(t, "addFontMapping", AddFontMapping);
|
43 | SET_PROTOTYPE_METHOD(t, "addColorSpaceMapping", AddColorSpaceMapping);
|
44 | SET_PROTOTYPE_METHOD(t, "addPatternMapping", AddPatternMapping);
|
45 | SET_PROTOTYPE_METHOD(t, "addPropertyMapping", AddPropertyMapping);
|
46 | SET_PROTOTYPE_METHOD(t, "addXObjectMapping", AddXObjectMapping);
|
47 | SET_PROTOTYPE_METHOD(t, "addShadingMapping", AddShadingMapping);
|
48 |
|
49 |
|
50 | EXPOSE_EXTERNAL_FOR_INIT(ConstructorsHolder, holder)
|
51 | SET_CONSTRUCTOR(holder->ResourcesDictionary_constructor, t);
|
52 | }
|
53 |
|
54 | ResourcesDictionaryDriver::ResourcesDictionaryDriver()
|
55 | {
|
56 | ResourcesDictionaryInstance = NULL;
|
57 | }
|
58 |
|
59 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::New(const ARGS_TYPE& args)
|
60 | {
|
61 | CREATE_ISOLATE_CONTEXT;
|
62 | CREATE_ESCAPABLE_SCOPE;
|
63 | EXPOSE_EXTERNAL_ARGS(ConstructorsHolder, externalHolder)
|
64 |
|
65 | ResourcesDictionaryDriver* form = new ResourcesDictionaryDriver();
|
66 | form->holder = externalHolder;
|
67 | form->Wrap(args.This());
|
68 |
|
69 | SET_FUNCTION_RETURN_VALUE(args.This())
|
70 | }
|
71 |
|
72 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddFormXObjectMapping(const ARGS_TYPE& args)
|
73 | {
|
74 | CREATE_ISOLATE_CONTEXT;
|
75 | CREATE_ESCAPABLE_SCOPE;
|
76 |
|
77 | if(args.Length() != 1 || !args[0]->IsNumber())
|
78 | {
|
79 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the form xobject id");
|
80 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
81 | }
|
82 |
|
83 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
84 |
|
85 | Local<String> name = NEW_STRING(
|
86 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddFormXObjectMapping(
|
87 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
88 |
|
89 | SET_FUNCTION_RETURN_VALUE(name)
|
90 |
|
91 | }
|
92 |
|
93 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddImageXObjectMapping(const ARGS_TYPE& args)
|
94 | {
|
95 | CREATE_ISOLATE_CONTEXT;
|
96 | CREATE_ESCAPABLE_SCOPE;
|
97 |
|
98 | if(args.Length() != 1)
|
99 | {
|
100 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the image xobject or its ID");
|
101 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
102 | }
|
103 |
|
104 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
105 |
|
106 | if(resourcesDictionaryDriver->holder->IsImageXObjectInstance(args[0]))
|
107 | {
|
108 |
|
109 | Local<String> name = NEW_STRING(
|
110 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddImageXObjectMapping(
|
111 | ObjectWrap::Unwrap<ImageXObjectDriver>(args[0]->TO_OBJECT())->ImageXObject
|
112 | ).c_str());
|
113 |
|
114 | SET_FUNCTION_RETURN_VALUE(name)
|
115 | }
|
116 | else if(args[0]->IsNumber())
|
117 | {
|
118 | Local<String> name = NEW_STRING(
|
119 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddImageXObjectMapping(
|
120 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
121 |
|
122 | SET_FUNCTION_RETURN_VALUE(name)
|
123 | }
|
124 | else
|
125 | {
|
126 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the image xobject or its ID");
|
127 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
128 | }
|
129 | }
|
130 |
|
131 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddProcsetResource(const ARGS_TYPE& args)
|
132 | {
|
133 | CREATE_ISOLATE_CONTEXT;
|
134 | CREATE_ESCAPABLE_SCOPE;
|
135 |
|
136 | if(args.Length() != 1 || !args[0]->IsString())
|
137 | {
|
138 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the procset name");
|
139 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
140 | }
|
141 |
|
142 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
143 |
|
144 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddProcsetResource(*UTF_8_VALUE(args[0]->TO_STRING()));
|
145 |
|
146 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
147 |
|
148 | }
|
149 |
|
150 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddExtGStateMapping(const ARGS_TYPE& args)
|
151 | {
|
152 | CREATE_ISOLATE_CONTEXT;
|
153 | CREATE_ESCAPABLE_SCOPE;
|
154 |
|
155 | if(args.Length() != 1 || !args[0]->IsNumber())
|
156 | {
|
157 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the external graphic state object id");
|
158 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
159 | }
|
160 |
|
161 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
162 |
|
163 | Local<String> name = NEW_STRING(
|
164 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddExtGStateMapping(
|
165 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
166 |
|
167 | SET_FUNCTION_RETURN_VALUE(name)
|
168 | }
|
169 |
|
170 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddFontMapping(const ARGS_TYPE& args)
|
171 | {
|
172 | CREATE_ISOLATE_CONTEXT;
|
173 | CREATE_ESCAPABLE_SCOPE;
|
174 |
|
175 | if(args.Length() != 1 || !args[0]->IsNumber())
|
176 | {
|
177 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the font object id");
|
178 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
179 | }
|
180 |
|
181 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
182 |
|
183 | Local<String> name = NEW_STRING(
|
184 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddFontMapping(
|
185 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
186 |
|
187 | SET_FUNCTION_RETURN_VALUE(name)
|
188 | }
|
189 |
|
190 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddColorSpaceMapping(const ARGS_TYPE& args)
|
191 | {
|
192 | CREATE_ISOLATE_CONTEXT;
|
193 | CREATE_ESCAPABLE_SCOPE;
|
194 |
|
195 | if(args.Length() != 1 || !args[0]->IsNumber())
|
196 | {
|
197 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the color space id");
|
198 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
199 | }
|
200 |
|
201 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
202 |
|
203 | Local<String> name = NEW_STRING(
|
204 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddColorSpaceMapping(
|
205 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
206 |
|
207 | SET_FUNCTION_RETURN_VALUE(name)
|
208 | }
|
209 |
|
210 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddPatternMapping(const ARGS_TYPE& args)
|
211 | {
|
212 | CREATE_ISOLATE_CONTEXT;
|
213 | CREATE_ESCAPABLE_SCOPE;
|
214 |
|
215 | if(args.Length() != 1 || !args[0]->IsNumber())
|
216 | {
|
217 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the pattern object id");
|
218 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
219 | }
|
220 |
|
221 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
222 |
|
223 | Local<String> name = NEW_STRING(
|
224 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddPatternMapping(
|
225 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
226 |
|
227 | SET_FUNCTION_RETURN_VALUE(name)
|
228 | }
|
229 |
|
230 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddPropertyMapping(const ARGS_TYPE& args)
|
231 | {
|
232 | CREATE_ISOLATE_CONTEXT;
|
233 | CREATE_ESCAPABLE_SCOPE;
|
234 |
|
235 | if(args.Length() != 1 || !args[0]->IsNumber())
|
236 | {
|
237 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the property object id");
|
238 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
239 | }
|
240 |
|
241 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
242 |
|
243 | Local<String> name = NEW_STRING(
|
244 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddPropertyMapping(
|
245 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
246 |
|
247 | SET_FUNCTION_RETURN_VALUE(name)
|
248 | }
|
249 |
|
250 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddXObjectMapping(const ARGS_TYPE& args)
|
251 | {
|
252 | CREATE_ISOLATE_CONTEXT;
|
253 | CREATE_ESCAPABLE_SCOPE;
|
254 |
|
255 | if(args.Length() != 1 || !args[0]->IsNumber())
|
256 | {
|
257 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the xobject id");
|
258 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
259 | }
|
260 |
|
261 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
262 |
|
263 | Local<String> name = NEW_STRING(
|
264 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddXObjectMapping(
|
265 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
266 |
|
267 | SET_FUNCTION_RETURN_VALUE(name)
|
268 | }
|
269 |
|
270 | METHOD_RETURN_TYPE ResourcesDictionaryDriver::AddShadingMapping(const ARGS_TYPE& args)
|
271 | {
|
272 | CREATE_ISOLATE_CONTEXT;
|
273 | CREATE_ESCAPABLE_SCOPE;
|
274 |
|
275 | if(args.Length() != 1 || !args[0]->IsNumber())
|
276 | {
|
277 | THROW_EXCEPTION("wrong arguments, pass 1 argument which is the shading object id");
|
278 | SET_FUNCTION_RETURN_VALUE(UNDEFINED)
|
279 | }
|
280 |
|
281 | ResourcesDictionaryDriver* resourcesDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(args.This());
|
282 |
|
283 | Local<String> name = NEW_STRING(
|
284 | resourcesDictionaryDriver->ResourcesDictionaryInstance->AddShadingMapping(
|
285 | (ObjectIDType)(TO_UINT32(args[0])->Value())).c_str());
|
286 |
|
287 | SET_FUNCTION_RETURN_VALUE(name)
|
288 | }
|
289 |
|
290 |
|