|
@@ -292,9 +292,31 @@ export default class Draw {
|
|
|
this.context.closePath();
|
|
|
this.context.stroke()
|
|
|
|
|
|
+ const defaultHeight = 24;
|
|
|
+ const defaultWidth = 156;
|
|
|
+
|
|
|
this.context.font = '12px Microsoft YaHei'
|
|
|
const fontWidth = this.context.measureText(geometry.value).width
|
|
|
- this.context.fillText(geometry.value, geometry.width/2 - fontWidth/2, geometry.height/2+6)
|
|
|
+
|
|
|
+ //let rowCount = Math.ceil(geometry.height/defaultHeight) //分几行写
|
|
|
+ let rowCount = Math.ceil(fontWidth/defaultWidth) //分几行写,根据要写的文字的长度来判断
|
|
|
+
|
|
|
+ if(rowCount == 1){
|
|
|
+ this.context.textAlign = "center";
|
|
|
+ this.context.textBaseline = "middle";
|
|
|
+ this.context.fillText(geometry.value, geometry.width/2, geometry.height/2)
|
|
|
+ }
|
|
|
+ //大于1行
|
|
|
+ else{
|
|
|
+ const rowWidth = Math.ceil(fontWidth/rowCount) //每行的长度
|
|
|
+ const rowFontCount = Math.ceil(geometry.value.length/rowCount) //每行的文字个数
|
|
|
+ this.context.textAlign = "left";
|
|
|
+ for(let i=0;i<rowCount;++i){
|
|
|
+ const value = geometry.value.substr(i*rowFontCount,rowFontCount)
|
|
|
+ this.context.fillText(value, geometry.width/2 - rowWidth/2, 18+18*i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.context.restore()
|
|
|
}
|
|
|
|
|
@@ -785,9 +807,6 @@ export default class Draw {
|
|
|
|
|
|
drawImage(geometry){
|
|
|
if(geometry.src != null){
|
|
|
-
|
|
|
- const imgWidth = 600
|
|
|
- const imgHeight = 400
|
|
|
const pt = {
|
|
|
x:30,
|
|
|
y:150
|
|
@@ -800,12 +819,12 @@ export default class Draw {
|
|
|
img.src = geometry.src;
|
|
|
img.crossOrigin=""
|
|
|
img.onload = function () {
|
|
|
- this.context.drawImage(img, pt.x, pt.y, imgWidth, imgHeight)
|
|
|
+ this.context.drawImage(img, pt.x, pt.y, img.width, img.height)
|
|
|
}.bind(this)
|
|
|
geometry.image = img;
|
|
|
}
|
|
|
else{
|
|
|
- this.context.drawImage(geometry.image, pt.x, pt.y, imgWidth, imgHeight)
|
|
|
+ this.context.drawImage(geometry.image, pt.x, pt.y, geometry.image.width, geometry.image.height)
|
|
|
}
|
|
|
this.context.restore()
|
|
|
}
|