From 1119ad88e5e83b110dcfaba2a7dde35d8118f9d0 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 29 Sep 2010 13:55:29 -0700 Subject: [PATCH] Added lineCap accessor --- src/context2d.cc | 38 ++++++++++++++++++++++++++++++++++++++ src/context2d.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/src/context2d.cc b/src/context2d.cc index 167068f..f44a93e 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -8,6 +8,7 @@ #include "canvas.h" #include "context2d.h" #include +#include using namespace v8; using namespace node; @@ -97,6 +98,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA); NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA); proto->SetAccessor(String::NewSymbol("lineWidth"), GetLineWidth, SetLineWidth); + proto->SetAccessor(String::NewSymbol("lineCap"), GetLineCap, SetLineCap); target->Set(String::NewSymbol("Context2d"), t->GetFunction()); } @@ -152,6 +154,42 @@ Context2d::SetLineWidth(Local prop, Local val, const AccessorInfo cairo_set_line_width(context->getContext(), val->NumberValue()); } +/* + * Get line cap. + */ + +Handle +Context2d::GetLineCap(Local prop, const AccessorInfo &info) { + Context2d *context = ObjectWrap::Unwrap(info.This()); + switch (cairo_get_line_cap(context->getContext())) { + case CAIRO_LINE_CAP_ROUND: + return String::NewSymbol("round"); + case CAIRO_LINE_CAP_SQUARE: + return String::NewSymbol("square"); + default: + return String::NewSymbol("butt"); + } +} + +/* + * Set line cap. + */ + +void +Context2d::SetLineCap(Local prop, Local val, const AccessorInfo &info) { + Context2d *context = ObjectWrap::Unwrap(info.This()); + cairo_t *ctx = context->getContext(); + String::AsciiValue type(val); + if (0 == strcmp("round", *type)) { + cairo_set_line_cap(ctx, CAIRO_LINE_CAP_ROUND); + } else if (0 == strcmp("square", *type)) { + cairo_set_line_cap(ctx, CAIRO_LINE_CAP_SQUARE); + } else { + cairo_set_line_cap(ctx, CAIRO_LINE_CAP_BUTT); + } +} + + /* * Set fill RGBA, used internally for fillStyle= */ diff --git a/src/context2d.h b/src/context2d.h index 4b27bfb..ccc7958 100644 --- a/src/context2d.h +++ b/src/context2d.h @@ -34,7 +34,9 @@ class Context2d: public node::ObjectWrap { static Handle StrokeRect(const Arguments &args); static Handle ClearRect(const Arguments &args); static Handle Arc(const Arguments &args); + static Handle GetLineCap(Local prop, const AccessorInfo &info); static Handle GetLineWidth(Local prop, const AccessorInfo &info); + static void SetLineCap(Local prop, Local val, const AccessorInfo &info); static void SetLineWidth(Local prop, Local val, const AccessorInfo &info); inline cairo_t *getContext(){ return _context; } inline Canvas *getCanvas(){ return _canvas; }