From a7f0e9612a82905164a1d2d10ef63055e6b25198 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Tue, 4 Dec 2012 08:26:10 -0600 Subject: [PATCH] Using setDash for dashed lines --- src/canvas.js | 12 ++++++++---- test/features/tests.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/canvas.js b/src/canvas.js index 40cfac6dc..b485ad95c 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -361,10 +361,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.ctx.miterLimit = limit; }, setDash: function CanvasGraphics_setDash(dashArray, dashPhase) { - this.ctx.mozDash = dashArray; - this.ctx.mozDashOffset = dashPhase; - this.ctx.webkitLineDash = dashArray; - this.ctx.webkitLineDashOffset = dashPhase; + var ctx = this.ctx; + if ('setLineDash' in ctx) { + ctx.setLineDash(dashArray); + ctx.lineDashOffset = dashPhase; + } else { + ctx.mozDash = dashArray; + ctx.mozDashOffset = dashPhase; + } }, setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) { // Maybe if we one day fully support color spaces this will be important diff --git a/test/features/tests.js b/test/features/tests.js index a9ea38c33..1b246dd5f 100644 --- a/test/features/tests.js +++ b/test/features/tests.js @@ -391,10 +391,14 @@ var tests = [ ctx.moveTo(0,5); ctx.lineTo(50, 5); ctx.lineWidth = 10; - ctx.mozDash = [10, 10]; - ctx.mozDashOffset = 0; - ctx.webkitLineDash = [10, 10]; - ctx.webkitLineDashOffset = 0; + + if ('setLineDash' in ctx) { + ctx.setLineDash([10, 10]); + ctx.lineDashOffset = 0; + } else { + ctx.mozDash = [10, 10]; + ctx.mozDashOffset = 0; + } ctx.stroke(); var data = ctx.getImageData(0, 0, 50, 50).data;