diff --git a/src/context2d.cc b/src/context2d.cc index e3e7e37..f2bbb80 100644 --- a/src/context2d.cc +++ b/src/context2d.cc @@ -262,8 +262,11 @@ Context2d::GetLineWidth(Local prop, const AccessorInfo &info) { void Context2d::SetLineWidth(Local prop, Local val, const AccessorInfo &info) { - Context2d *context = ObjectWrap::Unwrap(info.This()); - cairo_set_line_width(context->getContext(), val->NumberValue()); + double n = val->NumberValue(); + if (n > 0) { + Context2d *context = ObjectWrap::Unwrap(info.This()); + cairo_set_line_width(context->getContext(), n); + } } /* diff --git a/test/canvas.test.js b/test/canvas.test.js index 346f352..0804507 100644 --- a/test/canvas.test.js +++ b/test/canvas.test.js @@ -260,6 +260,12 @@ module.exports = { ctx.beginPath(); ctx.lineWidth = 10.0; assert.equal(10, ctx.lineWidth); + // ctx.lineWidth = Infinity; + assert.equal(10, ctx.lineWidth); + ctx.lineWidth = -5; + assert.equal(10, ctx.lineWidth); + ctx.lineWidth = 0; + assert.equal(10, ctx.lineWidth); ctx.moveTo(50, 50); ctx.lineTo(50, 100); ctx.lineTo(80, 120);