Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

复制自定义类型的元素,得到一个空白元素 #337

Open
marysyy1101 opened this issue Apr 17, 2024 · 0 comments
Open

复制自定义类型的元素,得到一个空白元素 #337

marysyy1101 opened this issue Apr 17, 2024 · 0 comments

Comments

@marysyy1101
Copy link

创建的自定义类型的元素,复制时候空白

1、使用createClass创建了一个自定义类(半圆)

export let Semicircle = fabric.util.createClass(fabric.Object, {
  // 初始化
  initialize(options) {
    this.callSuper('initialize', options);
    this.width = 100;
    this.height = 50;
  },
  // 渲染
  _render(ctx) {
    ctx.strokeStyle = this.stroke || '#333'; // 初始化描边颜色
    ctx.lineWidth = this.strokeWidth || 1; // 初始化描边宽度
    ctx.fillStyle = this.fill || '#333'; // 初始化填充色
    ctx.beginPath(); // 开始绘制路径
    ctx.arc(0, -25, 50, 0, (180 * Math.PI) / 180); // 绘制半圆
    ctx.closePath(); // 结束绘制路径
    ctx.stroke(); // 描边
    ctx.fill(); // 填充
  },
});

2、创建元素

const createBarCodeElement = () => {
  let semicircle = new Semicircle({
    top: 10,
    left: 10,
    stroke: '#7bcfa6', // 描边色
    fill: '#ed5736', // 填充色
    strokeWidth: 10, // 描边宽度
  });

  // 将半圆添加到画布里
  canvasEditor.canvas.add(semicircle);
  canvasEditor.canvas.setActiveObject(semicircle);
};

3、复制这个半圆
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant