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

Fix measure text width error #2171

Merged

Conversation

singlecoder
Copy link
Member

@singlecoder singlecoder commented Jul 12, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Improved text width calculation for more accurate text layout.
    • Adjusted test cases to better align with updated text rendering metrics.
  • Refactor

    • Updated internal methods for measuring text dimensions, enhancing precision.
  • Tests

    • Updated test cases to reflect changes in text measurement logic and bounding box coordinates.

@singlecoder singlecoder added this to the 1.2 milestone Jul 12, 2024
@singlecoder singlecoder requested a review from GuoLei1990 July 12, 2024 09:05
@singlecoder singlecoder self-assigned this Jul 12, 2024
Copy link

coderabbitai bot commented Jul 12, 2024

Walkthrough

The recent updates to the text measuring logic in TextUtils aim to improve text layout accuracy by utilizing more precise metrics. These enhancements include changes to the text width calculation and adjustments to test cases to ensure correctness in rendering and measuring text in various scenarios.

Changes

File Path Summary
packages/core/src/2d/text/TextUtils.ts Updated text width calculation for improved accuracy; Modified _measureFontOrChar to handle more precise metrics.
tests/src/core/2d/text/TextRenderer.test.ts Adjusted x-coordinate values in bounding box tests for text rendering.
tests/src/core/2d/text/TextUtils.test.ts Updated expected text line arrays and line width values in test cases to match improved text measurement logic.

Sequence Diagram(s)

Poem

In code's quiet realm, a change was made,
To measure text with the utmost precision.
Fonts now dance with accuracy displayed,
Rendering improved, a coder's vision.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@singlecoder singlecoder linked an issue Jul 12, 2024 that may be closed by this pull request
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ae79e6c and aa55f45.

Files selected for processing (1)
  • packages/core/src/2d/text/TextUtils.ts (1 hunks)
Additional comments not posted (1)
packages/core/src/2d/text/TextUtils.ts (1)

354-355: Improved accuracy in text width calculation.

The new implementation uses textMetrics.actualBoundingBoxRight - textMetrics.actualBoundingBoxLeft for a more precise width calculation, which is an improvement over the previous context.measureText(measureString).width.

@jtabibito
Copy link
Contributor

Need to consider the issues of white spaces and character spacing.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aa55f45 and 85705c4.

Files selected for processing (3)
  • packages/core/src/2d/text/TextUtils.ts (1 hunks)
  • tests/src/core/2d/text/TextRenderer.test.ts (3 hunks)
  • tests/src/core/2d/text/TextUtils.test.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • tests/src/core/2d/text/TextRenderer.test.ts
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/2d/text/TextUtils.ts
Additional comments not posted (11)
tests/src/core/2d/text/TextUtils.test.ts (11)

136-136: Update expected result for measureTextWithWrap test case.

The change in the expected result to ['T', 'h', 'e ', 'w', 'e', 'at', 'h', 'er', 'is ', 'gr', 'e', 'at', 'to', 'd', 'a', 'y.'] aligns with the refined text measurement logic in TextUtils.


142-142: Update expected result for measureTextWithWrap test case.

The change in the expected result to ['阳', '光', '明', '媚', ',t', 'h', 'e ', 'w', 'e', 'at', 'h', 'er', 'is ', 'gr', 'e', 'at', 'to', 'd', 'a', 'y。'] aligns with the refined text measurement logic in TextUtils.


148-148: Update expected result for measureTextWithWrap test case.

The change in the expected result to [' ', ' ', 'W', 'or', 'ld'] aligns with the refined text measurement logic in TextUtils.


211-211: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [478] aligns with the refined text measurement logic in TextUtils.


218-218: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [292] aligns with the refined text measurement logic in TextUtils.


225-225: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [393] aligns with the refined text measurement logic in TextUtils.


232-232: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [63, 112] aligns with the refined text measurement logic in TextUtils.


263-263: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [478] aligns with the refined text measurement logic in TextUtils.


270-270: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [292] aligns with the refined text measurement logic in TextUtils.


277-277: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [393] aligns with the refined text measurement logic in TextUtils.


284-284: Update expected result for measureTextWithoutWrap test case.

The change in the expected result to [63, 112] aligns with the refined text measurement logic in TextUtils.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 85705c4 and 586280d.

Files selected for processing (1)
  • packages/core/src/2d/text/TextUtils.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/2d/text/TextUtils.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 586280d and 360a178.

Files selected for processing (1)
  • packages/core/src/2d/text/TextUtils.ts (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/2d/text/TextUtils.ts

@GuoLei1990 GuoLei1990 merged commit de62de6 into galacean:main Jul 15, 2024
6 checks passed
@GuoLei1990 GuoLei1990 added bug Something isn't working text 2D text system labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working text 2D text system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When rendering italic text, the pixels are being clipped
3 participants