Browse Source

Fixed fillText() fillStroke(), added SetTextPath()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
b93c406b96
  1. 24
      lib/canvas.js
  2. 34
      src/CanvasRenderingContext2d.cc
  3. 3
      src/CanvasRenderingContext2d.h

24
lib/canvas.js

@ -339,21 +339,35 @@ Context2d.prototype.setTransform = function(){
};
/**
* Set text path then `stroke()`.
* Stroke `text` at (`x`, `y`).
*
* @param {String} str
* @param {String} text
* @param {Number} x
* @param {Number} y
* @api public
*/
var strokeText = Context2d.prototype.strokeText;
Context2d.prototype.strokeText = function(str, x, y){
Context2d.prototype.strokeText = function(text, x, y){
this.beginPath();
strokeText.call(this, str, x, y);
this.setTextPath(text, x, y);
return this.stroke();
};
/**
* Fill `text` at (`x`, `y`).
*
* @param {String} text
* @param {Number} x
* @param {Number} y
* @api public
*/
Context2d.prototype.fillText = function(text, x, y){
this.beginPath();
this.setTextPath(text, x, y);
return this.fill();
};
/**
* Set the fill style with the given css color string.
*

34
src/CanvasRenderingContext2d.cc

@ -88,8 +88,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, "strokeText", StrokeText);
NODE_SET_PROTOTYPE_METHOD(t, "fillText", FillText);
NODE_SET_PROTOTYPE_METHOD(t, "setTextPath", SetTextPath);
NODE_SET_PROTOTYPE_METHOD(t, "moveTo", MoveTo);
NODE_SET_PROTOTYPE_METHOD(t, "lineTo", LineTo);
NODE_SET_PROTOTYPE_METHOD(t, "bezierCurveTo", BezierCurveTo);
@ -845,11 +844,11 @@ Context2d::SetFont(const Arguments &args) {
}
/*
* Stroke text at x, y.
* Set text path at x, y.
*/
Handle<Value>
Context2d::StrokeText(const Arguments &args) {
Context2d::SetTextPath(const Arguments &args) {
HandleScope scope;
// Ignore when args are not present
@ -871,33 +870,6 @@ Context2d::StrokeText(const Arguments &args) {
return Undefined();
}
/*
* Fill text at x, y.
*/
Handle<Value>
Context2d::FillText(const Arguments &args) {
HandleScope scope;
// Ignore when args are not present
if (!args[0]->IsString()
|| !args[1]->IsNumber()
|| !args[2]->IsNumber()) return Undefined();
String::Utf8Value str(args[0]);
double x = args[1]->NumberValue()
, y = args[2]->NumberValue();
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->getContext();
cairo_text_extents_t te;
cairo_move_to(ctx, x, y);
cairo_show_text(ctx, *str);
return Undefined();
}
/*
* Fill the rectangle defined by x, y, width and height.
*/

3
src/CanvasRenderingContext2d.h

@ -64,8 +64,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> StrokeText(const Arguments &args);
static Handle<Value> FillText(const Arguments &args);
static Handle<Value> SetTextPath(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