|
|
@ -30,8 +30,8 @@ Canvas::Initialize(Handle<Object> target) { |
|
|
|
NanScope(); |
|
|
|
|
|
|
|
// Constructor
|
|
|
|
Local<FunctionTemplate> ctor = FunctionTemplate::New(Canvas::New); |
|
|
|
NanAssignPersistent(FunctionTemplate, constructor, ctor); |
|
|
|
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Canvas::New); |
|
|
|
NanAssignPersistent(constructor, ctor); |
|
|
|
ctor->InstanceTemplate()->SetInternalFieldCount(1); |
|
|
|
ctor->SetClassName(NanSymbol("Canvas")); |
|
|
|
|
|
|
@ -46,13 +46,13 @@ Canvas::Initialize(Handle<Object> target) { |
|
|
|
proto->SetAccessor(NanSymbol("width"), GetWidth, SetWidth); |
|
|
|
proto->SetAccessor(NanSymbol("height"), GetHeight, SetHeight); |
|
|
|
|
|
|
|
proto->Set("PNG_NO_FILTERS", Uint32::New(PNG_NO_FILTERS)); |
|
|
|
proto->Set("PNG_FILTER_NONE", Uint32::New(PNG_FILTER_NONE)); |
|
|
|
proto->Set("PNG_FILTER_SUB", Uint32::New(PNG_FILTER_SUB)); |
|
|
|
proto->Set("PNG_FILTER_UP", Uint32::New(PNG_FILTER_UP)); |
|
|
|
proto->Set("PNG_FILTER_AVG", Uint32::New(PNG_FILTER_AVG)); |
|
|
|
proto->Set("PNG_FILTER_PAETH", Uint32::New(PNG_FILTER_PAETH)); |
|
|
|
proto->Set("PNG_ALL_FILTERS", Uint32::New(PNG_ALL_FILTERS)); |
|
|
|
NanSetTemplate(proto, "PNG_NO_FILTERS", NanNew<Uint32>(PNG_NO_FILTERS)); |
|
|
|
NanSetTemplate(proto, "PNG_FILTER_NONE", NanNew<Uint32>(PNG_FILTER_NONE)); |
|
|
|
NanSetTemplate(proto, "PNG_FILTER_SUB", NanNew<Uint32>(PNG_FILTER_SUB)); |
|
|
|
NanSetTemplate(proto, "PNG_FILTER_UP", NanNew<Uint32>(PNG_FILTER_UP)); |
|
|
|
NanSetTemplate(proto, "PNG_FILTER_AVG", NanNew<Uint32>(PNG_FILTER_AVG)); |
|
|
|
NanSetTemplate(proto, "PNG_FILTER_PAETH", NanNew<Uint32>(PNG_FILTER_PAETH)); |
|
|
|
NanSetTemplate(proto, "PNG_ALL_FILTERS", NanNew<Uint32>(PNG_ALL_FILTERS)); |
|
|
|
|
|
|
|
target->Set(NanSymbol("Canvas"), ctor->GetFunction()); |
|
|
|
} |
|
|
@ -82,7 +82,7 @@ NAN_METHOD(Canvas::New) { |
|
|
|
NAN_GETTER(Canvas::GetType) { |
|
|
|
NanScope(); |
|
|
|
Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args.This()); |
|
|
|
NanReturnValue(String::New(canvas->isPDF() ? "pdf" : "image")); |
|
|
|
NanReturnValue(NanNew<String>(canvas->isPDF() ? "pdf" : "image")); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -92,7 +92,7 @@ NAN_GETTER(Canvas::GetType) { |
|
|
|
NAN_GETTER(Canvas::GetWidth) { |
|
|
|
NanScope(); |
|
|
|
Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args.This()); |
|
|
|
NanReturnValue(Number::New(canvas->width)); |
|
|
|
NanReturnValue(NanNew<Number>(canvas->width)); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -115,7 +115,7 @@ NAN_SETTER(Canvas::SetWidth) { |
|
|
|
NAN_GETTER(Canvas::GetHeight) { |
|
|
|
NanScope(); |
|
|
|
Canvas *canvas = ObjectWrap::Unwrap<Canvas>(args.This()); |
|
|
|
NanReturnValue(Number::New(canvas->height)); |
|
|
|
NanReturnValue(NanNew<Number>(canvas->height)); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -211,7 +211,7 @@ Canvas::EIO_AfterToBuffer(eio_req *req) { |
|
|
|
} else { |
|
|
|
Local<Object> buf = NanNewBufferHandle((char*)closure->data, closure->len); |
|
|
|
memcpy(Buffer::Data(buf), closure->data, closure->len); |
|
|
|
Local<Value> argv[2] = { NanNewLocal<Value>(Null()), buf }; |
|
|
|
Local<Value> argv[2] = { NanNull(), buf }; |
|
|
|
closure->pfn->Call(2, argv); |
|
|
|
} |
|
|
|
|
|
|
@ -246,13 +246,13 @@ NAN_METHOD(Canvas::ToBuffer) { |
|
|
|
NanReturnValue(buf); |
|
|
|
} |
|
|
|
|
|
|
|
if (args.Length() > 1 && !(args[1]->StrictEquals(Undefined()) && args[2]->StrictEquals(Undefined()))) { |
|
|
|
if (!args[1]->StrictEquals(Undefined())) { |
|
|
|
if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { |
|
|
|
if (!args[1]->StrictEquals(NanUndefined())) { |
|
|
|
bool good = true; |
|
|
|
if (args[1]->IsNumber()) { |
|
|
|
compression_level = args[1]->Uint32Value(); |
|
|
|
} else if (args[1]->IsString()) { |
|
|
|
if (args[1]->StrictEquals(String::New("0"))) { |
|
|
|
if (args[1]->StrictEquals(NanNew<String>("0"))) { |
|
|
|
compression_level = 0; |
|
|
|
} else { |
|
|
|
uint32_t tmp = args[1]->Uint32Value(); |
|
|
@ -275,7 +275,7 @@ NAN_METHOD(Canvas::ToBuffer) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!args[2]->StrictEquals(Undefined())) { |
|
|
|
if (!args[2]->StrictEquals(NanUndefined())) { |
|
|
|
if (args[2]->IsUint32()) { |
|
|
|
filter = args[2]->Uint32Value(); |
|
|
|
} else { |
|
|
@ -348,10 +348,10 @@ streamPNG(void *c, const uint8_t *data, unsigned len) { |
|
|
|
closure_t *closure = (closure_t *) c; |
|
|
|
Local<Object> buf = NanNewBufferHandle((char *)data, len); |
|
|
|
Local<Value> argv[3] = { |
|
|
|
NanNewLocal<Value>(Null()) |
|
|
|
NanNull() |
|
|
|
, buf |
|
|
|
, Integer::New(len) }; |
|
|
|
MakeCallback(Context::GetCurrent()->Global(), closure->fn, 3, argv); |
|
|
|
, NanNew<Integer>(len) }; |
|
|
|
NanMakeCallback(NanGetCurrentContext(), closure->fn, 3, argv); |
|
|
|
return CAIRO_STATUS_SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
@ -367,13 +367,13 @@ NAN_METHOD(Canvas::StreamPNGSync) { |
|
|
|
if (!args[0]->IsFunction()) |
|
|
|
return NanThrowTypeError("callback function required"); |
|
|
|
|
|
|
|
if (args.Length() > 1 && !(args[1]->StrictEquals(Undefined()) && args[2]->StrictEquals(Undefined()))) { |
|
|
|
if (!args[1]->StrictEquals(Undefined())) { |
|
|
|
if (args.Length() > 1 && !(args[1]->StrictEquals(NanUndefined()) && args[2]->StrictEquals(NanUndefined()))) { |
|
|
|
if (!args[1]->StrictEquals(NanUndefined())) { |
|
|
|
bool good = true; |
|
|
|
if (args[1]->IsNumber()) { |
|
|
|
compression_level = args[1]->Uint32Value(); |
|
|
|
} else if (args[1]->IsString()) { |
|
|
|
if (args[1]->StrictEquals(String::New("0"))) { |
|
|
|
if (args[1]->StrictEquals(NanNew<String>("0"))) { |
|
|
|
compression_level = 0; |
|
|
|
} else { |
|
|
|
uint32_t tmp = args[1]->Uint32Value(); |
|
|
@ -396,7 +396,7 @@ NAN_METHOD(Canvas::StreamPNGSync) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!args[2]->StrictEquals(Undefined())) { |
|
|
|
if (!args[2]->StrictEquals(NanUndefined())) { |
|
|
|
if (args[2]->IsUint32()) { |
|
|
|
filter = args[1]->Uint32Value(); |
|
|
|
} else { |
|
|
@ -420,13 +420,13 @@ NAN_METHOD(Canvas::StreamPNGSync) { |
|
|
|
NanReturnValue(try_catch.ReThrow()); |
|
|
|
} else if (status) { |
|
|
|
Local<Value> argv[1] = { Canvas::Error(status) }; |
|
|
|
MakeCallback(Context::GetCurrent()->Global(), closure.fn, 1, argv); |
|
|
|
NanMakeCallback(NanGetCurrentContext(), closure.fn, 1, argv); |
|
|
|
} else { |
|
|
|
Local<Value> argv[3] = { |
|
|
|
NanNewLocal<Value>(Null()) |
|
|
|
, NanNewLocal<Value>(Null()) |
|
|
|
, Integer::New(0) }; |
|
|
|
MakeCallback(Context::GetCurrent()->Global(), closure.fn, 3, argv); |
|
|
|
NanNull() |
|
|
|
, NanNull() |
|
|
|
, NanNew<Integer>(0) }; |
|
|
|
NanMakeCallback(NanGetCurrentContext(), closure.fn, 3, argv); |
|
|
|
} |
|
|
|
NanReturnUndefined(); |
|
|
|
} |
|
|
@ -483,7 +483,7 @@ Canvas::Canvas(int w, int h, canvas_type_t t): ObjectWrap() { |
|
|
|
} else { |
|
|
|
_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); |
|
|
|
assert(_surface); |
|
|
|
V8::AdjustAmountOfExternalAllocatedMemory(4 * w * h); |
|
|
|
NanAdjustExternalMemory(4 * w * h); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -501,7 +501,7 @@ Canvas::~Canvas() { |
|
|
|
break; |
|
|
|
case CANVAS_TYPE_IMAGE: |
|
|
|
cairo_surface_destroy(_surface); |
|
|
|
V8::AdjustAmountOfExternalAllocatedMemory(-4 * width * height); |
|
|
|
NanAdjustExternalMemory(-4 * width * height); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -522,10 +522,10 @@ Canvas::resurface(Handle<Object> canvas) { |
|
|
|
int old_height = cairo_image_surface_get_height(_surface); |
|
|
|
cairo_surface_destroy(_surface); |
|
|
|
_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); |
|
|
|
V8::AdjustAmountOfExternalAllocatedMemory(4 * (width * height - old_width * old_height)); |
|
|
|
NanAdjustExternalMemory(4 * (width * height - old_width * old_height)); |
|
|
|
|
|
|
|
// Reset context
|
|
|
|
Handle<Value> context = canvas->Get(String::New("context")); |
|
|
|
Handle<Value> context = canvas->Get(NanNew<String>("context")); |
|
|
|
if (!context->IsUndefined()) { |
|
|
|
Context2d *context2d = ObjectWrap::Unwrap<Context2d>(context->ToObject()); |
|
|
|
cairo_t *prev = context2d->context(); |
|
|
@ -542,5 +542,5 @@ Canvas::resurface(Handle<Object> canvas) { |
|
|
|
|
|
|
|
Local<Value> |
|
|
|
Canvas::Error(cairo_status_t status) { |
|
|
|
return Exception::Error(String::New(cairo_status_to_string(status))); |
|
|
|
return Exception::Error(NanNew<String>(cairo_status_to_string(status))); |
|
|
|
} |
|
|
|