mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-04 03:44:45 +00:00
Refactor fill setting into a separate method
This commit is contained in:
parent
ffe45dc702
commit
9e6fc35ffe
7 changed files with 72 additions and 87 deletions
51
dist/all.js
vendored
51
dist/all.js
vendored
|
|
@ -11648,23 +11648,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
|
|||
|
||||
ctx.save();
|
||||
|
||||
var m = this.transformMatrix;
|
||||
if (m && !this.group) {
|
||||
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
|
||||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
|
||||
this._transform(ctx, noTransform);
|
||||
this._setStrokeStyles(ctx);
|
||||
this._setFillStyles(ctx);
|
||||
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
|
||||
var m = this.transformMatrix;
|
||||
if (m && this.group) {
|
||||
ctx.translate(-this.group.width/2, -this.group.height/2);
|
||||
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
|
|
@ -11683,6 +11671,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
|
|||
ctx.restore();
|
||||
},
|
||||
|
||||
_transform: function(ctx, noTransform) {
|
||||
var m = this.transformMatrix;
|
||||
if (m && !this.group) {
|
||||
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
},
|
||||
|
||||
_setStrokeStyles: function(ctx) {
|
||||
if (this.stroke) {
|
||||
ctx.lineWidth = this.strokeWidth;
|
||||
|
|
@ -11695,6 +11693,14 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
|
|||
}
|
||||
},
|
||||
|
||||
_setFillStyles: function(ctx) {
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
|
|
@ -15316,15 +15322,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
// ctx.globalCompositeOperation = this.fillRule;
|
||||
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
|
||||
this._setStrokeStyles(ctx);
|
||||
this._setFillStyles(ctx);
|
||||
this._setShadow(ctx);
|
||||
this.clipTo && fabric.util.clipContext(this, ctx);
|
||||
ctx.beginPath();
|
||||
|
|
@ -18506,11 +18505,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
*/
|
||||
_setTextStyles: function(ctx) {
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
this._setFillStyles(ctx);
|
||||
this._setStrokeStyles(ctx);
|
||||
ctx.textBaseline = 'alphabetic';
|
||||
if (!this.skipTextAlign) {
|
||||
|
|
|
|||
6
dist/all.min.js
vendored
6
dist/all.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/all.min.js.gz
vendored
BIN
dist/all.min.js.gz
vendored
Binary file not shown.
51
dist/all.require.js
vendored
51
dist/all.require.js
vendored
|
|
@ -11648,23 +11648,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
|
|||
|
||||
ctx.save();
|
||||
|
||||
var m = this.transformMatrix;
|
||||
if (m && !this.group) {
|
||||
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
|
||||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
|
||||
this._transform(ctx, noTransform);
|
||||
this._setStrokeStyles(ctx);
|
||||
this._setFillStyles(ctx);
|
||||
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
|
||||
var m = this.transformMatrix;
|
||||
if (m && this.group) {
|
||||
ctx.translate(-this.group.width/2, -this.group.height/2);
|
||||
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
|
|
@ -11683,6 +11671,16 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
|
|||
ctx.restore();
|
||||
},
|
||||
|
||||
_transform: function(ctx, noTransform) {
|
||||
var m = this.transformMatrix;
|
||||
if (m && !this.group) {
|
||||
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
},
|
||||
|
||||
_setStrokeStyles: function(ctx) {
|
||||
if (this.stroke) {
|
||||
ctx.lineWidth = this.strokeWidth;
|
||||
|
|
@ -11695,6 +11693,14 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
|
|||
}
|
||||
},
|
||||
|
||||
_setFillStyles: function(ctx) {
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
|
|
@ -15316,15 +15322,8 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
|
|||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
// ctx.globalCompositeOperation = this.fillRule;
|
||||
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
|
||||
this._setStrokeStyles(ctx);
|
||||
this._setFillStyles(ctx);
|
||||
this._setShadow(ctx);
|
||||
this.clipTo && fabric.util.clipContext(this, ctx);
|
||||
ctx.beginPath();
|
||||
|
|
@ -18506,11 +18505,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
*/
|
||||
_setTextStyles: function(ctx) {
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
this._setFillStyles(ctx);
|
||||
this._setStrokeStyles(ctx);
|
||||
ctx.textBaseline = 'alphabetic';
|
||||
if (!this.skipTextAlign) {
|
||||
|
|
|
|||
|
|
@ -1012,23 +1012,11 @@
|
|||
|
||||
ctx.save();
|
||||
|
||||
var m = this.transformMatrix;
|
||||
if (m && !this.group) {
|
||||
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
|
||||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
|
||||
this._transform(ctx, noTransform);
|
||||
this._setStrokeStyles(ctx);
|
||||
this._setFillStyles(ctx);
|
||||
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
|
||||
var m = this.transformMatrix;
|
||||
if (m && this.group) {
|
||||
ctx.translate(-this.group.width/2, -this.group.height/2);
|
||||
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
|
|
@ -1047,6 +1035,16 @@
|
|||
ctx.restore();
|
||||
},
|
||||
|
||||
_transform: function(ctx, noTransform) {
|
||||
var m = this.transformMatrix;
|
||||
if (m && !this.group) {
|
||||
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
}
|
||||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
},
|
||||
|
||||
_setStrokeStyles: function(ctx) {
|
||||
if (this.stroke) {
|
||||
ctx.lineWidth = this.strokeWidth;
|
||||
|
|
@ -1059,6 +1057,14 @@
|
|||
}
|
||||
},
|
||||
|
||||
_setFillStyles: function(ctx) {
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
|
|
|
|||
|
|
@ -438,15 +438,8 @@
|
|||
if (!noTransform) {
|
||||
this.transform(ctx);
|
||||
}
|
||||
// ctx.globalCompositeOperation = this.fillRule;
|
||||
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
|
||||
this._setStrokeStyles(ctx);
|
||||
this._setFillStyles(ctx);
|
||||
this._setShadow(ctx);
|
||||
this.clipTo && fabric.util.clipContext(this, ctx);
|
||||
ctx.beginPath();
|
||||
|
|
|
|||
|
|
@ -425,11 +425,7 @@
|
|||
* @param {CanvasRenderingContext2D} ctx Context to render on
|
||||
*/
|
||||
_setTextStyles: function(ctx) {
|
||||
if (this.fill) {
|
||||
ctx.fillStyle = this.fill.toLive
|
||||
? this.fill.toLive(ctx)
|
||||
: this.fill;
|
||||
}
|
||||
this._setFillStyles(ctx);
|
||||
this._setStrokeStyles(ctx);
|
||||
ctx.textBaseline = 'alphabetic';
|
||||
if (!this.skipTextAlign) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue