UNPKG

2.22 kBtext/x-cView Raw
1/*
2 Source File : ImageXObjectDriver.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 "ImageXObjectDriver.h"
21#include "PDFImageXObject.h"
22#include "ConstructorsHolder.h"
23
24using namespace v8;
25
26ImageXObjectDriver::~ImageXObjectDriver()
27{
28 delete ImageXObject;
29}
30
31DEF_SUBORDINATE_INIT(ImageXObjectDriver::Init)
32{
33 CREATE_ISOLATE_CONTEXT;
34
35 Local<FunctionTemplate> t = NEW_FUNCTION_TEMPLATE(New);
36
37 t->SetClassName(NEW_STRING("ImageXObject"));
38 t->InstanceTemplate()->SetInternalFieldCount(1);
39
40 SET_ACCESSOR_METHOD(t, "id", GetID);
41
42 // save in factory
43 EXPOSE_EXTERNAL_FOR_INIT(ConstructorsHolder, holder)
44 SET_CONSTRUCTOR(holder->ImageXObject_constructor, t);
45 SET_CONSTRUCTOR_TEMPLATE(holder->ImageXObject_constructor_template, t);
46}
47
48ImageXObjectDriver::ImageXObjectDriver()
49{
50 ImageXObject = NULL;
51}
52
53METHOD_RETURN_TYPE ImageXObjectDriver::New(const ARGS_TYPE& args)
54{
55 CREATE_ISOLATE_CONTEXT;
56 CREATE_ESCAPABLE_SCOPE;
57
58 ImageXObjectDriver* image = new ImageXObjectDriver();
59 image->Wrap(args.This());
60
61 SET_FUNCTION_RETURN_VALUE(args.This())
62}
63
64METHOD_RETURN_TYPE ImageXObjectDriver::GetID(Local<String> property, const PROPERTY_TYPE &info)
65{
66 CREATE_ISOLATE_CONTEXT;
67 CREATE_ESCAPABLE_SCOPE;
68
69 ImageXObjectDriver* image = ObjectWrap::Unwrap<ImageXObjectDriver>(info.Holder());
70
71 if(!image->ImageXObject)
72 {
73 THROW_EXCEPTION("image object not initialized, create using pdfWriter.createFormXObject");
74 SET_ACCESSOR_RETURN_VALUE(UNDEFINED)
75 }
76
77 SET_ACCESSOR_RETURN_VALUE(NEW_NUMBER(image->ImageXObject->GetImageObjectID()))
78}
79