From c53b7c01a45689c782e5ed96ecb19adb5f103869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9B=BD=E8=87=A3?= Date: Wed, 14 Aug 2019 12:06:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8D=B3=E5=B0=86=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E7=BB=B4=E6=8A=A4=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B7=91=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pen.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/pen.js b/lib/pen.js index 6f548ea..890acdc 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -34,11 +34,11 @@ export default class Painter { this._doClip(this.data.borderRadius, width, height); if (!bg) { // 如果未设置背景,则默认使用白色 - this.ctx.setFillStyle('#fff'); + this.ctx.fillStyle = '#fff'; this.ctx.fillRect(-(width / 2), -(height / 2), width, height); } else if (bg.startsWith('#') || bg.startsWith('rgba') || bg.toLowerCase() === 'transparent') { // 背景填充颜色 - this.ctx.setFillStyle(bg); + this.ctx.fillStyle = bg; this.ctx.fillRect(-(width / 2), -(height / 2), width, height); } else if (GD.api.isGradient(bg)) { GD.api.doGradient(bg, width, height, this.ctx); @@ -79,10 +79,10 @@ export default class Painter { _doClip(borderRadius, width, height) { if (borderRadius && width && height) { const r = Math.min(borderRadius.toPx(), width / 2, height / 2); - // 防止在某些机型上周边有黑框现象,此处如果直接设置 setFillStyle 为透明,在 Android 机型上会导致被裁减的图片也变为透明, iOS 和 IDE 上不会 - // setGlobalAlpha 在 1.9.90 起支持,低版本下无效,但把 setFillStyle 设为了 white,相对默认的 black 要好点 - this.ctx.setGlobalAlpha(0); - this.ctx.setFillStyle('white'); + // 防止在某些机型上周边有黑框现象,此处如果直接设置 fillStyle 为透明,在 Android 机型上会导致被裁减的图片也变为透明, iOS 和 IDE 上不会 + // globalAlpha 在 1.9.90 起支持,低版本下无效,但把 fillStyle 设为了 white,相对默认的 black 要好点 + this.ctx.globalAlpha = 0; + this.ctx.fillStyle = 'white'; 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); @@ -99,7 +99,7 @@ export default class Painter { && getApp().systemInfo.platform === 'ios')) { this.ctx.clip(); } - this.ctx.setGlobalAlpha(1); + this.ctx.globalAlpha = 1; } } @@ -127,8 +127,8 @@ export default class Painter { r = 0; } const lineWidth = borderWidth.toPx(); - this.ctx.setLineWidth(lineWidth); - this.ctx.setStrokeStyle(borderColor || 'black'); + this.ctx.lineWidth = lineWidth; + this.ctx.strokeStyle = (borderColor || 'black'); this.ctx.beginPath(); this.ctx.arc(-width / 2 + r, -height / 2 + r, r + lineWidth / 2, 1 * Math.PI, 1.5 * Math.PI); this.ctx.lineTo(width / 2 - r, -height / 2 - lineWidth / 2); @@ -311,7 +311,7 @@ export default class Painter { if (GD.api.isGradient(background)) { GD.api.doGradient(background, width, height, this.ctx); } else { - this.ctx.setFillStyle(background); + this.ctx.fillStyle = background; } this.ctx.fillRect(-(width / 2), -(height / 2), width, height); @@ -378,7 +378,7 @@ export default class Painter { extra, } = this._preProcess(view); - this.ctx.setFillStyle(view.css.color || 'black'); + this.ctx.fillStyle = (view.css.color || 'black'); const { lines, lineHeight, @@ -469,7 +469,7 @@ export default class Painter { this.ctx.lineTo(x + measuredWith, y - fontSize / 3); } this.ctx.closePath(); - this.ctx.setStrokeStyle(view.css.color); + this.ctx.strokeStyle = view.css.color; this.ctx.stroke(); } } @@ -487,7 +487,7 @@ export default class Painter { if (GD.api.isGradient(view.css.color)) { GD.api.doGradient(view.css.color, width, height, this.ctx); } else { - this.ctx.setFillStyle(view.css.color); + this.ctx.fillStyle = view.css.color; } this.ctx.fillRect(-(width / 2), -(height / 2), width, height); this.ctx.restore();