From 51835c1224a389e1f3ed3d02beec0bf622089a18 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 2 Oct 2016 09:31:32 +0200 Subject: [PATCH] use native stroke dash for selection area (#3309) * use native stroke dash for selection area * check support at init --- src/canvas.class.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/canvas.class.js b/src/canvas.class.js index 67d0c09e..fcf11b38 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -5,6 +5,7 @@ radiansToDegrees = fabric.util.radiansToDegrees, atan2 = Math.atan2, abs = Math.abs, + supportLineDash = fabric.StaticCanvas.supports('setLineDash'), STROKE_OFFSET = 0.5; @@ -980,20 +981,25 @@ aleft = abs(left), atop = abs(top); - ctx.fillStyle = this.selectionColor; + if (this.selectionColor) { + ctx.fillStyle = this.selectionColor; - ctx.fillRect( - groupSelector.ex - ((left > 0) ? 0 : -left), - groupSelector.ey - ((top > 0) ? 0 : -top), - aleft, - atop - ); + ctx.fillRect( + groupSelector.ex - ((left > 0) ? 0 : -left), + groupSelector.ey - ((top > 0) ? 0 : -top), + aleft, + atop + ); + } + if (!this.selectionLineWidth || !this.selectionBorderColor) { + return; + } ctx.lineWidth = this.selectionLineWidth; ctx.strokeStyle = this.selectionBorderColor; // selection border - if (this.selectionDashArray.length > 1) { + if (this.selectionDashArray.length > 1 && !supportLineDash) { var px = groupSelector.ex + STROKE_OFFSET - ((left > 0) ? 0 : aleft), py = groupSelector.ey + STROKE_OFFSET - ((top > 0) ? 0 : atop); @@ -1009,6 +1015,7 @@ ctx.stroke(); } else { + fabric.Object.prototype._setLineDash.call(this, ctx, this.selectionDashArray); ctx.strokeRect( groupSelector.ex + STROKE_OFFSET - ((left > 0) ? 0 : aleft), groupSelector.ey + STROKE_OFFSET - ((top > 0) ? 0 : atop),