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

字号大小和文本框拖拽可以联动变化吗 #298

Open
aa2246740 opened this issue Dec 19, 2023 · 1 comment
Open

字号大小和文本框拖拽可以联动变化吗 #298

aa2246740 opened this issue Dec 19, 2023 · 1 comment
Labels
question Further information is requested

Comments

@aa2246740
Copy link

大佬你好,当一个文本框拖拽的时候,里面的文本也会一起发生大小的变化,但是右侧的文本框却无法变化
这个有办法解嘛? 跟其他同类产品一样文本框拖拽可以使得他的字体大小变化,字体大小变化也可以影响文本框大小变化

@panjianning
Copy link

拖拽时是改变的是scaleX和scaleY, fontSize不变。 可以监听object:modified事件,将文本的scaleX和scaleY设回1,fontSize *= scaleX

const updateTextSize = (obj) => {
 //  obj.target.type.indexOf('text')!=-1
  if (obj && obj.action == 'scale' && obj.target && obj.target.type == 'i-text') {
    let textObj = obj.target
    if (textObj.scaleX != 1 || textObj.scaleY != 1) {
      let scale = Math.max(textObj.scaleX, textObj.scaleY)
      textObj.set({
        fontSize: Math.floor(textObj.fontSize * scale),
        scaleX: 1,
        scaleY: 1,
      });
      canvasEditor.canvas.fire("object:modified", textObj)
    }
  }
};
canvasEditor.canvas.on('object:modified', updateTextSize);

@nihaojob nihaojob added the question Further information is requested label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants