From 0d5b80a284514b082bb49c15d2b9a6cf108d8ecc Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 2 Nov 2010 14:05:12 -0700 Subject: [PATCH] Added SetTextBaseline() --- src/CanvasRenderingContext2d.cc | 30 +++++++++++++++++++++++++++++- src/CanvasRenderingContext2d.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 41816a1..14cd319 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -59,6 +59,19 @@ using namespace node; int width = args[2]->Int32Value(); \ int height = args[3]->Int32Value(); +/* + * Text baselines. + */ + +enum { + TEXT_BASELINE_ALPHABETIC + , TEXT_BASELINE_TOP + , TEXT_BASELINE_BOTTOM + , TEXT_BASELINE_MIDDLE + , TEXT_BASELINE_IDEOGRAPHIC + , TEXT_BASELINE_HANGING +}; + /* * Initialize Context2d. */ @@ -88,6 +101,7 @@ Context2d::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "strokeRect", StrokeRect); NODE_SET_PROTOTYPE_METHOD(t, "clearRect", ClearRect); NODE_SET_PROTOTYPE_METHOD(t, "rect", Rect); + NODE_SET_PROTOTYPE_METHOD(t, "setTextBaseline", SetTextBaseline); NODE_SET_PROTOTYPE_METHOD(t, "setTextAlignment", SetTextAlignment); NODE_SET_PROTOTYPE_METHOD(t, "setTextPath", SetTextPath); NODE_SET_PROTOTYPE_METHOD(t, "measureText", MeasureText); @@ -868,6 +882,21 @@ Context2d::MeasureText(const Arguments &args) { return scope.Close(obj); } +/* + * Set text baseline. + */ + +Handle +Context2d::SetTextBaseline(const Arguments &args) { + HandleScope scope; + + if (!args[0]->IsInt32()) return Undefined(); + Context2d *context = ObjectWrap::Unwrap(args.This()); + context->state->textBaseline = args[0]->Int32Value(); + + return Undefined(); +} + /* * Set text alignment. -1 0 1 */ @@ -883,7 +912,6 @@ Context2d::SetTextAlignment(const Arguments &args) { return Undefined(); } - /* * Set text path at x, y. */ diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 8e16de3..f32054f 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -33,6 +33,7 @@ typedef struct { cairo_pattern_t *strokePattern; float globalAlpha; short textAlignment; + short textBaseline; } canvas_state_t; class Context2d: public node::ObjectWrap { @@ -65,6 +66,7 @@ class Context2d: public node::ObjectWrap { static Handle SetShadowRGBA(const Arguments &args); static Handle SetFillPattern(const Arguments &args); static Handle SetStrokePattern(const Arguments &args); + static Handle SetTextBaseline(const Arguments &args); static Handle SetTextAlignment(const Arguments &args); static Handle SetTextPath(const Arguments &args); static Handle MeasureText(const Arguments &args);