Skip to content

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

Merged
chearon merged 6 commits intoAutomattic:masterfrom
ShaMan123:fix/rtl-text-metrics
Jun 16, 2025
Merged

fix(TextMetrics): rtl direction + start/end textAlign#2510
chearon merged 6 commits intoAutomattic:masterfrom
ShaMan123:fix/rtl-text-metrics

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

}
}

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
@ShaMan123
Copy link
Contributor Author

@chearon ?

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.

Looks great!

@chearon chearon merged commit 772c464 into Automattic:master Jun 16, 2025
13 checks passed
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