From 8b24624eabb95554b3d0dcf9594b9166a7688d1f Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Fri, 29 Oct 2010 14:44:17 -0700 Subject: [PATCH] Added QuadraticCurveTo() using the libsvg-cairo implementation. Closes #10 --- src/CanvasRenderingContext2d.cc | 34 +++++++++++++++++++++++++++++++++ src/CanvasRenderingContext2d.h | 1 + 2 files changed, 35 insertions(+) diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 27c62c0..d85ebc9 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -91,6 +91,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "moveTo", MoveTo); NODE_SET_PROTOTYPE_METHOD(t, "lineTo", LineTo); NODE_SET_PROTOTYPE_METHOD(t, "bezierCurveTo", BezierCurveTo); + NODE_SET_PROTOTYPE_METHOD(t, "quadraticCurveTo", QuadraticCurveTo); NODE_SET_PROTOTYPE_METHOD(t, "beginPath", BeginPath); NODE_SET_PROTOTYPE_METHOD(t, "closePath", ClosePath); NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc); @@ -547,6 +548,39 @@ Context2d::BezierCurveTo(const Arguments &args) { return Undefined(); } +/* + * Quadratic curve approximation from libsvg-cairo. + */ + +Handle +Context2d::QuadraticCurveTo(const Arguments &args) { + HandleScope scope; + + if (!args[0]->IsNumber() + ||!args[1]->IsNumber() + ||!args[2]->IsNumber() + ||!args[3]->IsNumber()) return Undefined(); + + Context2d *context = ObjectWrap::Unwrap(args.This()); + cairo_t *ctx = context->getContext(); + + double x, y + , x1 = args[0]->NumberValue() + , y1 = args[1]->NumberValue() + , x2 = args[2]->NumberValue() + , y2 = args[3]->NumberValue(); + + cairo_get_current_point(ctx, &x, &y); + + cairo_curve_to(ctx + , x + 2.0 / 3.0 * (x1 - x), y + 2.0 / 3.0 * (y1 - y) + , x2 + 2.0 / 3.0 * (x1 - x2), y2 + 2.0 / 3.0 * (y1 - y2) + , x2 + , y2); + + return Undefined(); +} + /* * Save state. */ diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 35929cd..ac52868 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -65,6 +65,7 @@ class Context2d: public node::ObjectWrap { static Handle SetFillPattern(const Arguments &args); static Handle SetStrokePattern(const Arguments &args); static Handle BezierCurveTo(const Arguments &args); + static Handle QuadraticCurveTo(const Arguments &args); static Handle LineTo(const Arguments &args); static Handle MoveTo(const Arguments &args); static Handle FillRect(const Arguments &args);