Browse Source

Added SET_SOURCE_RGBA

v1.x
Tj Holowaychuk 15 years ago
parent
commit
a65f24b2d6
  1. 29
      src/context2d.cc
  2. 23
      test/canvas.test.js

29
src/context2d.cc

@ -22,6 +22,17 @@ using namespace node;
_.b = B; \
_.a = A; \
/*
* Set source RGBA.
*/
#define SET_SOURCE_RGBA(C) \
cairo_set_source_rgba(ctx \
, C.r \
, C.g \
, C.b \
, C.a);
/*
* Rectangle arg assertions.
*/
@ -211,13 +222,8 @@ Context2d::Fill(const Arguments &args) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->getContext();
cairo_set_source_rgba(
ctx
, context->fill.r
, context->fill.g
, context->fill.b
, context->fill.a);
cairo_fill(ctx);
SET_SOURCE_RGBA(context->fill);
cairo_fill_preserve(ctx);
return Undefined();
}
@ -230,13 +236,8 @@ Context2d::Stroke(const Arguments &args) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->getContext();
cairo_set_source_rgba(
ctx
, context->stroke.r
, context->stroke.g
, context->stroke.b
, context->stroke.a);
cairo_stroke(ctx);
SET_SOURCE_RGBA(context->stroke);
cairo_stroke_preserve(ctx);
return Undefined();
}

23
test/canvas.test.js

@ -171,6 +171,29 @@ module.exports = {
, 'Canvas#bezierCurveTo() failed');
},
'test fill with stroke': function(assert){
var canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d')
, path = __dirname + '/fillWithStroke.png';
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true);
ctx.fill();
ctx.closePath();
ctx.beginPath();
ctx.fillStyle = 'red';
ctx.strokeStyle = 'yellow';
ctx.arc(75,75,30,0,Math.PI*2,true);
ctx.fill();
ctx.stroke();
assertChecksum(
canvas
, path
, '0437605377cc9840c58cb166fb0b89d4'
, 'fill with stroke failed');
},
'test Canvas#fillStyle=': function(assert){
var canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d')

Loading…
Cancel
Save