fix incorrect display when no fill or stroke

This commit is contained in:
Anton Lavrenov 2023-01-05 23:43:35 -05:00
parent 1acfa9ebf7
commit e3f1d1c95b
2 changed files with 33 additions and 5 deletions

View File

@ -2,7 +2,10 @@ import { Util } from '../Util';
import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { _registerNode } from '../Global';
import { getNumberOrArrayOfNumbersValidator, getNumberValidator } from '../Validators';
import {
getNumberOrArrayOfNumbersValidator,
getNumberValidator,
} from '../Validators';
import { GetSet, IRect } from '../types';
import { Context } from '../Context';
@ -91,7 +94,7 @@ export class Image extends Shape<ImageConfig> {
}
}
if (this.hasFill() || this.hasStroke()) {
if (this.hasFill() || this.hasStroke() || cornerRadius) {
context.beginPath();
cornerRadius
? Util.drawRoundedRectPath(context, width, height, cornerRadius)
@ -101,13 +104,10 @@ export class Image extends Shape<ImageConfig> {
}
if (image) {
// context.save();
if (cornerRadius) {
// Util.drawRoundedRectPath(context, width, height, cornerRadius);
context.clip();
}
context.drawImage.apply(context, params);
// context.restore();
}
// If you need to draw later, you need to execute save/restore
}

View File

@ -385,4 +385,32 @@ describe('Image', function () {
done();
});
});
it.only('corner radius', function (done) {
loadImage('darth-vader.jpg', (imageObj) => {
var stage = addStage();
var layer = new Konva.Layer();
var darth = new Konva.Image({
x: 20,
y: 20,
image: imageObj,
cornerRadius: 10,
draggable: true,
stroke: 'red',
strokeWidth: 100,
strokeEnabled: false,
});
layer.add(darth);
stage.add(layer);
assert.equal(
layer.getContext().getTrace(true),
'clearRect();save();transform();beginPath();moveTo();lineTo();arc();lineTo();arc();lineTo();arc();lineTo();arc();closePath();clip();drawImage();restore();'
);
done();
});
});
});