Browse Source

Merge pull request #409 from rvagg/nan-1.0.0

NAN 1.0.0 for Node 0.11.13 support
v1.x
Juriy Zaytsev 11 years ago
parent
commit
dbdb9d854c
  1. 2
      package.json
  2. 70
      src/Canvas.cc
  3. 2
      src/Canvas.h
  4. 8
      src/CanvasGradient.cc
  5. 2
      src/CanvasGradient.h
  6. 4
      src/CanvasPattern.cc
  7. 2
      src/CanvasPattern.h
  8. 110
      src/CanvasRenderingContext2d.cc
  9. 8
      src/FontFace.cc
  10. 28
      src/Image.cc
  11. 2
      src/Image.h
  12. 8
      src/ImageData.cc
  13. 26
      src/JPEGStream.h
  14. 12
      src/PixelArray.cc
  15. 6
      src/closure.h
  16. 8
      src/init.cc

2
package.json

@ -14,7 +14,7 @@
"test": "make test"
}
, "dependencies": {
"nan": "~0.7.0"
"nan": "~1.0.0"
}
, "devDependencies": {
"express": "3.0"

70
src/Canvas.cc

@ -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());
}
@ -67,7 +67,7 @@ NAN_METHOD(Canvas::New) {
canvas_type_t type = CANVAS_TYPE_IMAGE;
if (args[0]->IsNumber()) width = args[0]->Uint32Value();
if (args[1]->IsNumber()) height = args[1]->Uint32Value();
if (args[2]->IsString()) type = !strcmp("pdf", *String::AsciiValue(args[2]))
if (args[2]->IsString()) type = !strcmp("pdf", *String::Utf8Value(args[2]))
? CANVAS_TYPE_PDF
: CANVAS_TYPE_IMAGE;
Canvas *canvas = new Canvas(width, height, type);
@ -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] = { NanNew(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())
NanNew(NanNull())
, buf
, Integer::New(len) };
MakeCallback(Context::GetCurrent()->Global(), closure->fn, 3, argv);
, NanNew<Integer>(len) };
NanMakeCallback(NanGetCurrentContext()->Global(), 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()->Global(), 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);
NanNew(NanNull())
, NanNew(NanNull())
, NanNew<Uint32>(0) };
NanMakeCallback(NanGetCurrentContext()->Global(), closure.fn, 1, 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)));
}

2
src/Canvas.h

@ -19,7 +19,7 @@
#include <cairo/cairo.h>
#endif
#include "nan.h"
#include <nan.h>
using namespace v8;
using namespace node;

8
src/CanvasGradient.cc

