增加 align 对多行文字的对齐支持

This commit is contained in:
CPPAlien 2018-07-25 14:54:59 +08:00
parent 6d504dd8d0
commit 8747d18904

View File

@ -266,7 +266,19 @@ export default class Painter {
text += '...';
measuredWith = this.ctx.measureText(text).width;
}
const x = -(width / 2);
this.ctx.setTextAlign(view.css.align ? view.css.align : 'left');
let x;
switch (view.css.align) {
case 'center':
x = 0;
break;
case 'right':
x = (width / 2);
break;
default:
x = -(width / 2);
break;
}
const y = -(height / 2) + (i === 0 ? view.css.fontSize.toPx() : (view.css.fontSize.toPx() + i * lineHeight));
if (view.css.textStyle === 'stroke') {
this.ctx.strokeText(text, x, y, measuredWith);