Skip to content

Conversation

Ovilia
Copy link
Member

@Ovilia Ovilia commented Sep 3, 2025

This PR fixes the following problems with parseText:

  1. When the space is at the end of a line and it will exceeds container width after appeding the space to the current line, the current behavior is to display the space at the beginning of the next line, which is not probably not expected by users. So this PR makes sure the next line won't have a space at the begining.

But this doesn't apply to the situation if the space is the first character of the first line, or when there are multiple spaces, where we preserver the space because we think this is expected by developers since they intentionally added these spaces.

  1. There are some punctuations that are not expected to be displayed at the begining of a line. Before this PR, we may see characters like ), , ?`` be displayed at the begining of a line. This PR fixes this problem by moving the currentWord` or the last non-prohibited character to the next line.

Check the test file test/text-overflow-2.html. The red texts are with CSS while the blue ones are with ZRender. CSS takes special care for letter spacing dynamically, so in some cases, we may find there is a few difference with ZRender, which is acceptable.

The result of this PR is not aligned with CSS behaviors in that:

  • Starting and trailing spaces are removed in CSS; we perserve the spaces at the begining for a line
  • Multiple spaces are displayed as a single space in CSS; we persever the multiple spaces and if they exceeds the container width, at most one space is removed
  • Sequencial prohibited starting characters may cause overflowing the container width in CSS; we make sure it doesn't exceeds container width
image

@Ovilia Ovilia changed the title test(text): test space and punct fix(text): fix parseText with space and punctuation Sep 3, 2025
@ecomfe ecomfe deleted a comment from Jancheng-z Sep 3, 2025
@Ovilia Ovilia marked this pull request as ready for review September 4, 2025 09:44
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

Successfully merging this pull request may close these issues.

1 participant