增加 align 对多行文字的对齐支持
This commit is contained in:
parent
6d504dd8d0
commit
8747d18904
14
lib/pen.js
14
lib/pen.js
@ -266,7 +266,19 @@ export default class Painter {
|
|||||||
text += '...';
|
text += '...';
|
||||||
measuredWith = this.ctx.measureText(text).width;
|
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));
|
const y = -(height / 2) + (i === 0 ? view.css.fontSize.toPx() : (view.css.fontSize.toPx() + i * lineHeight));
|
||||||
if (view.css.textStyle === 'stroke') {
|
if (view.css.textStyle === 'stroke') {
|
||||||
this.ctx.strokeText(text, x, y, measuredWith);
|
this.ctx.strokeText(text, x, y, measuredWith);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user