diff --git a/lib/pen.js b/lib/pen.js index cdc230e..749ee31 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -270,7 +270,7 @@ export default class Painter { break; } this.ctx.rotate(angle); - if (!notClip && view.css && view.css.borderRadius) { + if (!notClip && view.css && view.css.borderRadius && view.type !== 'rect') { this._doClip(view.css.borderRadius, width, height); } this._doShadow(view); @@ -509,7 +509,18 @@ export default class Painter { } else { this.ctx.fillStyle = view.css.color; } - this.ctx.fillRect(-(width / 2), -(height / 2), width, height); + const borderRadius = view.css.borderRadius + const r = borderRadius ? Math.min(borderRadius.toPx(), width / 2, height / 2) : 0; + this.ctx.beginPath(); + this.ctx.arc(-width / 2 + r, -height / 2 + r, r, 1 * Math.PI, 1.5 * Math.PI); //左上角圆弧 + this.ctx.lineTo(width / 2 - r, -height / 2); + this.ctx.arc(width / 2 - r, -height / 2 + r, r, 1.5 * Math.PI, 2 * Math.PI); // 右上角圆弧 + this.ctx.lineTo(width / 2, height / 2 - r); + this.ctx.arc(width / 2 - r, height / 2 - r, r, 0, 0.5 * Math.PI); // 右下角圆弧 + this.ctx.lineTo(-width / 2 + r, height / 2); + this.ctx.arc(-width / 2 + r, height / 2 - r, r, 0.5 * Math.PI, 1 * Math.PI); // 左下角圆弧 + this.ctx.closePath(); + this.ctx.fill(); this.ctx.restore(); this._doBorder(view, width, height); }