From afe1aa6028027670980d266098ff8f09c22bab35 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Thu, 14 Nov 2019 01:37:46 +0100 Subject: [PATCH] ISSUE-5952 fix toCanvasElement of objects in group (#5962) * fix toCanvasElement of objects in group * added test * lint --- src/shapes/object.class.js | 7 ++++++- test/visual/generic_rendering.js | 18 ++++++++++++++++++ .../golden/objectsInActiveSelections.png | Bin 0 -> 1287 bytes 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/visual/golden/objectsInActiveSelections.png diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 1dc0a53a45d..97324b3a93e 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1712,9 +1712,10 @@ options || (options = { }); var utils = fabric.util, origParams = utils.saveObjectTransform(this), + originalGroup = this.group, originalShadow = this.shadow, abs = Math.abs, multiplier = (options.multiplier || 1) * (options.enableRetinaScaling ? fabric.devicePixelRatio : 1); - + delete this.group; if (options.withoutTransform) { utils.resetObjectTransform(this); } @@ -1736,6 +1737,7 @@ else { scaling = this.getObjectScaling(); } + // consider non scaling shadow. shadowOffset.x = 2 * Math.round(abs(shadow.offsetX) + shadowBlur) * (abs(scaling.scaleX)); shadowOffset.y = 2 * Math.round(abs(shadow.offsetY) + shadowBlur) * (abs(scaling.scaleY)); } @@ -1758,6 +1760,9 @@ var canvasEl = canvas.toCanvasElement(multiplier || 1, options); this.shadow = originalShadow; this.canvas = originalCanvas; + if (originalGroup) { + this.group = originalGroup; + } this.set(origParams).setCoords(); // canvas.dispose will call image.dispose that will nullify the elements // since this canvas is a simple element for the process, we remove references diff --git a/test/visual/generic_rendering.js b/test/visual/generic_rendering.js index b8c5b9f2bd9..309a47b669f 100644 --- a/test/visual/generic_rendering.js +++ b/test/visual/generic_rendering.js @@ -242,5 +242,23 @@ height: 300, }); + function objectsInActiveSelections(canvas, callback) { + canvas.setZoom(0.1); + var rect1 = new fabric.Rect({ fill: 'purple', top: 30, left: 50, width: 30, height: 100, angle: 10 }); + var rect2 = new fabric.Rect({ fill: 'green', top: 150, left: 10, width: 300, height: 30, angle: -10 }); + new fabric.ActiveSelection([rect1, rect2]); + var output = rect1.toCanvasElement(); + callback(output); + } + + tests.push({ + test: 'objects in activeSelection toCanvasElement', + code: objectsInActiveSelections, + golden: 'objectsInActiveSelections.png', + percentage: 0.09, + width: 300, + height: 300, + }); + tests.forEach(visualTestLoop(QUnit)); })(); diff --git a/test/visual/golden/objectsInActiveSelections.png b/test/visual/golden/objectsInActiveSelections.png new file mode 100644 index 0000000000000000000000000000000000000000..d4f5abc1714c1544ed10cb5ba8ba4334b7cad1a1 GIT binary patch literal 1287 zcmV+i1^D`jP)*A$zKR~}hK11gN0t5)q zf^e5?H}xBI%cm$hbnevQfTBf<0HT5Wv-p5OraG8(XrF9RqLP=s{s0cvoh3fvOY;5E zlrnmdLVW{#3w&lU8qk2QsPvMh9x*Bu%JgxqZ4G-m&)2|r!1J8^1}Lx)0|pw<3bh6+ zDT|U)zv0bw?1i(~6DU*;`~Z9puE2%47fb z+!pU(euoFd2Y@-C4W@8mc*&)H%iHD00vLDv?g{XvExvB>T4lgMPnqf|(~VZV<@WDr z0E3z2!4y#d z=bWG9&C6D~RjF z(f~lm5V9slst@RjY7Nk}1wu^B$5L+qQaMmDWLUTlhX$|!<_dM=4jdZ5MhAwD00tx0 zfr$kWHZjGLW#J!a4UmF~@ei~H$jL%hfd+VTe+6$1XiSe};V8B3h1lna{d^G_` zO<;EhGY{F8+0+M;O(C381!$asopu5!)G@0RA~_S|YhMc_okBS61Q1*Yg%$uiw;BkW z7(HVaw0}Cq5DLEg@K6C>@#={+@{jteRSN~B5KgrKC!9!Spa6QwGCG7LO^hBf3Yx?q zJ%At+<10ykHeaX%$Wq#k(xiI;(k7;)432-O0T4DZMTm*-VPbqeEC9g??1t5b*5HRgolY5IhtBg>see z>opB+6c1q6K@Td0a2kTRiP1A=S6xrw`oKZPKRf_{p*1mM;ENtA)K;BS2&Wuj4=`ZR zDT#BE23S8@-c^zSolT4{2XHXUDBBtu%s&~~FB#dNe1Q2BEz%D_PX1d-`7R?Hy9v$P zX6cH9dJ=mD002ovPDHLkV1m)jGq?Z% literal 0 HcmV?d00001