Browse Source

Started SetFont()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
e0aca54c57
  1. 8
      lib/canvas.js
  2. 30
      src/CanvasRenderingContext2d.cc
  3. 2
      src/CanvasRenderingContext2d.h

8
lib/canvas.js

@ -430,11 +430,17 @@ Context2d.prototype.__defineSetter__('shadowColor', function(val){
Context2d.prototype.__defineGetter__('shadowColor', normalizedColor('lastShadowColor'));
Context2d.prototype.__defineSetter__('font', function(val){
console.log(val);
if ('string' == typeof val) {
var font;
if (font = parseFont(val)) {
this.lastFontString = val;
this.font = font;
this.setFont(
font.weight
, font.style
, font.size
, font.unit
, font.family);
}
}
});

30
src/CanvasRenderingContext2d.cc

@ -96,6 +96,7 @@ Context2d::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "beginPath", BeginPath);
NODE_SET_PROTOTYPE_METHOD(t, "closePath", ClosePath);
NODE_SET_PROTOTYPE_METHOD(t, "arc", Arc);
NODE_SET_PROTOTYPE_METHOD(t, "setFont", SetFont);
NODE_SET_PROTOTYPE_METHOD(t, "setShadowRGBA", SetShadowRGBA);
NODE_SET_PROTOTYPE_METHOD(t, "setFillRGBA", SetFillRGBA);
NODE_SET_PROTOTYPE_METHOD(t, "setStrokeRGBA", SetStrokeRGBA);
@ -791,6 +792,35 @@ Context2d::MoveTo(const Arguments &args) {
return Undefined();
}
/*
* Set font:
* - weight
* - style
* - size
* - unit
* - family
*/
Handle<Value>
Context2d::SetFont(const Arguments &args) {
HandleScope scope;
// TODO: optimize; match cairo constants
String::AsciiValue weight(args[0]);
String::AsciiValue style(args[1]);
double size = args[2]->NumberValue();
String::AsciiValue unit(args[3]);
String::AsciiValue family(args[4]);
printf("weight: %s\n", *weight);
printf("style: %s\n", *style);
printf("size: %d\n", (int) size);
printf("unit: %s\n", *unit);
printf("family: %s\n", *family);
return Undefined();
}
/*
* Fill text at x, y.
*/

2
src/CanvasRenderingContext2d.h

@ -58,7 +58,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> Clip(const Arguments &args);
static Handle<Value> Fill(const Arguments &args);
static Handle<Value> Stroke(const Arguments &args);
static Handle<Value> SetSource(const Arguments &args);
static Handle<Value> SetFont(const Arguments &args);
static Handle<Value> SetFillRGBA(const Arguments &args);
static Handle<Value> SetStrokeRGBA(const Arguments &args);
static Handle<Value> SetShadowRGBA(const Arguments &args);

Loading…
Cancel
Save