加入 fontWeight 属性

This commit is contained in:
CPPAlien 2018-07-16 17:34:15 +08:00
parent c17b06dcd4
commit b8ffc14965
2 changed files with 5 additions and 2 deletions

View File

@ -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;
// 计算行数

View File

@ -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;
}