Browse files

Merge pull request #2432 from yurydelendik/setDash

Using setListDash for dashed lines
  • Loading branch information...
2 parents 85591aa + a7f0e96 commit 859aad138c0aae7ffb8a721855caf7117abf80c0 @yurydelendik yurydelendik committed Dec 4, 2012
Showing with 16 additions and 8 deletions.
  1. +8 −4 src/canvas.js
  2. +8 −4 test/features/tests.js
View
12 src/canvas.js
@@ -415,10 +415,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
View
12 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;

0 comments on commit 859aad1

Please sign in to comment.