Browse Source

Added backwards compatibility through conditional compilation.

v1.x
Infinite Whiteboard 11 years ago
parent
commit
13b8f41141
  1. 66
      src/Canvas.cc
  2. 6
      src/CanvasGradient.cc
  3. 6
      src/CanvasPattern.cc
  4. 6
      src/CanvasRenderingContext2d.cc
  5. 6
      src/FontFace.cc
  6. 18
      src/Image.cc
  7. 6
      src/ImageData.cc
  8. 30
      src/JPEGStream.h
  9. 6
      src/PixelArray.cc

66
src/Canvas.cc

@ -29,7 +29,11 @@ Canvas::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Canvas::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Canvas::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(Canvas::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("Canvas"));
@ -202,9 +206,17 @@ Canvas::EIO_AfterToBuffer(eio_req *req) {
Local<Value> argv[1] = { Canvas::Error(closure->status) };
closure->pfn->Call(Context::GetCurrent()->Global(), 1, argv);
} else {
Local<Object> buf = Buffer::New(closure->len);
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Object> buf = Buffer::New(closure->len);
#else
Buffer *buf = Buffer::New(closure->len);
#endif
memcpy(Buffer::Data(buf), closure->data, closure->len);
Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(buf) };
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(buf) };
#else
Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(buf->handle_) };
#endif
closure->pfn->Call(Context::GetCurrent()->Global(), 2, argv);
}
@ -233,9 +245,20 @@ Canvas::ToBuffer(const Arguments &args) {
if (canvas->isPDF()) {
cairo_surface_finish(canvas->surface());
closure_t *closure = (closure_t *) canvas->closure();
Local<Object> buf = Buffer::New(closure->len);
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Object> buf = Buffer::New(closure->len);
#else
Buffer *buf = Buffer::New(closure->len);
#endif
memcpy(Buffer::Data(buf), closure->data, closure->len);
return buf;
#if NODE_VERSION_AT_LEAST(0, 11, 3)
return buf;
#else
return buf->handle_;
#endif
}
// Async
@ -252,7 +275,11 @@ Canvas::ToBuffer(const Arguments &args) {
// TODO: only one callback fn in closure
canvas->Ref();
closure->pfn = Persistent<Function>::New(Isolate::GetCurrent(), Handle<Function>::Cast(args[0]));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
closure->pfn = Persistent<Function>::New(Isolate::GetCurrent(), Handle<Function>::Cast(args[0]));
#else
closure->pfn = Persistent<Function>::New(Handle<Function>::Cast(args[0]));
#endif
#if NODE_VERSION_AT_LEAST(0, 6, 0)
uv_work_t* req = new uv_work_t;
@ -285,10 +312,18 @@ Canvas::ToBuffer(const Arguments &args) {
closure_destroy(&closure);
return ThrowException(Canvas::Error(status));
} else {
Local<Object> buf = Buffer::New(closure.len);
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Object> buf = Buffer::New(closure.len);
#else
Buffer *buf = Buffer::New(closure.len);
#endif
memcpy(Buffer::Data(buf), closure.data, closure.len);
closure_destroy(&closure);
return buf;
#if NODE_VERSION_AT_LEAST(0, 11, 3)
return buf;
#else
return buf->handle_;
#endif
}
}
}
@ -301,11 +336,20 @@ static cairo_status_t
streamPNG(void *c, const uint8_t *data, unsigned len) {
HandleScope scope;
closure_t *closure = (closure_t *) c;
Local<Object> buf = Buffer::New(len);
memcpy(Buffer::Data(buf), data, len);
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Object> buf = Buffer::New(len);
memcpy(Buffer::Data(buf), data, len);
#else
Local<Buffer> buf = Buffer::New(len);
memcpy(Buffer::Data(buf->handle_), data, len);
#endif
Local<Value> argv[3] = {
Local<Value>::New(Null())
, Local<Value>::New(buf)
#if NODE_VERSION_AT_LEAST(0, 11, 3)
, Local<Value>::New(buf)
#else
, Local<Value>::New(buf->handle_)
#endif
, Integer::New(len) };
closure->fn->Call(Context::GetCurrent()->Global(), 3, argv);
return CAIRO_STATUS_SUCCESS;

6
src/CanvasGradient.cc

@ -20,7 +20,11 @@ Gradient::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Gradient::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Gradient::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(Gradient::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("CanvasGradient"));

6
src/CanvasPattern.cc

@ -20,7 +20,11 @@ Pattern::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Pattern::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Pattern::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(Pattern::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("CanvasPattern"));

6
src/CanvasRenderingContext2d.cc

@ -81,7 +81,11 @@ Context2d::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Context2d::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Context2d::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(Context2d::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("CanvasRenderingContext2d"));

6
src/FontFace.cc

@ -28,7 +28,11 @@ FontFace::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(FontFace::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(FontFace::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(FontFace::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("FontFace"));

18
src/Image.cc

@ -39,7 +39,11 @@ Image::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Image::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(Image::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(Image::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("Image"));
@ -274,7 +278,11 @@ void
Image::SetOnload(Local<String>, Local<Value> val, const AccessorInfo &info) {
if (val->IsFunction()) {
Image *img = ObjectWrap::Unwrap<Image>(info.This());
img->onload = Persistent<Function>::New(Isolate::GetCurrent(), Handle<Function>::Cast(val));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
img->onload = Persistent<Function>::New(Isolate::GetCurrent(), Handle<Function>::Cast(val));
#else
img->onload = Persistent<Function>::New(Handle<Function>::Cast(val));
#endif
}
}
@ -296,7 +304,11 @@ void
Image::SetOnerror(Local<String>, Local<Value> val, const AccessorInfo &info) {
if (val->IsFunction()) {
Image *img = ObjectWrap::Unwrap<Image>(info.This());
img->onerror = Persistent<Function>::New(Isolate::GetCurrent(), Handle<Function>::Cast(val));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
img->onerror = Persistent<Function>::New(Isolate::GetCurrent(), Handle<Function>::Cast(val));
#else
img->onerror = Persistent<Function>::New(Handle<Function>::Cast(val));
#endif
}
}

6
src/ImageData.cc

@ -18,7 +18,11 @@ ImageData::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(ImageData::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(ImageData::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(ImageData::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("ImageData"));

30
src/JPEGStream.h

@ -30,11 +30,20 @@ init_closure_destination(j_compress_ptr cinfo){
boolean
empty_closure_output_buffer(j_compress_ptr cinfo){
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest;
Local<Object> buf = Buffer::New(dest->bufsize);
memcpy(Buffer::Data(buf), dest->buffer, dest->bufsize);
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Object> buf = Buffer::New(dest->bufsize);
memcpy(Buffer::Data(buf), dest->buffer, dest->bufsize);
#else
Local<Buffer> buf = Buffer::New(dest->bufsize);
memcpy(Buffer::Data(buf->handle_), dest->buffer, dest->bufsize);
#endif
Local<Value> argv[3] = {
Local<Value>::New(Null())
, Local<Value>::New(buf)
#if NODE_VERSION_AT_LEAST(0, 11, 3)
, Local<Value>::New(buf)
#else
, Local<Value>::New(buf->handle_)
#endif
, Integer::New(dest->bufsize)
};
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, argv);
@ -48,12 +57,21 @@ term_closure_destination(j_compress_ptr cinfo){
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest;
/* emit remaining data */
size_t remaining = dest->bufsize - cinfo->dest->free_in_buffer;
Local<Object> buf = Buffer::New(remaining);
memcpy(Buffer::Data(buf), dest->buffer, remaining);
#if NODE_VERSION_AT_LEAST(0, 11, 3)
Local<Object> buf = Buffer::New(remaining);
memcpy(Buffer::Data(buf), dest->buffer, remaining);
#else
Local<Buffer> buf = Buffer::New(remaining);
memcpy(Buffer::Data(buf->handle_), dest->buffer, remaining);
#endif
Local<Value> data_argv[3] = {
Local<Value>::New(Null())
, Local<Value>::New(buf)
#if NODE_VERSION_AT_LEAST(0, 11, 3)
, Local<Value>::New(buf)
#else
, Local<Value>::New(buf->handle_)
#endif
, Integer::New(remaining)
};

6
src/PixelArray.cc

@ -20,7 +20,11 @@ PixelArray::Initialize(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(PixelArray::New));
#if NODE_VERSION_AT_LEAST(0, 11, 3)
constructor = Persistent<FunctionTemplate>::New(Isolate::GetCurrent(), FunctionTemplate::New(PixelArray::New));
#else
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(PixelArray::New));
#endif
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("CanvasPixelArray"));

Loading…
Cancel
Save