【发布时间】:2020-12-20 19:29:02
【问题描述】:
我在Fabric.js 文档中大量搜索maxLines、noWrap、splitByWhitespace 等属性,但它们不存在。您知道在fabric.Textbox 内禁用文本换行的有效解决方案吗?
我的代码:
const text = new window.fabric.Textbox('expected single line', {
fontFamily: 'Nunito Sans',
fontWeight: 400,
fontSize: 15,
originX: 'center',
originY: 'center',
});
const border = new window.fabric.Rect({
rx: 10,
ry: 10,
fill: '#999999',
height: text.height + 10,
width: text.width + 100,
originX: 'center',
originY: 'center',
});
const group = new window.fabric.Group([border, text], {
originX: 'left',
originY: 'top',
hasRotatingPoint: false,
height: 42,
width: 200,
top: 167,
left: 50,
});
canvas.add(group);
实际效果演示:
如您所见,每个空格都有换行符,但我希望有一个带空格的单行文本。有趣的是,如果我用下划线_ 替换空格,我会得到单行文本。
演示:
【问题讨论】:
标签: javascript textbox fabricjs