Merge pull request #2432 from yurydelendik/setDash

Using setListDash for dashed lines
This commit is contained in:
Yury Delendik 2012-12-04 13:58:48 -08:00
commit 859aad138c
2 changed files with 16 additions and 8 deletions

View File

@ -415,10 +415,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.ctx.miterLimit = limit; this.ctx.miterLimit = limit;
}, },
setDash: function CanvasGraphics_setDash(dashArray, dashPhase) { setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
this.ctx.mozDash = dashArray; var ctx = this.ctx;
this.ctx.mozDashOffset = dashPhase; if ('setLineDash' in ctx) {
this.ctx.webkitLineDash = dashArray; ctx.setLineDash(dashArray);
this.ctx.webkitLineDashOffset = dashPhase; ctx.lineDashOffset = dashPhase;
} else {
ctx.mozDash = dashArray;
ctx.mozDashOffset = dashPhase;
}
}, },
setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) { setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
// Maybe if we one day fully support color spaces this will be important // Maybe if we one day fully support color spaces this will be important

View File

@ -391,10 +391,14 @@ var tests = [
ctx.moveTo(0,5); ctx.moveTo(0,5);
ctx.lineTo(50, 5); ctx.lineTo(50, 5);
ctx.lineWidth = 10; ctx.lineWidth = 10;
ctx.mozDash = [10, 10];
ctx.mozDashOffset = 0; if ('setLineDash' in ctx) {
ctx.webkitLineDash = [10, 10]; ctx.setLineDash([10, 10]);
ctx.webkitLineDashOffset = 0; ctx.lineDashOffset = 0;
} else {
ctx.mozDash = [10, 10];
ctx.mozDashOffset = 0;
}
ctx.stroke(); ctx.stroke();
var data = ctx.getImageData(0, 0, 50, 50).data; var data = ctx.getImageData(0, 0, 50, 50).data;