【发布时间】:2024-04-21 04:40:02
【问题描述】:
我正在使用 Fabric.js 制作绘图编辑器。要求之一是创建灵活的文本框组件(如 Goole Slides 或 Power Point),其边界框可以在不影响文本大小和其他文本控件(如缩放、重新定位)的情况下进行调整......目前,fabric.js 提供 @987654327 @ 不足以完成此任务。所以我正在使用fabric.Group,但我对选择问题很感兴趣。我无法选择组的子对象。我该如何解决这个问题。欢迎提供任何信息
这是我想要实现的:
这就是我现在拥有的原始 fabric.Text 对象
这就是我使用fabric.Group 所取得的成就
这是我的文本框类
class Text extends fabric.Group {
constructor(options) {
super([], Object.assign(options));
this.class = 'textbox';
this.init();
}
init() {
const left = this.left;
const top = this.top;
const width = this.width || 100;
const height = this.height || 40;
this.rect = new fabric.Rect({
left,
top,
width,
height,
fill: 'rgba(0,0,0,0)',
stroke: this.stroke,
type: 'rect',
originX: 'left',
originY: 'top',
strokeWidth: this.strokeWidth
});
this.text = new fabric.IText(this.text, {
left: left + 20,
top: top + 12,
fontSize: this.fontSize,
fontFamily: this.fontFamily,
fontColor: this.fontColor,
selectable: true
});
this.text.setCoords();
this.text.setControlsVisibility({
br: false, // middle top disable
bl: false, // midle bottom
tl: false, // middle left
tr: false, // I think you get it,
mb: false,
ml: false,
mt: false,
mr: false,
mtr: false
});
this.addWithUpdate(this.rect);
this.addWithUpdate(this.text);
}
toObject() {
const obj = super.toObject();
return Object.assign(obj, {
class: this.class
});
}
}
export default Text;
【问题讨论】:
标签: javascript canvas html5-canvas drawing fabricjs