Browse Source

Added lineCap accessor

v1.x
Tj Holowaychuk 14 years ago
parent
commit
1119ad88e5
  1. 38
      src/context2d.cc
  2. 2
      src/context2d.h

38
src/context2d.cc

@ -8,6 +8,7 @@
#include "canvas.h"
#include "context2d.h"
#include <math.h>
#include <string.h>
using namespace v8;
using namespace node;
@ -97,6 +98,7 @@ Context2d::Initialize(Handle<Object> 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<String> prop, Local<Value> val, const AccessorInfo
cairo_set_line_width(context->getContext(), val->NumberValue());
}
/*
* Get line cap.
*/
Handle<Value>
Context2d::GetLineCap(Local<String> prop, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(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<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_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=
*/

2
src/context2d.h

@ -34,7 +34,9 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> StrokeRect(const Arguments &args);
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> GetLineWidth(Local<String> prop, const AccessorInfo &info);
static void SetLineCap(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