@tmsfe/tms-core 0.0.84 → 0.0.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -125,14 +125,15 @@ class CanvasDrawer {
|
|
|
125
125
|
* @memberof Wxml2Poster
|
|
126
126
|
*/
|
|
127
127
|
drawText(text, x, y, size, color, align = 'left', bold = 'normal', baseLine = 'middle', calWidth = false) {
|
|
128
|
+
const str = `${text}`; // 避免某些环境下字体宽度计算异常(如手图),这里统一将绘制文本转为字符串
|
|
128
129
|
this.ctx.save();
|
|
129
130
|
this.ctx.fillStyle = color;
|
|
130
131
|
this.ctx.font = `normal ${bold} ${~~(this.toPx(size))}px sans-serif`;
|
|
131
132
|
let width = 0;
|
|
132
|
-
if (calWidth) width = this.ctx.measureText(
|
|
133
|
+
if (calWidth) width = this.ctx.measureText(str).width; // 必须在设置字体属性后未绘制前计算才能拿到准确值; 无需计算时避免耗费性能
|
|
133
134
|
this.ctx.textAlign = align;
|
|
134
135
|
this.ctx.textBaseline = baseLine;
|
|
135
|
-
this.ctx.fillText(
|
|
136
|
+
this.ctx.fillText(str, this.toPx(x), this.toPx(y));
|
|
136
137
|
this.ctx.restore();
|
|
137
138
|
return width;
|
|
138
139
|
}
|