From ee0d1dbb6ae38560cde33bfa854bfb19118b896e Mon Sep 17 00:00:00 2001 From: guangyan Date: Tue, 9 Jul 2019 09:42:42 +0800 Subject: [PATCH 1/2] This closes #69, closes #34, and closes #25 --- miniprogram_dist/index/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/miniprogram_dist/index/index.js b/miniprogram_dist/index/index.js index 4d51c04..5573284 100644 --- a/miniprogram_dist/index/index.js +++ b/miniprogram_dist/index/index.js @@ -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(); From b72ee8735b64990a79db62f247d32524473df432 Mon Sep 17 00:00:00 2001 From: guangyan Date: Tue, 9 Jul 2019 10:07:12 +0800 Subject: [PATCH 2/2] fix text pixel ratio --- miniprogram_dist/index/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniprogram_dist/index/index.js b/miniprogram_dist/index/index.js index 4d51c04..1bc3cf1 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) { // 文本宽度 大于 渲染宽度