I found what seems like an even better solution, works great with SVG tracks.
You can override the fabricjs _renderStroke method and add ctx.scale(1 / this.scaleX, 1 / this.scaleY); to ctx.stroke(); as shown below.
fabric.Object.prototype._renderStroke = function(ctx) { if (!this.stroke || this.strokeWidth === 0) { return; } if (this.shadow && !this.shadow.affectStroke) { this._removeShadow(ctx); } ctx.save(); ctx.scale(1 / this.scaleX, 1 / this.scaleY); this._setLineDash(ctx, this.strokeDashArray, this._renderDashedStroke); this._applyPatternGradientTransform(ctx, this.stroke); ctx.stroke(); ctx.restore(); };
You may also need to override fabric.Object.prototype._getTransformedDimensions to adjust the bounding box to account for the difference in size.
In addition, a more complete implementation is likely to add an object-object property to conditionally control this change for both overridden methods.
byoungb
source share