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

[Bug]: textAlign property not working as expected #10454

Open
7 tasks done
jerryzhangjq opened this issue Feb 28, 2025 · 2 comments
Open
7 tasks done

[Bug]: textAlign property not working as expected #10454

jerryzhangjq opened this issue Feb 28, 2025 · 2 comments

Comments

@jerryzhangjq
Copy link

jerryzhangjq commented Feb 28, 2025

CheckList

  • I agree to follow this project's Code of Conduct
  • I have read and followed the Contributing Guide
  • I have read and followed the Issue Tracker Guide
  • I have searched and referenced existing issues and discussions
  • I am filing a BUG report.
  • I have managed to reproduce the bug after upgrading to the latest version
  • I have created an accurate and minimal reproduction

Version

6.0.2

In What environments are you experiencing the problem?

No response

Node Version (if applicable)

None

Link To Reproduction

Steps To Reproduce

I am trying to set the textAlign property on a fabric.Text object, but it does not seem to have any effect. Here is my code:
`const canvas = new fabric.Canvas('canvas');

  // 创建文本框
  const text = new fabric.Textbox(
    '这是一段示例文本,用于测试两端对齐,这是一段示例文本,用于测试两端对齐,这是一段示例文本,用于测试两端对齐,这是一段示例文本,用于测试两端对齐,这是一段示例文本,用于测试两端对齐',
    {
      width: 420, // 文本框宽度
      fontSize: 20,
      fontFamily: 'Arial',
      fill: '#333',
      textAlign: 'justify-left', // 最后一行左对齐
      lineHeight: 1.5,
      splitByGrapheme: true,
    }
  );

  // 将文本框添加到画布
  canvas.add(text);`

Expected Behavior

I want like this In photoShop

set left

Image

set justify

Image

Actual Behavior

Without justified alignment for the previous lines

Image

This is the case in the canva.com
Image

Error Message & Stack Trace

@GrammyLi
Copy link

Image

  const addTextBox = (option, size = 80) => {
    return new fabric.Textbox(t('addElement.everythingGoesWell'), {
      ...defaultPosition,
      ...option,
      splitByGrapheme: true,
      paintFirst: 'stroke',
      width: 400,
      fontSize: size,
      fill: '#000000FF',
      id: uuid(),
      textAlign: 'justify', // 设置文本两端对齐
    });
  };

我这里也是 textAlign 设置 justify, 明明两端对齐,咋和 “left” 效果一样,

文档上:

Image

this "justify" or "left", set tetAlign, rendering common,

@GrammyLi
Copy link

下面这快图的是可以的

https://ikuaitu.github.io/vue-fabric-editor/#/

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

2 participants