-
Notifications
You must be signed in to change notification settings - Fork 2
/
PdfInfo.cc
106 lines (86 loc) · 3.44 KB
/
PdfInfo.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <node.h>
#include "PdfInfo.h"
using v8::Handle;
using v8::Object;
using v8::Local;
using v8::FunctionTemplate;
using v8::Function;
using v8::String;
using v8::Number;
using v8::Boolean;
using v8::External;
Nan::Persistent<FunctionTemplate> PdfInfo::constructor_template;
PdfInfo::PdfInfo(PoDoFo::PdfInfo* obj) : _obj(obj) { }
PdfInfo::~PdfInfo() { }
void PdfInfo::Init(Handle<Object> exports) {
Nan::HandleScope scope;
// Prepare constructor template
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("PdfInfo").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(8);
// Prototype
Nan::SetPrototypeMethod(tpl, "GetAuthor", GetAuthor);
Nan::SetPrototypeMethod(tpl, "GetCreator", GetCreator);
Nan::SetPrototypeMethod(tpl, "GetKeywords", GetKeywords);
Nan::SetPrototypeMethod(tpl, "GetSubject", GetSubject);
Nan::SetPrototypeMethod(tpl, "GetTitle", GetTitle);
Nan::SetPrototypeMethod(tpl, "GetProducer", GetProducer);
Nan::SetPrototypeMethod(tpl, "GetTrapped", GetTrapped);
constructor_template.Reset(tpl);
exports->Set(Nan::New("PdfInfo").ToLocalChecked(), tpl->GetFunction());
}
NAN_METHOD(PdfInfo::New) {
Nan::HandleScope scope;
if (!info.IsConstructCall()) {
return Nan::ThrowTypeError("Use the new operator to create new PdfInfo objects");
}
if (info.Length() < 1 || !info[0]->IsExternal()) {
return Nan::ThrowTypeError("PdfInfo object cannot be created directly");
}
PdfInfo* pdfInfo = new PdfInfo(static_cast<PoDoFo::PdfInfo*>(
External::Cast(*info[0])->Value()));
pdfInfo->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}
NAN_METHOD(PdfInfo::GetAuthor) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfString author = obj->_obj->GetAuthor();
info.GetReturnValue().Set(Nan::New<String>(author.GetStringUtf8()).ToLocalChecked());
}
NAN_METHOD(PdfInfo::GetCreator) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfString creator = obj->_obj->GetCreator();
info.GetReturnValue().Set(Nan::New<String>(creator.GetStringUtf8()).ToLocalChecked());
}
NAN_METHOD(PdfInfo::GetKeywords) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfString keywords = obj->_obj->GetKeywords();
info.GetReturnValue().Set(Nan::New<String>(keywords.GetStringUtf8()).ToLocalChecked());
}
NAN_METHOD(PdfInfo::GetSubject) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfString subject = obj->_obj->GetSubject();
info.GetReturnValue().Set(Nan::New<String>(subject.GetStringUtf8()).ToLocalChecked());
}
NAN_METHOD(PdfInfo::GetTitle) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfString title = obj->_obj->GetTitle();
info.GetReturnValue().Set(Nan::New<String>(title.GetStringUtf8()).ToLocalChecked());
}
NAN_METHOD(PdfInfo::GetProducer) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfString producer = obj->_obj->GetProducer();
info.GetReturnValue().Set(Nan::New<String>(producer.GetStringUtf8()).ToLocalChecked());
}
NAN_METHOD(PdfInfo::GetTrapped) {
Nan::HandleScope scope;
PdfInfo* obj = ObjectWrap::Unwrap<PdfInfo>(info.This());
PoDoFo::PdfName trapped = obj->_obj->GetTrapped();
info.GetReturnValue().Set(Nan::New<String>(trapped.GetName()).ToLocalChecked());
}