Browse Source

Added lineJoin accessor

v1.x
Tj Holowaychuk 14 years ago
parent
commit
2c2e20d807
  1. 37
      src/context2d.cc
  2. 2
      src/context2d.h

37
src/context2d.cc

@ -99,6 +99,7 @@ Context2d::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA);
proto->SetAccessor(String::NewSymbol("lineWidth"), GetLineWidth, SetLineWidth);
proto->SetAccessor(String::NewSymbol("lineCap"), GetLineCap, SetLineCap);
proto->SetAccessor(String::NewSymbol("lineJoin"), GetLineJoin, SetLineJoin);
target->Set(String::NewSymbol("Context2d"), t->GetFunction());
}
@ -154,6 +155,41 @@ Context2d::SetLineWidth(Local<String> prop, Local<Value> val, const AccessorInfo
cairo_set_line_width(context->getContext(), val->NumberValue());
}
/*
* Get line join.
*/
Handle<Value>
Context2d::GetLineJoin(Local<String> prop, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
switch (cairo_get_line_join(context->getContext())) {
case CAIRO_LINE_JOIN_BEVEL:
return String::NewSymbol("bevel");
case CAIRO_LINE_JOIN_ROUND:
return String::NewSymbol("round");
default:
return String::NewSymbol("miter");
}
}
/*
* Set line join.
*/
void
Context2d::SetLineJoin(Local<String> prop, Local<Value> val, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
cairo_t *ctx = context->getContext();
String::AsciiValue type(val);
if (0 == strcmp("round", *type)) {
cairo_set_line_join(ctx, CAIRO_LINE_JOIN_ROUND);
} else if (0 == strcmp("bevel", *type)) {
cairo_set_line_join(ctx, CAIRO_LINE_JOIN_BEVEL);
} else {
cairo_set_line_join(ctx, CAIRO_LINE_JOIN_MITER);
}
}
/*
* Get line cap.
*/
@ -189,7 +225,6 @@ Context2d::SetLineCap(Local<String> prop, Local<Value> val, const AccessorInfo &
}
}
/*
* Set fill RGBA, used internally for fillStyle=
*/

2
src/context2d.h

@ -35,8 +35,10 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> ClearRect(const Arguments &args);
static Handle<Value> Arc(const Arguments &args);
static Handle<Value> GetLineCap(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetLineJoin(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetLineWidth(Local<String> prop, const AccessorInfo &info);
static void SetLineCap(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetLineJoin(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetLineWidth(Local<String> prop, Local<Value> val, const AccessorInfo &info);
inline cairo_t *getContext(){ return _context; }
inline Canvas *getCanvas(){ return _canvas; }

Loading…
Cancel
Save