|
@@ -296,7 +296,15 @@ export default class Draw {
|
|
|
const defaultWidth = 156;
|
|
|
|
|
|
this.context.font = '12px Microsoft YaHei'
|
|
|
- const fontWidth = this.context.measureText(geometry.value).width
|
|
|
+ let fontWidth = this.context.measureText(geometry.value).width
|
|
|
+ //如果是数字或者字母
|
|
|
+ const patt = /[A-z0-9]/g;
|
|
|
+ const alphanumeric = geometry.value.match(patt);
|
|
|
+ if(alphanumeric){
|
|
|
+ const alphanumericLen = geometry.value.match(patt).length;
|
|
|
+ fontWidth = fontWidth * (geometry.value.length - alphanumericLen)/geometry.value.length + fontWidth * alphanumericLen/geometry.value.length*1.5
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//let rowCount = Math.ceil(geometry.height/defaultHeight) //分几行写
|
|
|
let rowCount = Math.ceil(fontWidth/geometry.width) //分几行写,根据要写的文字的长度来判断
|