Browse Source

Added measureText()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
b4339f9555
  1. 23
      src/CanvasRenderingContext2d.cc
  2. 1
      src/CanvasRenderingContext2d.h

23
src/CanvasRenderingContext2d.cc

@ -89,6 +89,7 @@ Context2d::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "clearRect", ClearRect);
NODE_SET_PROTOTYPE_METHOD(t, "rect", Rect);
NODE_SET_PROTOTYPE_METHOD(t, "setTextPath", SetTextPath);
NODE_SET_PROTOTYPE_METHOD(t, "measureText", MeasureText);
NODE_SET_PROTOTYPE_METHOD(t, "moveTo", MoveTo);
NODE_SET_PROTOTYPE_METHOD(t, "lineTo", LineTo);
NODE_SET_PROTOTYPE_METHOD(t, "bezierCurveTo", BezierCurveTo);
@ -843,6 +844,28 @@ Context2d::SetFont(const Arguments &args) {
return Undefined();
}
/*
* Return the given text extents.
*/
Handle<Value>
Context2d::MeasureText(const Arguments &args) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->getContext();
String::Utf8Value str(args[0]->ToString());
Local<Object> obj = Object::New();
cairo_text_extents_t te;
cairo_text_extents(ctx, *str, &te);
obj->Set(String::New("width"), Number::New(te.width));
obj->Set(String::New("height"), Number::New(te.height));
return scope.Close(obj);
}
/*
* Set text path at x, y.
*/

1
src/CanvasRenderingContext2d.h

@ -65,6 +65,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> SetFillPattern(const Arguments &args);
static Handle<Value> SetStrokePattern(const Arguments &args);
static Handle<Value> SetTextPath(const Arguments &args);
static Handle<Value> MeasureText(const Arguments &args);
static Handle<Value> BezierCurveTo(const Arguments &args);
static Handle<Value> QuadraticCurveTo(const Arguments &args);
static Handle<Value> LineTo(const Arguments &args);

Loading…
Cancel
Save