1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | #include "FormXObjectDriver.h"
|
21 | #include "PDFFormXObject.h"
|
22 | #include "XObjectContentContextDriver.h"
|
23 | #include "ResourcesDictionaryDriver.h"
|
24 | #include "PDFStreamDriver.h"
|
25 | #include "ConstructorsHolder.h"
|
26 |
|
27 | using namespace v8;
|
28 |
|
29 | FormXObjectDriver::~FormXObjectDriver()
|
30 | {
|
31 | delete FormXObject;
|
32 | }
|
33 |
|
34 | FormXObjectDriver::FormXObjectDriver()
|
35 | {
|
36 | mPDFWriterDriver = NULL;
|
37 | FormXObject = NULL;
|
38 | }
|
39 |
|
40 | DEF_SUBORDINATE_INIT(FormXObjectDriver::Init)
|
41 | {
|
42 | CREATE_ISOLATE_CONTEXT;
|
43 |
|
44 | Local<FunctionTemplate> t = NEW_FUNCTION_TEMPLATE_EXTERNAL(New);
|
45 |
|
46 | t->SetClassName(NEW_STRING("FormXObject"));
|
47 | t->InstanceTemplate()->SetInternalFieldCount(1);
|
48 |
|
49 | SET_ACCESSOR_METHOD(t,"id", GetID);
|
50 | SET_PROTOTYPE_METHOD(t, "getContentContext", GetContentContext);
|
51 | SET_PROTOTYPE_METHOD(t, "getResourcesDictinary", GetResourcesDictionary);
|
52 | SET_PROTOTYPE_METHOD(t, "getResourcesDictionary", GetResourcesDictionary);
|
53 | SET_PROTOTYPE_METHOD(t, "getContentStream", GetContentStream);
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | EXPOSE_EXTERNAL_FOR_INIT(ConstructorsHolder, holder)
|
59 | SET_CONSTRUCTOR(holder->FormXObject_constructor, t);
|
60 | SET_CONSTRUCTOR_TEMPLATE(holder->FormXObject_constructor_template, t);
|
61 | }
|
62 |
|
63 | METHOD_RETURN_TYPE FormXObjectDriver::New(const ARGS_TYPE& args)
|
64 | {
|
65 | CREATE_ISOLATE_CONTEXT;
|
66 | CREATE_ESCAPABLE_SCOPE;
|
67 | EXPOSE_EXTERNAL_ARGS(ConstructorsHolder, externalHolder)
|
68 |
|
69 | FormXObjectDriver* form = new FormXObjectDriver();
|
70 | form->holder = externalHolder;
|
71 | form->Wrap(args.This());
|
72 | SET_FUNCTION_RETURN_VALUE(args.This())
|
73 | }
|
74 |
|
75 | METHOD_RETURN_TYPE FormXObjectDriver::GetID(Local<String> property, const PROPERTY_TYPE &info)
|
76 | {
|
77 | CREATE_ISOLATE_CONTEXT;
|
78 | CREATE_ESCAPABLE_SCOPE;
|
79 |
|
80 | FormXObjectDriver* form = ObjectWrap::Unwrap<FormXObjectDriver>(info.Holder());
|
81 |
|
82 | if(!form->FormXObject)
|
83 | {
|
84 | THROW_EXCEPTION("form object not initialized, create using pdfWriter.CreateFormXObject");
|
85 | SET_ACCESSOR_RETURN_VALUE(UNDEFINED)
|
86 | }
|
87 |
|
88 | SET_ACCESSOR_RETURN_VALUE(NEW_NUMBER(form->FormXObject->GetObjectID()))
|
89 | }
|
90 |
|
91 | METHOD_RETURN_TYPE FormXObjectDriver::GetContentContext(const ARGS_TYPE& args)
|
92 | {
|
93 | CREATE_ISOLATE_CONTEXT;
|
94 | CREATE_ESCAPABLE_SCOPE;
|
95 | FormXObjectDriver* formDriver = ObjectWrap::Unwrap<FormXObjectDriver>(args.This());
|
96 |
|
97 | Local<Value> newInstance = formDriver->holder->GetNewXObjectContentContext(args);
|
98 | XObjectContentContextDriver* contentContextDriver = ObjectWrap::Unwrap<XObjectContentContextDriver>(newInstance->TO_OBJECT());
|
99 | contentContextDriver->ContentContext = formDriver->FormXObject->GetContentContext();
|
100 | contentContextDriver->FormOfContext = formDriver->FormXObject;
|
101 | contentContextDriver->SetResourcesDictionary(&(formDriver->FormXObject->GetResourcesDictionary()));
|
102 |
|
103 | SET_FUNCTION_RETURN_VALUE(newInstance)
|
104 | }
|
105 |
|
106 | METHOD_RETURN_TYPE FormXObjectDriver::GetResourcesDictionary(const ARGS_TYPE& args)
|
107 | {
|
108 | CREATE_ISOLATE_CONTEXT;
|
109 | CREATE_ESCAPABLE_SCOPE;
|
110 | FormXObjectDriver* formDriver = ObjectWrap::Unwrap<FormXObjectDriver>(args.This());
|
111 |
|
112 | Local<Value> newInstance = formDriver->holder->GetNewResourcesDictionary(args);
|
113 | ResourcesDictionaryDriver* resourceDictionaryDriver = ObjectWrap::Unwrap<ResourcesDictionaryDriver>(newInstance->TO_OBJECT());
|
114 | resourceDictionaryDriver->ResourcesDictionaryInstance = &(formDriver->FormXObject->GetResourcesDictionary());
|
115 |
|
116 | SET_FUNCTION_RETURN_VALUE(newInstance)
|
117 | }
|
118 |
|
119 |
|
120 | METHOD_RETURN_TYPE FormXObjectDriver::GetContentStream(const ARGS_TYPE& args)
|
121 | {
|
122 | CREATE_ISOLATE_CONTEXT;
|
123 | CREATE_ESCAPABLE_SCOPE;
|
124 | FormXObjectDriver* formDriver = ObjectWrap::Unwrap<FormXObjectDriver>(args.This());
|
125 |
|
126 | Local<Value> newInstance = formDriver->holder->GetNewPDFStream(args);
|
127 | PDFStreamDriver* streamDriver = ObjectWrap::Unwrap<PDFStreamDriver>(newInstance->TO_OBJECT());
|
128 | streamDriver->PDFStreamInstance = formDriver->FormXObject->GetContentStream();
|
129 |
|
130 | SET_FUNCTION_RETURN_VALUE(newInstance)
|
131 | }
|