diff --git a/miniprogram_dist/index/index.js b/miniprogram_dist/index/index.js index 4d51c04..58b4cb8 100644 --- a/miniprogram_dist/index/index.js +++ b/miniprogram_dist/index/index.js @@ -185,7 +185,7 @@ const handle = { this.ctx.setFillStyle(color); this.ctx.setTextBaseline(baseLine); this.ctx.setTextAlign(textAlign); - let textWidth = this.toRpx(this.ctx.measureText(text).width); + let textWidth = this.toRpx(this.ctx.measureText(text).width / this.pixelRatio); const textArr = []; if (textWidth > width) { // 文本宽度 大于 渲染宽度 @@ -216,10 +216,20 @@ const handle = { } else { textArr.push(text); } - textArr.forEach((item, index) => { - this.ctx.fillText(item, this.toPx(x), this.toPx(y + (lineHeight || fontSize) * index)); + if (textAlign === 'left') { + this.ctx.fillText(item, this.toPx(x), this.toPx(y + (lineHeight || fontSize) * index) + (lineHeight || fontSize) / 2); + } + else if (textAlign === 'center') { + this.ctx.fillText(item, this.toPx(x + width / 2), this.toPx(y + (lineHeight || fontSize) * index) + (lineHeight || fontSize) / 2); + } + else if (textAlign === 'right') { + this.ctx.fillText(item, this.toPx(x + width), this.toPx(y + (lineHeight || fontSize) * index) + (lineHeight || fontSize) / 2); + } }) + // textArr.forEach((item, index) => { + // this.ctx.fillText(item, this.toPx(x), this.toPx(y + (lineHeight || fontSize) * index)); + // }) this.ctx.restore();