From b8ffc149657a84cc1a4daaf4482e84ef0533e8c2 Mon Sep 17 00:00:00 2001 From: CPPAlien Date: Mon, 16 Jul 2018 17:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=20fontWeight=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pen.js | 5 ++++- painter.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pen.js b/lib/pen.js index de1f8e8..99a8819 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -103,8 +103,11 @@ export default class Painter { let y; let extra; if (view.type === 'text') { + const fontWeight = view.css.fontWeight === 'bold' ? 'bold' : 'normal'; + const fontSize = view.css.fontSize ? view.css.fontSize : '20rpx'; + this.ctx.font = `normal ${fontWeight} ${fontSize.toPx()}px sans-serif`; this.ctx.setFillStyle(view.css.color ? view.css.color : 'black'); - this.ctx.setFontSize(view.css.fontSize.toPx()); + // this.ctx.setFontSize(view.css.fontSize.toPx()); const textLength = this.ctx.measureText(view.text).width; width = view.css.width ? view.css.width.toPx() : textLength; // 计算行数 diff --git a/painter.js b/painter.js index a8ef3a7..1e6cd9a 100644 --- a/painter.js +++ b/painter.js @@ -195,7 +195,7 @@ function setStringPrototype() { let res = 0; if (unit === 'rpx') { - res = value * screenK; + res = Math.round(value * screenK); } else if (unit === 'px') { res = value; }