From 0d89fe6cb7b69a8babd5a8c8a00abcfb75d44790 Mon Sep 17 00:00:00 2001 From: CPPAlien Date: Wed, 6 Nov 2019 16:17:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E6=9C=AC=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pen.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/pen.js b/lib/pen.js index bfab2d6..832c4c6 100644 --- a/lib/pen.js +++ b/lib/pen.js @@ -6,6 +6,7 @@ export default class Painter { this.ctx = ctx; this.data = data; this.globalTextWidth = {}; + this.globalTextHeight = {}; } paint(callback) { @@ -237,7 +238,22 @@ export default class Painter { } else { x = 0; } - const y = view.css && view.css.bottom ? this.style.height - height - view.css.bottom.toPx(true) : (view.css && view.css.top ? view.css.top.toPx(true) : 0); + //const y = view.css && view.css.bottom ? this.style.height - height - view.css.bottom.toPx(true) : (view.css && view.css.top ? view.css.top.toPx(true) : 0); + let y; + if (view.css && view.css.bottom) { + y = this.style.height - height - view.css.bottom.toPx(true); + } else { + if (view.css && view.css.top) { + if (typeof view.css.top === 'string') { + y = view.css.top.toPx(true); + } else { + const tops = view.css.top; + y = tops[0].toPx(true) + this.globalTextHeight[tops[1]] * (tops[2] || 1); + } + } else { + y = 0 + } + } const angle = view.css && view.css.rotate ? this._getAngle(view.css.rotate) : 0; // 当设置了 right 时,默认 align 用 right,反之用 left @@ -393,6 +409,7 @@ export default class Painter { textWidth = this.ctx.measureText(textArray[i]).width > textWidth ? this.ctx.measureText(textArray[i]).width : textWidth; } this.globalTextWidth[view.id] = width ? (textWidth < width ? textWidth : width) : textWidth; + this.globalTextHeight[view.id] = height; } let lineIndex = 0; for (let j = 0; j < textArray.length; ++j) {