fix: 🐛 fix test failed

This commit is contained in:
iaosee 2022-12-21 23:57:42 +08:00
parent b10daa43cc
commit e04cabfb45
2 changed files with 17 additions and 12 deletions

View File

@ -91,20 +91,25 @@ export class Image extends Shape<ImageConfig> {
} }
} }
context.beginPath(); if (this.hasFill() || this.hasStroke()) {
if (!cornerRadius) { context.beginPath();
context.rect(0, 0, width, height); cornerRadius
} else { ? Util.drawRoundedRectPath(context, width, height, cornerRadius)
Util.drawRoundedRectPath(context, width, height, cornerRadius); : context.rect(0, 0, width, height);
context.closePath();
context.fillStrokeShape(this);
} }
if (image) { if (image) {
context.save(); // context.save();
cornerRadius && context.clip(); if (cornerRadius) {
// Util.drawRoundedRectPath(context, width, height, cornerRadius);
context.clip();
}
context.drawImage.apply(context, params); context.drawImage.apply(context, params);
context.restore(); // context.restore();
} }
context.closePath(); // If you need to draw later, you need to execute save/restore
context.fillStrokeShape(this);
} }
_hitFunc(context) { _hitFunc(context) {
var width = this.width(), var width = this.width(),

View File

@ -26,7 +26,6 @@ describe('Image', function () {
offset: { x: 50, y: 30 }, offset: { x: 50, y: 30 },
crop: { x: 135, y: 7, width: 167, height: 134 }, crop: { x: 135, y: 7, width: 167, height: 134 },
draggable: true, draggable: true,
cornerRadius: 15,
}); });
layer.add(darth); layer.add(darth);
@ -44,7 +43,6 @@ describe('Image', function () {
assert.equal(darth.getHeight(), 100); assert.equal(darth.getHeight(), 100);
assert.equal(darth.offset().x, 50); assert.equal(darth.offset().x, 50);
assert.equal(darth.offset().y, 30); assert.equal(darth.offset().y, 30);
assert.equal(darth.cornerRadius(), 15);
var crop = darth.crop(); var crop = darth.crop();
@ -169,6 +167,7 @@ describe('Image', function () {
crop: { x: 186, y: 211, width: 106, height: 74 }, crop: { x: 186, y: 211, width: 106, height: 74 },
draggable: true, draggable: true,
scale: { x: 0.5, y: 0.5 }, scale: { x: 0.5, y: 0.5 },
cornerRadius: 15,
}); });
layer.add(darth); layer.add(darth);
@ -210,6 +209,7 @@ describe('Image', function () {
assert.equal(darth.cropY(), 6); assert.equal(darth.cropY(), 6);
assert.equal(darth.cropWidth(), 7); assert.equal(darth.cropWidth(), 7);
assert.equal(darth.cropHeight(), 8); assert.equal(darth.cropHeight(), 8);
assert.equal(darth.cornerRadius(), 15);
done(); done();
}); });