我使用的是fabricjs 1.5,并且我一直坚持垂直对齐行中间的文本。
我正在使用此代码来设置行高
text.setProperty('lineHeight', $scope.lineHeight.current);
它更改画布上文本的行高,但文本始终保留在顶部。我希望它位于垂直中间。请帮忙。
const box_width = 100
const box_height = 100
// box
var rect = new fabric.Rect({
width: box_width, height: box_height,
fill: false, stroke: '#000',
})
// text
// vertical align = center
var text = new fabric.Text(
'hello', {
originX: 'center', originY: 'center',
left: 0.5*box_width, top: 0.5*box_height,
})
// group
var group = new fabric.Group(
[rect, text], {
left: 50, top: 50,
})
canvas.add(group)
fiddle
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)