fix: 挪动时 textDecoration 丢失问题

This commit is contained in:
CPPAlien 2019-12-18 11:58:51 +08:00
parent c19e0331bf
commit 81e6193b1f

View File

@ -527,18 +527,19 @@ export default class Painter {
text, text,
x, x,
y, y,
textDecoration
} = i } = i
if (view.css.textStyle === 'stroke') { if (view.css.textStyle === 'stroke') {
this.ctx.strokeText(text, x, y, measuredWith); this.ctx.strokeText(text, x, y, measuredWith);
} else { } else {
this.ctx.fillText(text, x, y, measuredWith); this.ctx.fillText(text, x, y, measuredWith);
} }
if (view.css.textDecoration) { if (textDecoration) {
const fontSize = view.css.fontSize.toPx(); const fontSize = view.css.fontSize.toPx();
this.ctx.lineWidth = fontSize / 13; this.ctx.lineWidth = fontSize / 13;
this.ctx.beginPath(); this.ctx.beginPath();
this.ctx.moveTo(...this.movingCache.textDecoration.moveTo); this.ctx.moveTo(...textDecoration.moveTo);
this.ctx.lineTo(...this.movingCache.textDecoration.lineTo); this.ctx.lineTo(...textDecoration.lineTo);
this.ctx.closePath(); this.ctx.closePath();
this.ctx.strokeStyle = view.css.color; this.ctx.strokeStyle = view.css.color;
this.ctx.stroke(); this.ctx.stroke();
@ -625,32 +626,33 @@ export default class Painter {
this.ctx.fillText(text, x, y, measuredWith); this.ctx.fillText(text, x, y, measuredWith);
} }
const fontSize = view.css.fontSize.toPx(); const fontSize = view.css.fontSize.toPx();
let textDecoration;
if (view.css.textDecoration) { if (view.css.textDecoration) {
this.ctx.lineWidth = fontSize / 13; this.ctx.lineWidth = fontSize / 13;
this.ctx.beginPath(); this.ctx.beginPath();
if (/\bunderline\b/.test(view.css.textDecoration)) { if (/\bunderline\b/.test(view.css.textDecoration)) {
this.ctx.moveTo(lineX, y); this.ctx.moveTo(lineX, y);
this.ctx.lineTo(lineX + measuredWith, y); this.ctx.lineTo(lineX + measuredWith, y);
!this.isMoving && (this.callbackInfo.textDecoration = { textDecoration = {
moveTo: [lineX, y], moveTo: [lineX, y],
lineTo: [lineX + measuredWith, y] lineTo: [lineX + measuredWith, y]
}) }
} }
if (/\boverline\b/.test(view.css.textDecoration)) { if (/\boverline\b/.test(view.css.textDecoration)) {
this.ctx.moveTo(lineX, y - fontSize); this.ctx.moveTo(lineX, y - fontSize);
this.ctx.lineTo(lineX + measuredWith, y - fontSize); this.ctx.lineTo(lineX + measuredWith, y - fontSize);
!this.isMoving && (this.callbackInfo.textDecoration = { textDecoration = {
moveTo: [lineX, y - fontSize], moveTo: [lineX, y - fontSize],
lineTo: [lineX + measuredWith, y - fontSize] lineTo: [lineX + measuredWith, y - fontSize]
}) }
} }
if (/\bline-through\b/.test(view.css.textDecoration)) { if (/\bline-through\b/.test(view.css.textDecoration)) {
this.ctx.moveTo(lineX, y - fontSize / 3); this.ctx.moveTo(lineX, y - fontSize / 3);
this.ctx.lineTo(lineX + measuredWith, y - fontSize / 3); this.ctx.lineTo(lineX + measuredWith, y - fontSize / 3);
!this.isMoving && (this.callbackInfo.textDecoration = { textDecoration = {
moveTo: [lineX, y - fontSize / 3], moveTo: [lineX, y - fontSize / 3],
lineTo: [lineX + measuredWith, y - fontSize / 3] lineTo: [lineX + measuredWith, y - fontSize / 3]
}) }
} }
this.ctx.closePath(); this.ctx.closePath();
this.ctx.strokeStyle = view.css.color; this.ctx.strokeStyle = view.css.color;
@ -661,12 +663,14 @@ export default class Painter {
text, text,
x, x,
y, y,
measuredWith measuredWith,
textDecoration
}) : this.callbackInfo.lineArray = [{ }) : this.callbackInfo.lineArray = [{
text, text,
x, x,
y, y,
measuredWith measuredWith,
textDecoration
}] }]
} }
} }