Browse Source

Started FillText() implementation with toy text api

v1.x
Tj Holowaychuk 14 years ago
parent
commit
f8190ba5f7
  1. 1
      lib/canvas.js
  2. 21
      src/CanvasRenderingContext2d.cc

1
lib/canvas.js

@ -434,6 +434,7 @@ Context2d.prototype.__defineSetter__('font', function(val){
var font;
if (font = parseFont(val)) {
this.lastFontString = val;
this.font = font;
}
}
});

21
src/CanvasRenderingContext2d.cc

@ -797,7 +797,26 @@ Context2d::MoveTo(const Arguments &args) {
Handle<Value>
Context2d::FillText(const Arguments &args) {
HandleScope scope;
// Ignore when args are not present
if (!args[0]->IsString()) return Undefined();
if (!args[1]->IsNumber()) return Undefined();
if (!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_select_font_face(ctx, "Helvetica", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(ctx, 20); // TODO: relative
cairo_move_to(ctx, x, y);
cairo_show_text(ctx, *str);
return Undefined();
}

Loading…
Cancel
Save