mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-21 03:41:52 +00:00
Add fabric.IText#caching
This commit is contained in:
parent
435f3933ac
commit
0f23f14a44
6 changed files with 75 additions and 18 deletions
29
dist/all.js
vendored
29
dist/all.js
vendored
|
|
@ -17721,7 +17721,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {Array} textLines Array of all text lines
|
||||
*/
|
||||
_renderTextFill: function(ctx, textLines) {
|
||||
if (!this.fill && !this.skipFillStrokeCheck) return;
|
||||
if (!this.fill && !this._skipFillStrokeCheck) return;
|
||||
|
||||
this._boundaries = [ ];
|
||||
var lineHeights = 0;
|
||||
|
|
@ -17747,7 +17747,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {Array} textLines Array of all text lines
|
||||
*/
|
||||
_renderTextStroke: function(ctx, textLines) {
|
||||
if (!this.stroke && !this.skipFillStrokeCheck) return;
|
||||
if (!this.stroke && !this._skipFillStrokeCheck) return;
|
||||
|
||||
var lineHeights = 0;
|
||||
|
||||
|
|
@ -18395,7 +18395,19 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
*/
|
||||
styles: null,
|
||||
|
||||
skipFillStrokeCheck: true,
|
||||
/**
|
||||
* Indicates whether internal text char widths can be cached
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
caching: true,
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
_skipFillStrokeCheck: true,
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
|
@ -19050,7 +19062,9 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {Object} [decl]
|
||||
*/
|
||||
_applyCharStylesGetWidth: function(ctx, _char, lineIndex, charIndex, decl) {
|
||||
var styleDeclaration = decl || (this.styles[lineIndex] && this.styles[lineIndex][charIndex]);
|
||||
var styleDeclaration = decl ||
|
||||
(this.styles[lineIndex] &&
|
||||
this.styles[lineIndex][charIndex]);
|
||||
|
||||
if (styleDeclaration) {
|
||||
// cloning so that original style object is not polluted with following font declarations
|
||||
|
|
@ -19065,7 +19079,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
var cacheProp = this._getCacheProp(_char, styleDeclaration);
|
||||
|
||||
// short-circuit if no styles
|
||||
if (this.isEmptyStyles() && this._charWidthsCache[cacheProp]) {
|
||||
if (this.isEmptyStyles() && this._charWidthsCache[cacheProp] && this.caching) {
|
||||
return this._charWidthsCache[cacheProp];
|
||||
}
|
||||
|
||||
|
|
@ -19088,9 +19102,14 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
ctx.font = this._getFontDeclaration.call(styleDeclaration);
|
||||
this._setShadow.call(styleDeclaration, ctx);
|
||||
|
||||
if (!this.caching) {
|
||||
return ctx.measureText(_char).width;
|
||||
}
|
||||
|
||||
if (!this._charWidthsCache[cacheProp]) {
|
||||
this._charWidthsCache[cacheProp] = ctx.measureText(_char).width;
|
||||
}
|
||||
|
||||
return this._charWidthsCache[cacheProp];
|
||||
},
|
||||
|
||||
|
|
|
|||
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.
29
dist/all.require.js
vendored
29
dist/all.require.js
vendored
|
|
@ -17721,7 +17721,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {Array} textLines Array of all text lines
|
||||
*/
|
||||
_renderTextFill: function(ctx, textLines) {
|
||||
if (!this.fill && !this.skipFillStrokeCheck) return;
|
||||
if (!this.fill && !this._skipFillStrokeCheck) return;
|
||||
|
||||
this._boundaries = [ ];
|
||||
var lineHeights = 0;
|
||||
|
|
@ -17747,7 +17747,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {Array} textLines Array of all text lines
|
||||
*/
|
||||
_renderTextStroke: function(ctx, textLines) {
|
||||
if (!this.stroke && !this.skipFillStrokeCheck) return;
|
||||
if (!this.stroke && !this._skipFillStrokeCheck) return;
|
||||
|
||||
var lineHeights = 0;
|
||||
|
||||
|
|
@ -18395,7 +18395,19 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
*/
|
||||
styles: null,
|
||||
|
||||
skipFillStrokeCheck: true,
|
||||
/**
|
||||
* Indicates whether internal text char widths can be cached
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
caching: true,
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
_skipFillStrokeCheck: true,
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
|
@ -19050,7 +19062,9 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
* @param {Object} [decl]
|
||||
*/
|
||||
_applyCharStylesGetWidth: function(ctx, _char, lineIndex, charIndex, decl) {
|
||||
var styleDeclaration = decl || (this.styles[lineIndex] && this.styles[lineIndex][charIndex]);
|
||||
var styleDeclaration = decl ||
|
||||
(this.styles[lineIndex] &&
|
||||
this.styles[lineIndex][charIndex]);
|
||||
|
||||
if (styleDeclaration) {
|
||||
// cloning so that original style object is not polluted with following font declarations
|
||||
|
|
@ -19065,7 +19079,7 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
var cacheProp = this._getCacheProp(_char, styleDeclaration);
|
||||
|
||||
// short-circuit if no styles
|
||||
if (this.isEmptyStyles() && this._charWidthsCache[cacheProp]) {
|
||||
if (this.isEmptyStyles() && this._charWidthsCache[cacheProp] && this.caching) {
|
||||
return this._charWidthsCache[cacheProp];
|
||||
}
|
||||
|
||||
|
|
@ -19088,9 +19102,14 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
|
|||
ctx.font = this._getFontDeclaration.call(styleDeclaration);
|
||||
this._setShadow.call(styleDeclaration, ctx);
|
||||
|
||||
if (!this.caching) {
|
||||
return ctx.measureText(_char).width;
|
||||
}
|
||||
|
||||
if (!this._charWidthsCache[cacheProp]) {
|
||||
this._charWidthsCache[cacheProp] = ctx.measureText(_char).width;
|
||||
}
|
||||
|
||||
return this._charWidthsCache[cacheProp];
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,19 @@
|
|||
*/
|
||||
styles: null,
|
||||
|
||||
skipFillStrokeCheck: true,
|
||||
/**
|
||||
* Indicates whether internal text char widths can be cached
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
caching: true,
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
_skipFillStrokeCheck: true,
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
|
@ -786,7 +798,9 @@
|
|||
* @param {Object} [decl]
|
||||
*/
|
||||
_applyCharStylesGetWidth: function(ctx, _char, lineIndex, charIndex, decl) {
|
||||
var styleDeclaration = decl || (this.styles[lineIndex] && this.styles[lineIndex][charIndex]);
|
||||
var styleDeclaration = decl ||
|
||||
(this.styles[lineIndex] &&
|
||||
this.styles[lineIndex][charIndex]);
|
||||
|
||||
if (styleDeclaration) {
|
||||
// cloning so that original style object is not polluted with following font declarations
|
||||
|
|
@ -801,7 +815,7 @@
|
|||
var cacheProp = this._getCacheProp(_char, styleDeclaration);
|
||||
|
||||
// short-circuit if no styles
|
||||
if (this.isEmptyStyles() && this._charWidthsCache[cacheProp]) {
|
||||
if (this.isEmptyStyles() && this._charWidthsCache[cacheProp] && this.caching) {
|
||||
return this._charWidthsCache[cacheProp];
|
||||
}
|
||||
|
||||
|
|
@ -824,9 +838,14 @@
|
|||
ctx.font = this._getFontDeclaration.call(styleDeclaration);
|
||||
this._setShadow.call(styleDeclaration, ctx);
|
||||
|
||||
if (!this.caching) {
|
||||
return ctx.measureText(_char).width;
|
||||
}
|
||||
|
||||
if (!this._charWidthsCache[cacheProp]) {
|
||||
this._charWidthsCache[cacheProp] = ctx.measureText(_char).width;
|
||||
}
|
||||
|
||||
return this._charWidthsCache[cacheProp];
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@
|
|||
* @param {Array} textLines Array of all text lines
|
||||
*/
|
||||
_renderTextFill: function(ctx, textLines) {
|
||||
if (!this.fill && !this.skipFillStrokeCheck) return;
|
||||
if (!this.fill && !this._skipFillStrokeCheck) return;
|
||||
|
||||
this._boundaries = [ ];
|
||||
var lineHeights = 0;
|
||||
|
|
@ -585,7 +585,7 @@
|
|||
* @param {Array} textLines Array of all text lines
|
||||
*/
|
||||
_renderTextStroke: function(ctx, textLines) {
|
||||
if (!this.stroke && !this.skipFillStrokeCheck) return;
|
||||
if (!this.stroke && !this._skipFillStrokeCheck) return;
|
||||
|
||||
var lineHeights = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue