fabric.js 中我创建了一个组合,如何才能使文字相对于绘制图形居中?

示例代码

        //这个是手动绘制的图形
       let polyline = new fabric.Polyline(points, {
          stroke: "red",
          fill: this.defaultFillColor,
          statefullCache: true,
          //这两属性开启了也没有效果
           //originX: "center",
          //originY: "center",
        });
        //创建文本
        let text = new fabric.Text("暂未设置", {
        fontSize: this.defaultFontSize,
        statefullCache: true 
        //这两属性开启了也没有效果
         //originX: "center",
        //originY: "center",
      });
        //进行组合
        let group = new fabric.Group([polyline, text], {
          statefullCache: true //修改元素后进行更新
        });
        this.canvas.add(group);

代码效果

image.png

怎样才能使文字相对于图形居中呢?

阅读 2.1k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题