Skip to content

fix(TextMetrics): rtl direction + start/end textAlign #2510

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Apr 30, 2025

Thanks for contributing!

  • Have you updated CHANGELOG.md?

closes #2508

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

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

Is there any other test/thing I should add/do?

Copy link
Collaborator

@chearon chearon left a comment

Choose a reason for hiding this comment

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

Thanks and I'm glad to see new tests! Need a couple of changes I think.

it("2d.type class string", function () {
const canvas = createCanvas(100, 50);
const ctx = canvas.getContext("2d");
assert.strictEqual(Object.prototype.toString.call(ctx), '[object CanvasRenderingContext2D]')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did this need to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran npm run generate-wpt - this is outdated code I believe


ctx.textAlign = "left"
metrics = ctx.measureText('hello');
@assert metrics.actualBoundingBoxLeft < metrics.actualBoundingBoxRight;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this goes here. This test is imported from the WPT tests, so it would get overwritten if they did any updates. You should be able to write this in canvas.test.js though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the yaml files generate the js test files. Regardless I saw nothing runs these tests on CI

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

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

I reverted the pwt changes in favor of the jest test and exposed resolveTextAlignment as requested

@@ -2557,6 +2557,20 @@ inline double getBaselineAdjustment(PangoLayout* layout, short baseline) {
}
}

text_align_t
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I expose a strict text align enum?

enum text_align_strict_t : int8_t {
  STRICT_TEXT_ALIGNMENT_LEFT = TEXT_ALIGNMENT_LEFT,
  STRICT_TEXT_ALIGNMENT_CENTER = TEXT_ALIGNMENT_CENTER,
  STRICT_TEXT_ALIGNMENT_RIGHT = TEXT_ALIGNMENT_RIGHT
};

@ShaMan123 ShaMan123 requested a review from chearon May 3, 2025 16:22
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.

[BUG]: measureText not respecting ctx.direction
2 participants