Skip to content

Commit

Permalink
additional fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lavrton committed Sep 4, 2023
1 parent 3af5f0f commit f6bcbb7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/shapes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,11 @@ export class Text extends Shape<TextConfig> {
}

_useBufferCanvas() {
const hasUnderline = this.textDecoration().indexOf('underline') !== -1;
const hasLine =
this.textDecoration().indexOf('underline') !== -1 ||
this.textDecoration().indexOf('line-through') !== -1;
const hasShadow = this.hasShadow();
if (hasUnderline && hasShadow) {
if (hasLine && hasShadow) {
return true;
}
return super._useBufferCanvas();
Expand Down
34 changes: 34 additions & 0 deletions test/unit/Text-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,40 @@ describe('Text', function () {
compareCanvases(groupCanvas, text.toCanvas(), 200);
});

it('text with line-through and shadow', function () {
var stage = addStage();
var layer = new Konva.Layer();

var text = new Konva.Text({
text: 'Test',
fill: 'black',
fontSize: 40,
textDecoration: 'line-through',
shadowEnabled: true,
shadowColor: 'red',
shadowOffsetX: 5,
shadowOffsetY: 5,
});

layer.add(text);
stage.add(layer);

var trace =
'clearRect();save();shadowColor;shadowBlur;shadowOffsetX;shadowOffsetY;drawImage();restore();';

assert.equal(layer.getContext().getTrace(true), trace);

// now check result visually
// text with red shadow is the same as red text with back text on top
const group = new Konva.Group({});
layer.add(group);
group.add(text.clone({ shadowEnabled: false, x: 5, y: 5, fill: 'red' }));
group.add(text.clone({ shadowEnabled: false }));
const groupCanvas = group.toCanvas();

compareCanvases(groupCanvas, text.toCanvas(), 200, 50);
});

// ======================================================
it('change font size should update text data', function () {
var stage = addStage();
Expand Down

0 comments on commit f6bcbb7

Please sign in to comment.