Skip to content

Commit

Permalink
Another fix for exporting buffered shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Feb 9, 2024
1 parent 1e2c287 commit 4da037a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

### 9.3.3 (2024-02-09)

- Another fix for exporting buffered shapes

### 9.3.2 (2024-01-26)

- Fix large memory usage on node export
Expand Down
5 changes: 3 additions & 2 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1935,8 +1935,9 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
const bufferCanvas = new SceneCanvas({
// width and height already multiplied by pixelRatio
// so we need to revert that
width: canvas.width / canvas.pixelRatio,
height: canvas.height / canvas.pixelRatio,
// also increase size by x nd y offset to make sure content fits canvas
width: canvas.width / canvas.pixelRatio + Math.abs(x),
height: canvas.height / canvas.pixelRatio + Math.abs(y),
pixelRatio: canvas.pixelRatio,
});

Expand Down
36 changes: 36 additions & 0 deletions test/unit/Shape-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,42 @@ describe('Shape', function () {
compareCanvases(canvas2, canvas1, 255, 10);
});

it('export when buffer canvas is used should handle scaling correctly another time', async function () {
var stage = addStage();

var layer = new Konva.Layer();
stage.add(layer);

var group = new Konva.Group({
x: 400,
});
layer.add(group);

var text = new Konva.Text({
text: 'hello',
fontSize: 300,
fill: 'green',
shadowColor: 'black',
});
group.add(text);

const canvas1 = group.toCanvas({
x: group.x(),
y: group.y(),
width: text.width(),
height: text.height(),
});
text.stroke('transparent');
const canvas2 = group.toCanvas({
x: group.x(),
y: group.y(),
width: text.width(),
height: text.height(),
});

compareCanvases(canvas2, canvas1, 240, 110);
});

// ======================================================
it('optional disable shadow for stroke', function () {
var stage = addStage();
Expand Down

0 comments on commit 4da037a

Please sign in to comment.