From fb95c0bf253561b941d310c620e8e1d1a1f08667 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 5 Oct 2010 11:15:36 -0700 Subject: [PATCH] Fixed lineWidth setter, ignores <= 0 --- src/context2d.cc | 7 +++++-- test/canvas.test.js | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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);