Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image stroke #2926

Merged
merged 4 commits into from
May 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,17 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_stroke: function(ctx) {
ctx.save();
this._setStrokeStyles(ctx);
if (!this.stroke || this.strokeWidth === 0) {
return;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_stroke is called by the _render function, _setStrokeStyle has been already done.

}
var w = this.width / 2, h = this.height / 2;
ctx.beginPath();
ctx.strokeRect(-this.width / 2, -this.height / 2, this.width, this.height);
ctx.moveTo(-w, -h);
ctx.lineTo(w, -h);
ctx.lineTo(w, h);
ctx.lineTo(-w, h);
ctx.lineTo(-w, -h);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an un-optimization, but in my opinion it simplify the rendering flow for the dev.

ctx.closePath();
ctx.restore();
},

/**
Expand Down Expand Up @@ -410,6 +415,7 @@
imageMargins.height
);

this._stroke(ctx);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image class is the only one with the internal _stroke method. We can call it directly from its render method

this._renderStroke(ctx);
},

Expand Down
17 changes: 9 additions & 8 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,20 +1185,21 @@
}
if (supportsLineDash) {
ctx.setLineDash(this.strokeDashArray);
this._stroke && this._stroke(ctx);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been done by the _render itselft

else {
this._renderDashedStroke && this._renderDashedStroke(ctx);
}
ctx.stroke();
}
else {
if (this.stroke.gradientTransform) {
var g = this.stroke.gradientTransform;
ctx.transform.apply(ctx, g);
}
this._stroke ? this._stroke(ctx) : ctx.stroke();
if (this.stroke.gradientTransform) {
var g = this.stroke.gradientTransform;
ctx.transform.apply(ctx, g);
}
if (this.stroke.toLive) {
ctx.translate(
-this.width / 2 + this.stroke.offsetX || 0,
-this.height / 2 + this.stroke.offsetY || 0);
}
ctx.stroke();
Copy link
Member Author

@asturur asturur May 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we have to stroke anyway, so out of the IF

ctx.restore();
},

Expand Down