From ad2fcf303fa7b407f2dbe77269f2f451b2cc8ca9 Mon Sep 17 00:00:00 2001 From: Riley Gowan Date: Tue, 9 Mar 2021 20:24:37 -0800 Subject: [PATCH 1/3] Cache object properties cropX and cropY --- src/shapes/object.class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 2f6f76af7b3..6a3aeaef81e 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -604,7 +604,7 @@ */ cacheProperties: ( 'fill stroke strokeWidth strokeDashArray width height paintFirst strokeUniform' + - ' strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath' + ' strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath cropX cropY' ).split(' '), /** From e6f2b816820f4f42232a52623b500ac85e72c867 Mon Sep 17 00:00:00 2001 From: Riley Gowan Date: Tue, 9 Mar 2021 20:47:30 -0800 Subject: [PATCH 2/3] Update text test --- test/unit/text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/text.js b/test/unit/text.js index aee6bf2baf3..fc5dfd70d87 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -866,7 +866,7 @@ QUnit.test('cacheProperties for text', function(assert) { var text = new fabric.Text('a'); - assert.equal(text.cacheProperties.join('-'), 'fill-stroke-strokeWidth-strokeDashArray-width-height-paintFirst-strokeUniform-strokeLineCap-strokeDashOffset-strokeLineJoin-strokeMiterLimit-backgroundColor-clipPath-fontFamily-fontWeight-fontSize-text-underline-overline-linethrough-textAlign-fontStyle-lineHeight-textBackgroundColor-charSpacing-styles-path'); + assert.equal(text.cacheProperties.join('-'), 'fill-stroke-strokeWidth-strokeDashArray-width-height-paintFirst-strokeUniform-strokeLineCap-strokeDashOffset-strokeLineJoin-strokeMiterLimit-backgroundColor-clipPath-cropX-cropY-fontFamily-fontWeight-fontSize-text-underline-overline-linethrough-textAlign-fontStyle-lineHeight-textBackgroundColor-charSpacing-styles-path'); }); })(); From 5aae31ecc544a69eab6475a4dc105a29938a96cc Mon Sep 17 00:00:00 2001 From: Riley Gowan Date: Wed, 10 Mar 2021 11:08:34 -0800 Subject: [PATCH 3/3] Move cacheProperties to image.class --- src/shapes/image.class.js | 9 +++++++++ src/shapes/object.class.js | 2 +- test/unit/text.js | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/shapes/image.class.js b/src/shapes/image.class.js index 9509fc3d38b..13b50811472 100644 --- a/src/shapes/image.class.js +++ b/src/shapes/image.class.js @@ -92,6 +92,15 @@ */ stateProperties: fabric.Object.prototype.stateProperties.concat('cropX', 'cropY'), + /** + * List of properties to consider when checking if cache needs refresh + * Those properties are checked by statefullCache ON ( or lazy mode if we want ) or from single + * calls to Object.set(key, value). If the key is in this list, the object is marked as dirty + * and refreshed at the next render + * @type Array + */ + cacheProperties: fabric.Object.prototype.cacheProperties.concat('cropX', 'cropY'), + /** * key used to retrieve the texture representing this image * @since 2.0.0 diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 6a3aeaef81e..2f6f76af7b3 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -604,7 +604,7 @@ */ cacheProperties: ( 'fill stroke strokeWidth strokeDashArray width height paintFirst strokeUniform' + - ' strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath cropX cropY' + ' strokeLineCap strokeDashOffset strokeLineJoin strokeMiterLimit backgroundColor clipPath' ).split(' '), /** diff --git a/test/unit/text.js b/test/unit/text.js index fc5dfd70d87..aee6bf2baf3 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -866,7 +866,7 @@ QUnit.test('cacheProperties for text', function(assert) { var text = new fabric.Text('a'); - assert.equal(text.cacheProperties.join('-'), 'fill-stroke-strokeWidth-strokeDashArray-width-height-paintFirst-strokeUniform-strokeLineCap-strokeDashOffset-strokeLineJoin-strokeMiterLimit-backgroundColor-clipPath-cropX-cropY-fontFamily-fontWeight-fontSize-text-underline-overline-linethrough-textAlign-fontStyle-lineHeight-textBackgroundColor-charSpacing-styles-path'); + assert.equal(text.cacheProperties.join('-'), 'fill-stroke-strokeWidth-strokeDashArray-width-height-paintFirst-strokeUniform-strokeLineCap-strokeDashOffset-strokeLineJoin-strokeMiterLimit-backgroundColor-clipPath-fontFamily-fontWeight-fontSize-text-underline-overline-linethrough-textAlign-fontStyle-lineHeight-textBackgroundColor-charSpacing-styles-path'); }); })();