From a5e7c0040e2d5c94a77fba6291463f8d86c24280 Mon Sep 17 00:00:00 2001 From: 0JARVIS0 <709406687@qq.com> Date: Tue, 3 Dec 2019 18:14:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E5=AD=97?= =?UTF-8?q?=E5=87=BA=E6=A1=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pen.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pen.js b/lib/pen.js index a83f060..4bfed02 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -196,15 +196,15 @@ export default class Painter { } const fontWeight = view.css.fontWeight === 'bold' ? 'bold' : 'normal'; const textStyle = view.css.textStyle === 'italic' ? 'italic' : 'normal'; - view.css.fontSize = view.css.fontSize ? view.css.fontSize : '20rpx'; + const fontSize = view.css.fontSize ? view.css.fontSize.toPx() : '20rpx'.toPx(); this.ctx.font = `${textStyle} ${fontWeight} ${view.css.fontSize.toPx()}px ${view.css.fontFamily ? view.css.fontFamily : 'sans-serif'}`; - // this.ctx.setFontSize(view.css.fontSize.toPx()); // 计算行数 let lines = 0; const linesArray = []; for (let i = 0; i < textArray.length; ++i) { const textLength = this.ctx.measureText(textArray[i]).width; - const partWidth = view.css.width ? view.css.width.toPx(false, this.style.width) - paddings[1] - paddings[3] : textLength; + let partWidth = view.css.width ? view.css.width.toPx(false, this.style.width) - paddings[1] - paddings[3] : textLength; + partWidth = partWidth > fontSize ? partWidth - partWidth % fontSize + fontSize : fontSize const calLines = Math.ceil(textLength / partWidth); // 取最长的作为 width width = partWidth > width ? partWidth : width; @@ -547,7 +547,7 @@ export default class Painter { } let lineIndex = 0; for (let j = 0; j < textArray.length; ++j) { - const preLineLength = Math.ceil(textArray[j].length / linesArray[j]); + const preLineLength = Math.floor(textArray[j].length / linesArray[j]); let start = 0; let alreadyCount = 0; for (let i = 0; i < linesArray[j]; ++i) {