From fd77f305d1bef081f0c23cd8822d5e1531a4953a Mon Sep 17 00:00:00 2001 From: Anton Lavrevov Date: Fri, 28 Mar 2025 12:52:40 -0500 Subject: [PATCH] fix buffer usage in export for stage and layer. fix #1903 --- src/Container.ts | 2 -- src/Layer.ts | 4 ++-- src/shapes/Image.ts | 1 - test/unit/Shape-test.ts | 47 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/Container.ts b/src/Container.ts index 73d77a0b..c70026fa 100644 --- a/src/Container.ts +++ b/src/Container.ts @@ -120,8 +120,6 @@ export abstract class Container< * layer.add(shape1, shape2, shape3); * // empty arrays are accepted, though each individual child must be defined * layer.add(...shapes); - * // remember to redraw layer if you changed something - * layer.draw(); */ add(...children: ChildType[]) { if (children.length === 0) { diff --git a/src/Layer.ts b/src/Layer.ts index 8e94c1d1..2ffc12f3 100644 --- a/src/Layer.ts +++ b/src/Layer.ts @@ -385,7 +385,7 @@ export class Layer extends Container { // empty pixel return {}; } - drawScene(can?: SceneCanvas, top?: Node) { + drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas) { const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()); @@ -397,7 +397,7 @@ export class Layer extends Container { canvas.getContext().clear(); } - Container.prototype.drawScene.call(this, canvas, top); + Container.prototype.drawScene.call(this, canvas, top, bufferCanvas); this._fire(DRAW, { node: this, diff --git a/src/shapes/Image.ts b/src/shapes/Image.ts index a091b3ec..b4ef1935 100644 --- a/src/shapes/Image.ts +++ b/src/shapes/Image.ts @@ -163,7 +163,6 @@ export class Image extends Shape { * Konva.Image.fromURL(imageURL, function(image){ * // image is Konva.Image instance * layer.add(image); - * layer.draw(); * }); */ static fromURL( diff --git a/test/unit/Shape-test.ts b/test/unit/Shape-test.ts index 26758dda..70b1929d 100644 --- a/test/unit/Shape-test.ts +++ b/test/unit/Shape-test.ts @@ -1550,6 +1550,53 @@ describe('Shape', function () { compareCanvases(canvas2, canvas1, 240, 110); }); + it('export stage when buffer canvas is for line', async function () { + var stage = addStage(); + + var layer = new Konva.Layer(); + stage.add(layer); + + const group = new Konva.Group({ + id: 'group01', + draggable: false, + opacity: 0.99, + }); + layer.add(group); + + const arrow = new Konva.Arrow({ + x: 0, + y: 0, + points: [50, 25, 200, 25, 200, 225, 400, 225], + stroke: 'purple', + fill: 'purple', + strokeWidth: 4, + pointerAtEnding: true, + bezier: true, + }); + group.add(arrow); + + const bounds = layer.getClientRect({ relativeTo: stage }); + const pos = stage.getPosition(); + + const canvas1 = layer.toCanvas({ + pixelRatio: 1, + x: bounds.x + pos.x, + y: bounds.y + pos.y, + width: bounds.width, + height: bounds.height, + }); + group.opacity(1); + const canvas2 = layer.toCanvas({ + pixelRatio: 1, + x: bounds.x + pos.x, + y: bounds.y + pos.y, + width: bounds.width, + height: bounds.height, + }); + + compareCanvases(canvas1, canvas2, 240, 110); + }); + // ====================================================== it('optional disable shadow for stroke', function () { var stage = addStage();