From f8e6ae946114c6ba22ef3dc2f52ff4a198361274 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Fri, 26 Sep 2014 00:29:59 +0200 Subject: [PATCH] Update parser.js Allow first example of stroke svg import to work properly --- src/parser.js | 2 +- src/shapes/object.class.js | 24 ++++++------------------ src/shapes/path.class.js | 13 ++++++++----- src/shapes/text.class.js | 11 ++++++----- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/parser.js b/src/parser.js index 19eef366..2aad4288 100644 --- a/src/parser.js +++ b/src/parser.js @@ -65,7 +65,7 @@ } else if (attr === 'strokeDashArray') { value = value.replace(/,/g, ' ').split(/\s+/).map(function(n) { - return parseInt(n); + return parseFloat(n); }); } else if (attr === 'transformMatrix') { diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index baca2e25..e743909e 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -971,16 +971,16 @@ //setup fill rule for current object this._setupCompositeOperation(ctx); - - this._transform(ctx, noTransform); + if (!noTransform) { + this.transform(ctx); + } this._setStrokeStyles(ctx); this._setFillStyles(ctx); - if (this.group && this.group.type === 'path-group') { ctx.translate(-this.group.width/2, -this.group.height/2); - if (this.transformMatrix) { - ctx.transform.apply(ctx, this.transformMatrix); - } + } + if (this.transformMatrix) { + ctx.transform.apply(ctx, this.transformMatrix); } this._setOpacity(ctx); this._setShadow(ctx); @@ -993,17 +993,6 @@ ctx.restore(); }, - _transform: function(ctx, noTransform) { - var m = this.transformMatrix; - - if (m && !this.group) { - ctx.setTransform.apply(ctx, m); - } - if (!noTransform) { - this.transform(ctx); - } - }, - /* @private * @param {CanvasRenderingContext2D} ctx Context to render on */ @@ -1137,7 +1126,6 @@ if (1 & this.strokeDashArray.length) { this.strokeDashArray.push.apply(this.strokeDashArray, this.strokeDashArray); } - if (supportsLineDash) { ctx.setLineDash(this.strokeDashArray); this._stroke && this._stroke(ctx); diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index 88e637fb..7b28e6ac 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -420,29 +420,32 @@ */ render: function(ctx, noTransform) { // do not render if width/height are zeros or object is not visible - if (this.width === 0 || this.height === 0 || !this.visible) { + if (!this.visible) { return; } ctx.save(); + this._setupCompositeOperation(ctx); if (!noTransform) { this.transform(ctx); } + this._setStrokeStyles(ctx); + this._setFillStyles(ctx); if (this.group && this.group.type === 'path-group') { - ctx.translate(-this.group.width/2, -this.group.height/2); + ctx.translate(-this.group.width / 2, -this.group.height / 2); } if (this.transformMatrix) { ctx.transform.apply(ctx, this.transformMatrix); } - this._setStrokeStyles(ctx); - this._setFillStyles(ctx); + this._setOpacity(ctx); this._setShadow(ctx); this.clipTo && fabric.util.clipContext(this, ctx); - ctx.globalAlpha = this.group ? (ctx.globalAlpha * this.opacity) : this.opacity; this._render(ctx, noTransform); this.clipTo && ctx.restore(); this._removeShadow(ctx); + this._restoreCompositeOperation(ctx); + ctx.restore(); }, diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index 84b8812b..5c20599f 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -771,16 +771,17 @@ } ctx.save(); - this._transform(ctx, noTransform); + if (!noTransform) { + this.transform(ctx); + } - var m = this.transformMatrix, - isInPathGroup = this.group && this.group.type === 'path-group'; + var isInPathGroup = this.group && this.group.type === 'path-group'; if (isInPathGroup) { ctx.translate(-this.group.width/2, -this.group.height/2); } - if (m) { - ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]); + if (this.transformMatrix) { + ctx.transform.apply(ctx, this.transformMatrix); } if (isInPathGroup) { ctx.translate(this.left, this.top);