@ -20,8 +20,8 @@ Gradient::Initialize(Handle<Object> target) {
NanScope();
// Constructor
Local<FunctionTemplate> ctor = FunctionTemplate::New(Gradient::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Gradient::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("CanvasGradient"));
@ -60,7 +60,7 @@ NAN_METHOD(Gradient::New) {
grad->Wrap(args.This());
NanReturnValue(args.This());
}
return NanThrowTypeError("invalid arguments");
}
@ -77,7 +77,7 @@ NAN_METHOD(Gradient::AddColorStop) {
Gradient *grad = ObjectWrap::Unwrap<Gradient>(args.This());
short ok;
String::AsciiValue str(args[1]);
String::Utf8Value str(args[1]);
uint32_t rgba = rgba_from_string(*str, &ok);
if (ok) {

2
src/CanvasGradient.h

@ -8,7 +8,7 @@
#ifndef __NODE_GRADIENT_H__
#define __NODE_GRADIENT_H__
#include "nan.h"
#include <nan.h>
#include "Canvas.h"
class Gradient: public node::ObjectWrap {

4
src/CanvasPattern.cc

@ -20,8 +20,8 @@ Pattern::Initialize(Handle<Object> target) {
NanScope();
// Constructor
Local<FunctionTemplate> ctor = FunctionTemplate::New(Pattern::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Pattern::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("CanvasPattern"));

2
src/CanvasPattern.h

@ -8,7 +8,7 @@
#ifndef __NODE_PATTERN_H__
#define __NODE_PATTERN_H__
#include "nan.h"
#include <nan.h>
#include "Canvas.h"
class Pattern: public node::ObjectWrap {

110
src/CanvasRenderingContext2d.cc

@ -81,8 +81,8 @@ Context2d::Initialize(Handle<Object> target) {
NanScope();
// Constructor
Local<FunctionTemplate> ctor = FunctionTemplate::New(Context2d::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Context2d::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("CanvasRenderingContext2d"));
@ -694,7 +694,7 @@ NAN_METHOD(Context2d::DrawImage) {
NAN_GETTER(Context2d::GetGlobalAlpha) {
NanScope();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
NanReturnValue(Number::New(context->state->globalAlpha));
NanReturnValue(NanNew<Number>(context->state->globalAlpha));
}
/*
@ -764,7 +764,7 @@ NAN_GETTER(Context2d::GetGlobalCompositeOperation) {
NAN_SETTER(Context2d::SetPatternQuality) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
String::AsciiValue quality(value->ToString());
String::Utf8Value quality(value->ToString());
if (0 == strcmp("fast", *quality)) {
context->state->patternQuality = CAIRO_FILTER_FAST;
} else if (0 == strcmp("good", *quality)) {
@ -803,7 +803,7 @@ NAN_GETTER(Context2d::GetPatternQuality) {
NAN_SETTER(Context2d::SetGlobalCompositeOperation) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->context();
String::AsciiValue type(value->ToString());
String::Utf8Value type(value->ToString());
if (0 == strcmp("xor", *type)) {
cairo_set_operator(ctx, CAIRO_OPERATOR_XOR);
} else if (0 == strcmp("source-atop", *type)) {
@ -878,7 +878,7 @@ NAN_SETTER(Context2d::SetGlobalCompositeOperation) {
NAN_GETTER(Context2d::GetShadowOffsetX) {
NanScope();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
NanReturnValue(Number::New(context->state->shadowOffsetX));
NanReturnValue(NanNew<Number>(context->state->shadowOffsetX));
}
/*
@ -897,7 +897,7 @@ NAN_SETTER(Context2d::SetShadowOffsetX) {
NAN_GETTER(Context2d::GetShadowOffsetY) {
NanScope();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
NanReturnValue(Number::New(context->state->shadowOffsetY));
NanReturnValue(NanNew<Number>(context->state->shadowOffsetY));
}
/*
@ -916,7 +916,7 @@ NAN_SETTER(Context2d::SetShadowOffsetY) {
NAN_GETTER(Context2d::GetShadowBlur) {
NanScope();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
NanReturnValue(Number::New(context->state->shadowBlur));
NanReturnValue(NanNew<Number>(context->state->shadowBlur));
}
/*
@ -953,7 +953,7 @@ NAN_GETTER(Context2d::GetAntiAlias) {
*/
NAN_SETTER(Context2d::SetAntiAlias) {
String::AsciiValue str(value->ToString());
String::Utf8Value str(value->ToString());
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->context();
cairo_antialias_t a;
@ -994,7 +994,7 @@ NAN_GETTER(Context2d::GetTextDrawingMode) {
*/
NAN_SETTER(Context2d::SetTextDrawingMode) {
String::AsciiValue str(value->ToString());
String::Utf8Value str(value->ToString());
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
if (0 == strcmp("path", *str)) {
context->state->textDrawingMode = TEXT_DRAW_PATHS;
@ -1026,7 +1026,7 @@ NAN_GETTER(Context2d::GetFilter) {
*/
NAN_SETTER(Context2d::SetFilter) {
String::AsciiValue str(value->ToString());
String::Utf8Value str(value->ToString());
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_filter_t filter;
if (0 == strcmp("fast", *str)) {
@ -1050,7 +1050,7 @@ NAN_SETTER(Context2d::SetFilter) {
NAN_GETTER(Context2d::GetMiterLimit) {
NanScope();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
NanReturnValue(Number::New(cairo_get_miter_limit(context->context())));
NanReturnValue(NanNew<Number>(cairo_get_miter_limit(context->context())));
}
/*
@ -1072,7 +1072,7 @@ NAN_SETTER(Context2d::SetMiterLimit) {
NAN_GETTER(Context2d::GetLineWidth) {
NanScope();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
NanReturnValue(Number::New(cairo_get_line_width(context->context())));
NanReturnValue(NanNew<Number>(cairo_get_line_width(context->context())));
}
/*
@ -1110,7 +1110,7 @@ NAN_GETTER(Context2d::GetLineJoin) {
NAN_SETTER(Context2d::SetLineJoin) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->context();
String::AsciiValue type(value->ToString());
String::Utf8Value type(value->ToString());
if (0 == strcmp("round", *type)) {
cairo_set_line_join(ctx, CAIRO_LINE_JOIN_ROUND);
} else if (0 == strcmp("bevel", *type)) {
@ -1143,7 +1143,7 @@ NAN_GETTER(Context2d::GetLineCap) {
NAN_SETTER(Context2d::SetLineCap) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->context();
String::AsciiValue type(value->ToString());
String::Utf8Value type(value->ToString());
if (0 == strcmp("round", *type)) {
cairo_set_line_cap(ctx, CAIRO_LINE_CAP_ROUND);
} else if (0 == strcmp("square", *type)) {
@ -1164,9 +1164,9 @@ NAN_METHOD(Context2d::IsPointInPath) {
cairo_t *ctx = context->context();
double x = args[0]->NumberValue()
, y = args[1]->NumberValue();
NanReturnValue(Boolean::New(cairo_in_fill(ctx, x, y) || cairo_in_stroke(ctx, x, y)));
NanReturnValue(NanNew<Boolean>(cairo_in_fill(ctx, x, y) || cairo_in_stroke(ctx, x, y)));
}
NanReturnValue(False());
NanReturnValue(NanFalse());
}
/*
@ -1220,7 +1220,7 @@ NAN_METHOD(Context2d::SetStrokePattern) {
NAN_SETTER(Context2d::SetShadowColor) {
short ok;
String::AsciiValue str(value->ToString());
String::Utf8Value str(value->ToString());
uint32_t rgba = rgba_from_string(*str, &ok);
if (ok) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
@ -1237,7 +1237,7 @@ NAN_GETTER(Context2d::GetShadowColor) {
char buf[64];
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
rgba_to_string(context->state->shadow, buf, sizeof(buf));
NanReturnValue(String::New(buf));
NanReturnValue(NanNew<String>(buf));
}
/*
@ -1248,7 +1248,7 @@ NAN_METHOD(Context2d::SetFillColor) {
NanScope();
short ok;
if (!args[0]->IsString()) NanReturnUndefined();
String::AsciiValue str(args[0]);
String::Utf8Value str(args[0]);
uint32_t rgba = rgba_from_string(*str, &ok);
if (!ok) NanReturnUndefined();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
@ -1266,7 +1266,7 @@ NAN_GETTER(Context2d::GetFillColor) {
char buf[64];
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
rgba_to_string(context->state->fill, buf, sizeof(buf));
NanReturnValue(String::New(buf));
NanReturnValue(NanNew<String>(buf));
}
/*
@ -1277,7 +1277,7 @@ NAN_METHOD(Context2d::SetStrokeColor) {
NanScope();
short ok;
if (!args[0]->IsString()) NanReturnUndefined();
String::AsciiValue str(args[0]);
String::Utf8Value str(args[0]);
uint32_t rgba = rgba_from_string(*str, &ok);
if (!ok) NanReturnUndefined();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
@ -1295,7 +1295,7 @@ NAN_GETTER(Context2d::GetStrokeColor) {
char buf[64];
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
rgba_to_string(context->state->stroke, buf, sizeof(buf));
NanReturnValue(String::New(buf));
NanReturnValue(NanNew<String>(buf));
}
/*
@ -1763,11 +1763,11 @@ NAN_METHOD(Context2d::SetFont) {
|| !args[3]->IsString()
|| !args[4]->IsString()) NanReturnUndefined();
String::AsciiValue weight(args[0]);
String::AsciiValue style(args[1]);
String::Utf8Value weight(args[0]);
String::Utf8Value style(args[1]);
double size = args[2]->NumberValue();
String::AsciiValue unit(args[3]);
String::AsciiValue family(args[4]);
String::Utf8Value unit(args[3]);
String::Utf8Value family(args[4]);
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
@ -1876,7 +1876,7 @@ NAN_METHOD(Context2d::MeasureText) {
cairo_t *ctx = context->context();
String::Utf8Value str(args[0]->ToString());
Local<Object> obj = Object::New();
Local<Object> obj = NanNew<Object>();
#if HAVE_PANGO
@ -1917,21 +1917,21 @@ NAN_METHOD(Context2d::MeasureText) {
y_offset = 0.0;
}
obj->Set(String::New("width"), Number::New(logical_rect.width));
obj->Set(String::New("actualBoundingBoxLeft"),
Number::New(x_offset - PANGO_LBEARING(logical_rect)));
obj->Set(String::New("actualBoundingBoxRight"),
Number::New(x_offset + PANGO_RBEARING(logical_rect)));
obj->Set(String::New("actualBoundingBoxAscent"),
Number::New(-(y_offset+ink_rect.y)));
obj->Set(String::New("actualBoundingBoxDescent"),
Number::New((PANGO_DESCENT(ink_rect) + y_offset)));
obj->Set(String::New("emHeightAscent"),
Number::New(PANGO_ASCENT(logical_rect) - y_offset));
obj->Set(String::New("emHeightDescent"),
Number::New(PANGO_DESCENT(logical_rect) + y_offset));
obj->Set(String::New("alphabeticBaseline"),
Number::New((pango_font_metrics_get_ascent(metrics) / PANGO_SCALE)
obj->Set(NanNew<String>("width"), NanNew<Number>(logical_rect.width));
obj->Set(NanNew<String>("actualBoundingBoxLeft"),
NanNew<Number>(x_offset - PANGO_LBEARING(logical_rect)));
obj->Set(NanNew<String>("actualBoundingBoxRight"),
NanNew<Number>(x_offset + PANGO_RBEARING(logical_rect)));
obj->Set(NanNew<String>("actualBoundingBoxAscent"),
NanNew<Number>(-(y_offset+ink_rect.y)));
obj->Set(NanNew<String>("actualBoundingBoxDescent"),
NanNew<Number>((PANGO_DESCENT(ink_rect) + y_offset)));
obj->Set(NanNew<String>("emHeightAscent"),
NanNew<Number>(PANGO_ASCENT(logical_rect) - y_offset));
obj->Set(NanNew<String>("emHeightDescent"),
NanNew<Number>(PANGO_DESCENT(logical_rect) + y_offset));
obj->Set(NanNew<String>("alphabeticBaseline"),
NanNew<Number>((pango_font_metrics_get_ascent(metrics) / PANGO_SCALE)
+ y_offset));
pango_font_metrics_unref(metrics);
@ -1972,18 +1972,18 @@ NAN_METHOD(Context2d::MeasureText) {
y_offset = 0.0;
}
obj->Set(String::New("width"), Number::New(te.x_advance));
obj->Set(String::New("actualBoundingBoxLeft"),
Number::New(x_offset - te.x_bearing));
obj->Set(String::New("actualBoundingBoxRight"),
Number::New((te.x_bearing + te.width) - x_offset));
obj->Set(String::New("actualBoundingBoxAscent"),
Number::New(-(te.y_bearing + y_offset)));
obj->Set(String::New("actualBoundingBoxDescent"),
Number::New(te.height + te.y_bearing + y_offset));
obj->Set(String::New("emHeightAscent"), Number::New(fe.ascent - y_offset));
obj->Set(String::New("emHeightDescent"), Number::New(fe.descent + y_offset));
obj->Set(String::New("alphabeticBaseline"), Number::New(y_offset));
obj->Set(NanNew<String>("width"), NanNew<Number>(te.x_advance));
obj->Set(NanNew<String>("actualBoundingBoxLeft"),
NanNew<Number>(x_offset - te.x_bearing));
obj->Set(NanNew<String>("actualBoundingBoxRight"),
NanNew<Number>((te.x_bearing + te.width) - x_offset));
obj->Set(NanNew<String>("actualBoundingBoxAscent"),
NanNew<Number>(-(te.y_bearing + y_offset)));
obj->Set(NanNew<String>("actualBoundingBoxDescent"),
NanNew<Number>(te.height + te.y_bearing + y_offset));
obj->Set(NanNew<String>("emHeightAscent"), NanNew<Number>(fe.ascent - y_offset));
obj->Set(NanNew<String>("emHeightDescent"), NanNew<Number>(fe.descent + y_offset));
obj->Set(NanNew<String>("alphabeticBaseline"), NanNew<Number>(y_offset));
#endif

8
src/FontFace.cc

@ -6,7 +6,7 @@
#include "FontFace.h"
#include "nan.h"
#include <nan.h>
Persistent<FunctionTemplate> FontFace::constructor;
@ -30,8 +30,8 @@ FontFace::Initialize(Handle<Object> target) {
NanScope();
// Constructor
Local<FunctionTemplate> ctor = FunctionTemplate::New(FontFace::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(FontFace::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("FontFace"));
@ -60,7 +60,7 @@ NAN_METHOD(FontFace::New) {
return NanThrowError("Wrong argument types passed to FontFace constructor");
}
String::AsciiValue filePath(args[0]);
String::Utf8Value filePath(args[0]);
int faceIdx = int(args[1]->NumberValue());
FT_Face ftFace;

28
src/Image.cc

@ -38,8 +38,8 @@ void
Image::Initialize(Handle<Object> target) {
NanScope();
Local<FunctionTemplate> ctor = FunctionTemplate::New(Image::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(Image::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("Image"));
@ -56,8 +56,8 @@ Image::Initialize(Handle<Object> target) {
proto->SetAccessor(NanSymbol("onerror"), GetOnerror, SetOnerror);
#if CAIRO_VERSION_MINOR >= 10
proto->SetAccessor(NanSymbol("dataMode"), GetDataMode, SetDataMode);
ctor->Set(NanSymbol("MODE_IMAGE"), Number::New(DATA_IMAGE));
ctor->Set(NanSymbol("MODE_MIME"), Number::New(DATA_MIME));
ctor->Set(NanSymbol("MODE_IMAGE"), NanNew<Number>(DATA_IMAGE));
ctor->Set(NanSymbol("MODE_MIME"), NanNew<Number>(DATA_MIME));
#endif
target->Set(NanSymbol("Image"), ctor->GetFunction());
}
@ -81,7 +81,7 @@ NAN_METHOD(Image::New) {
NAN_GETTER(Image::GetComplete) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(Boolean::New(Image::COMPLETE == img->state));
NanReturnValue(NanNew<Boolean>(Image::COMPLETE == img->state));
}
#if CAIRO_VERSION_MINOR >= 10
@ -93,7 +93,7 @@ NAN_GETTER(Image::GetComplete) {
NAN_GETTER(Image::GetDataMode) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(Number::New(img->data_mode));
NanReturnValue(NanNew<Number>(img->data_mode));
}
/*
@ -117,7 +117,7 @@ NAN_SETTER(Image::SetDataMode) {
NAN_GETTER(Image::GetWidth) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(Number::New(img->width));
NanReturnValue(NanNew<Number>(img->width));
}
/*
* Get height.
@ -126,7 +126,7 @@ NAN_GETTER(Image::GetWidth) {
NAN_GETTER(Image::GetHeight) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(Number::New(img->height));
NanReturnValue(NanNew<Number>(img->height));
}
/*
@ -136,7 +136,7 @@ NAN_GETTER(Image::GetHeight) {
NAN_GETTER(Image::GetSource) {
NanScope();
Image *img = ObjectWrap::Unwrap<Image>(args.This());
NanReturnValue(String::New(img->filename ? img->filename : ""));
NanReturnValue(NanNew<String>(img->filename ? img->filename : ""));
}
/*
@ -147,7 +147,7 @@ void
Image::clearData() {
if (_surface) {
cairo_surface_destroy(_surface);
V8::AdjustAmountOfExternalAllocatedMemory(-_data_len);
NanAdjustExternalMemory(-_data_len);
_data_len = 0;
_surface = NULL;
}
@ -175,7 +175,7 @@ NAN_SETTER(Image::SetSource) {
// url string
if (value->IsString()) {
String::AsciiValue src(value);
String::Utf8Value src(value);
if (img->filename) free(img->filename);
img->filename = strdup(*src);
status = img->load();
@ -359,7 +359,7 @@ Image::loaded() {
width = cairo_image_surface_get_width(_surface);
height = cairo_image_surface_get_height(_surface);
_data_len = height * cairo_image_surface_get_stride(_surface);
V8::AdjustAmountOfExternalAllocatedMemory(_data_len);
NanAdjustExternalMemory(_data_len);
if (onload != NULL) {
onload->Call(0, NULL);
@ -807,7 +807,7 @@ Image::decodeJPEGBufferIntoMimeSurface(uint8_t *buf, unsigned len) {
void
clearMimeData(void *closure) {
V8::AdjustAmountOfExternalAllocatedMemory(-((read_closure_t *)closure)->len);
NanAdjustExternalMemory(-((read_closure_t *)closure)->len);
free(((read_closure_t *) closure)->buf);
free(closure);
}
@ -834,7 +834,7 @@ Image::assignDataAsMime(uint8_t *data, int len, const char *mime_type) {
mime_closure->buf = mime_data;
mime_closure->len = len;
V8::AdjustAmountOfExternalAllocatedMemory(len);
NanAdjustExternalMemory(len);
return cairo_surface_set_mime_data(_surface
, mime_type

2
src/Image.h

@ -8,7 +8,7 @@
#ifndef __NODE_IMAGE_H__
#define __NODE_IMAGE_H__
#include "nan.h"
#include <nan.h>
#include "Canvas.h"
#ifdef HAVE_JPEG

8
src/ImageData.cc

@ -18,8 +18,8 @@ ImageData::Initialize(Handle<Object> target) {
NanScope();
// Constructor
Local<FunctionTemplate> ctor = FunctionTemplate::New(ImageData::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(ImageData::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("ImageData"));
@ -55,7 +55,7 @@ NAN_METHOD(ImageData::New) {
NAN_GETTER(ImageData::GetWidth) {
NanScope();
ImageData *imageData = ObjectWrap::Unwrap<ImageData>(args.This());
NanReturnValue(Number::New(imageData->pixelArray()->width()));
NanReturnValue(NanNew<Number>(imageData->pixelArray()->width()));
}
/*
@ -65,5 +65,5 @@ NAN_GETTER(ImageData::GetWidth) {
NAN_GETTER(ImageData::GetHeight) {
NanScope();
ImageData *imageData = ObjectWrap::Unwrap<ImageData>(args.This());
NanReturnValue(Number::New(imageData->pixelArray()->height()));
NanReturnValue(NanNew<Number>(imageData->pixelArray()->height()));
}

26
src/JPEGStream.h

@ -6,7 +6,7 @@
#ifndef __NODE_JPEG_STREAM_H__
#define __NODE_JPEG_STREAM_H__
#include "nan.h"
#include <nan.h>
#include "Canvas.h"
#include <jpeglib.h>
#include <jerror.h>
@ -34,11 +34,11 @@ empty_closure_output_buffer(j_compress_ptr cinfo){
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest;
Local<Object> buf = NanNewBufferHandle((char *)dest->buffer, dest->bufsize);
Local<Value> argv[3] = {
NanNewLocal<Value>(Null())
, NanNewLocal<Value>(buf)
, Integer::New(dest->bufsize)
NanNew(NanNull())
, NanNew(buf)
, NanNew<Integer>(dest->bufsize)
};
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, argv);
NanMakeCallback(NanGetCurrentContext()->Global(), dest->closure->fn, 3, argv);
cinfo->dest->next_output_byte = dest->buffer;
cinfo->dest->free_in_buffer = dest->bufsize;
return true;
@ -53,21 +53,21 @@ term_closure_destination(j_compress_ptr cinfo){
Local<Object> buf = NanNewBufferHandle((char *)dest->buffer, remaining);
Local<Value> data_argv[3] = {
NanNewLocal<Value>(Null())
, NanNewLocal<Value>(buf)
, Integer::New(remaining)
NanNew(NanNull())
, NanNew(buf)
, NanNew<Integer>(remaining)
};
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, data_argv);
NanMakeCallback(NanGetCurrentContext()->Global(), dest->closure->fn, 3, data_argv);
// emit "end"
Local<Value> end_argv[3] = {
NanNewLocal<Value>(Null())
, NanNewLocal<Value>(Null())
, Integer::New(0)
NanNew(NanNull())
, NanNew(NanNull())
, NanNew<Integer>(0)
};
dest->closure->fn->Call(Context::GetCurrent()->Global(), 3, end_argv);
NanMakeCallback(NanGetCurrentContext()->Global(), dest->closure->fn, 3, end_argv);
}
void

12
src/PixelArray.cc

@ -9,7 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include "nan.h"
#include <nan.h>
Persistent<FunctionTemplate> PixelArray::constructor;
@ -22,8 +22,8 @@ PixelArray::Initialize(Handle<Object> target) {
NanScope();
// Constructor
Local<FunctionTemplate> ctor = FunctionTemplate::New(PixelArray::New);
NanAssignPersistent(FunctionTemplate, constructor, ctor);
Local<FunctionTemplate> ctor = NanNew<FunctionTemplate>(PixelArray::New);
NanAssignPersistent(constructor, ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(1);
ctor->SetClassName(NanSymbol("CanvasPixelArray"));
@ -82,7 +82,7 @@ NAN_METHOD(PixelArray::New) {
NAN_GETTER(PixelArray::GetLength) {
NanScope();
NanReturnValue(Number::New(args.This()->GetIndexedPropertiesPixelDataLength()));
NanReturnValue(NanNew<Number>(args.This()->GetIndexedPropertiesPixelDataLength()));
}
/*
@ -142,7 +142,7 @@ uint8_t *
PixelArray::alloc() {
int len = length();
_data = (uint8_t *) calloc(1, len);
V8::AdjustAmountOfExternalAllocatedMemory(len);
NanAdjustExternalMemory(len);
return _data;
}
@ -151,6 +151,6 @@ PixelArray::alloc() {
*/
PixelArray::~PixelArray() {
V8::AdjustAmountOfExternalAllocatedMemory(-length());
NanAdjustExternalMemory(-length());
free(_data);
}

6
src/closure.h

@ -16,7 +16,7 @@
#define PAGE_SIZE 4096
#endif
#include "nan.h"
#include <nan.h>
/*
* PNG stream closure.
@ -50,7 +50,7 @@ closure_init(closure_t *closure, Canvas *canvas, unsigned int compression_level,
}
/*
* Free the given closure's data,
* Free the given closure's data,
* and hint V8 at the memory dealloc.
*/
@ -58,7 +58,7 @@ void
closure_destroy(closure_t *closure) {
if (closure->len) {
free(closure->data);
V8::AdjustAmountOfExternalAllocatedMemory(- (intptr_t) closure->max_len);
NanAdjustExternalMemory(-((intptr_t) closure->max_len));
}
}

8
src/init.cc

@ -32,7 +32,7 @@ init (Handle<Object> target) {
FontFace::Initialize(target);
#endif
target->Set(String::New("cairoVersion"), String::New(cairo_version_string()));
target->Set(NanNew<String>("cairoVersion"), NanNew<String>(cairo_version_string()));
#ifdef HAVE_JPEG
#ifndef JPEG_LIB_VERSION_MAJOR
@ -57,16 +57,16 @@ init (Handle<Object> target) {
} else {
snprintf(jpeg_version, 10, "%d", JPEG_LIB_VERSION_MAJOR);
}
target->Set(String::New("jpegVersion"), String::New(jpeg_version));
target->Set(NanNew<String>("jpegVersion"), NanNew<String>(jpeg_version));
#endif
#ifdef HAVE_GIF
#ifndef GIF_LIB_VERSION
char gif_version[10];
snprintf(gif_version, 10, "%d.%d.%d", GIFLIB_MAJOR, GIFLIB_MINOR, GIFLIB_RELEASE);
target->Set(String::New("gifVersion"), String::New(gif_version));
target->Set(NanNew<String>("gifVersion"), NanNew<String>(gif_version));
#else
target->Set(String::New("gifVersion"), String::New(GIF_LIB_VERSION));
target->Set(NanNew<String>("gifVersion"), NanNew<String>(GIF_LIB_VERSION));
#endif
#endif
}

Loading…
Cancel
Save