-
Notifications
You must be signed in to change notification settings - Fork 2
/
PdfObject.cc
61 lines (47 loc) · 1.49 KB
/
PdfObject.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <node.h>
#include "PdfVariant.h"
#include "PdfObject.h"
using v8::Handle;
using v8::Object;
using v8::Local;
using v8::FunctionTemplate;
using v8::Number;
using v8::External;
Nan::Persistent<FunctionTemplate> PdfObject::constructor_template;
PdfObject::PdfObject() :
_obj(new PoDoFo::PdfObject()),
_objFromElsewhere(false) {
}
PdfObject::PdfObject(PoDoFo::PdfObject* obj) :
_obj(obj),
_objFromElsewhere(true) { }
PdfObject::~PdfObject() {
if (!_objFromElsewhere) { delete _obj; }
}
void PdfObject::Init(Handle<Object> exports) {
Nan::HandleScope scope;
// Prepare constructor template
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->Inherit(Nan::New(PdfVariant::constructor_template));
tpl->SetClassName(Nan::New("PdfObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
// Prototype
//NODE_SET_PROTOTYPE_METHOD(tpl, "GetSize", GetSize);
constructor_template.Reset(tpl);
exports->Set(Nan::New("PdfObject").ToLocalChecked(), tpl->GetFunction());
}
NAN_METHOD(PdfObject::New) {
Nan::HandleScope scope;
if (!info.IsConstructCall()) {
return Nan::ThrowTypeError("Use the new operator to create new PdfObject objects");
}
PdfObject* objects;
if (info.Length() == 1 && info[0]->IsExternal()) {
objects = new PdfObject(static_cast<PoDoFo::PdfObject*>(
External::Cast(*info[0])->Value()));
} else {
objects = new PdfObject();
}
objects->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}