Browse Source

Added SetTextBaseline()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
0d5b80a284
  1. 30
      src/CanvasRenderingContext2d.cc
  2. 2
      src/CanvasRenderingContext2d.h

30
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<Object> 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<Value>
Context2d::SetTextBaseline(const Arguments &args) {
HandleScope scope;
if (!args[0]->IsInt32()) return Undefined();
Context2d *context = ObjectWrap::Unwrap<Context2d>(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.
*/

2
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<Value> SetShadowRGBA(const Arguments &args);
static Handle<Value> SetFillPattern(const Arguments &args);
static Handle<Value> SetStrokePattern(const Arguments &args);
static Handle<Value> SetTextBaseline(const Arguments &args);
static Handle<Value> SetTextAlignment(const Arguments &args);
static Handle<Value> SetTextPath(const Arguments &args);
static Handle<Value> MeasureText(const Arguments &args);

Loading…
Cancel
Save