From 81e6193b1fe6ea4601d713dd6da8f527ed533d5e Mon Sep 17 00:00:00 2001 From: CPPAlien Date: Wed, 18 Dec 2019 11:58:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=AA=E5=8A=A8=E6=97=B6=20textDecora?= =?UTF-8?q?tion=20=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pen.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/pen.js b/lib/pen.js index f991d52..be0ef3c 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -527,18 +527,19 @@ export default class Painter { text, x, y, + textDecoration } = i if (view.css.textStyle === 'stroke') { this.ctx.strokeText(text, x, y, measuredWith); } else { this.ctx.fillText(text, x, y, measuredWith); } - if (view.css.textDecoration) { + if (textDecoration) { const fontSize = view.css.fontSize.toPx(); this.ctx.lineWidth = fontSize / 13; this.ctx.beginPath(); - this.ctx.moveTo(...this.movingCache.textDecoration.moveTo); - this.ctx.lineTo(...this.movingCache.textDecoration.lineTo); + this.ctx.moveTo(...textDecoration.moveTo); + this.ctx.lineTo(...textDecoration.lineTo); this.ctx.closePath(); this.ctx.strokeStyle = view.css.color; this.ctx.stroke(); @@ -625,32 +626,33 @@ export default class Painter { this.ctx.fillText(text, x, y, measuredWith); } const fontSize = view.css.fontSize.toPx(); + let textDecoration; if (view.css.textDecoration) { this.ctx.lineWidth = fontSize / 13; this.ctx.beginPath(); if (/\bunderline\b/.test(view.css.textDecoration)) { this.ctx.moveTo(lineX, y); this.ctx.lineTo(lineX + measuredWith, y); - !this.isMoving && (this.callbackInfo.textDecoration = { + textDecoration = { moveTo: [lineX, y], lineTo: [lineX + measuredWith, y] - }) + } } if (/\boverline\b/.test(view.css.textDecoration)) { this.ctx.moveTo(lineX, y - fontSize); this.ctx.lineTo(lineX + measuredWith, y - fontSize); - !this.isMoving && (this.callbackInfo.textDecoration = { + textDecoration = { moveTo: [lineX, y - fontSize], lineTo: [lineX + measuredWith, y - fontSize] - }) + } } if (/\bline-through\b/.test(view.css.textDecoration)) { this.ctx.moveTo(lineX, y - fontSize / 3); this.ctx.lineTo(lineX + measuredWith, y - fontSize / 3); - !this.isMoving && (this.callbackInfo.textDecoration = { + textDecoration = { moveTo: [lineX, y - fontSize / 3], lineTo: [lineX + measuredWith, y - fontSize / 3] - }) + } } this.ctx.closePath(); this.ctx.strokeStyle = view.css.color; @@ -661,12 +663,14 @@ export default class Painter { text, x, y, - measuredWith + measuredWith, + textDecoration }) : this.callbackInfo.lineArray = [{ text, x, y, - measuredWith + measuredWith, + textDecoration }] } }