UNPKG

4.65 kBtext/x-cView Raw
1/*
2 Source File : FormXObjectDriver.cpp
3
4
5 Copyright 2013 Gal Kahana HummusJS
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
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
27using namespace v8;
28
29FormXObjectDriver::~FormXObjectDriver()
30{
31 delete FormXObject;
32}
33
34FormXObjectDriver::FormXObjectDriver()
35{
36 mPDFWriterDriver = NULL;
37 FormXObject = NULL;
38}
39
40DEF_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 // save in factory
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
63METHOD_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
75METHOD_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
91METHOD_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
106METHOD_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
120METHOD_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}