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

Add more whitespace subtests #49567

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ <h1>2d.text.measure.actualBoundingBox.whitespace</h1>
// Values that are nominally expected to be zero might actually vary by a
// pixel or so if the UA accounts for antialiasing at glyph edges, so we
// allow a slight deviation.
_assert(Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1");
_assert(ctx.measureText('A ').actualBoundingBoxRight >= 50, "ctx.measureText('A ').actualBoundingBoxRight >= 50");
var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000];
for (var codepoint of whitespaces) {
let whitespace = String.fromCharCode(codepoint);

_assert(Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49");
_assert(ctx.measureText(' A').actualBoundingBoxRight <= 101, "ctx.measureText(' A').actualBoundingBoxRight <= 101");
_assert(Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1");
_assert(ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50, "ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50");

_assert(Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49");
_assert(ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101, "ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101");
}

}, "Testing actualBoundingBox with leading/trailing whitespace");
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ <h1>2d.text.measure.actualBoundingBox.whitespace</h1>
// Values that are nominally expected to be zero might actually vary by a
// pixel or so if the UA accounts for antialiasing at glyph edges, so we
// allow a slight deviation.
_assert(Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1");
_assert(ctx.measureText('A ').actualBoundingBoxRight >= 50, "ctx.measureText('A ').actualBoundingBoxRight >= 50");
var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000];
for (var codepoint of whitespaces) {
let whitespace = String.fromCharCode(codepoint);

_assert(Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49");
_assert(ctx.measureText(' A').actualBoundingBoxRight <= 101, "ctx.measureText(' A').actualBoundingBoxRight <= 101");
_assert(Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1");
_assert(ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50, "ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50");

_assert(Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49");
_assert(ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101, "ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101");
}

}, "Testing actualBoundingBox with leading/trailing whitespace");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ promise_test(async t => {
// Values that are nominally expected to be zero might actually vary by a
// pixel or so if the UA accounts for antialiasing at glyph edges, so we
// allow a slight deviation.
_assert(Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1");
_assert(ctx.measureText('A ').actualBoundingBoxRight >= 50, "ctx.measureText('A ').actualBoundingBoxRight >= 50");
var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000];
for (var codepoint of whitespaces) {
let whitespace = String.fromCharCode(codepoint);

_assert(Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49");
_assert(ctx.measureText(' A').actualBoundingBoxRight <= 101, "ctx.measureText(' A').actualBoundingBoxRight <= 101");
_assert(Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1");
_assert(ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50, "ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50");

_assert(Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49");
_assert(ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101, "ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101");
}
}, "Testing actualBoundingBox with leading/trailing whitespace");
done();
13 changes: 9 additions & 4 deletions html/canvas/tools/yaml-new/text.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1097,11 +1097,16 @@
// Values that are nominally expected to be zero might actually vary by a
// pixel or so if the UA accounts for antialiasing at glyph edges, so we
// allow a slight deviation.
@assert Math.abs(ctx.measureText('A ').actualBoundingBoxLeft) <= 1;
@assert ctx.measureText('A ').actualBoundingBoxRight >= 50;
var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000];
for (var codepoint of whitespaces) {
let whitespace = String.fromCharCode(codepoint);

@assert Math.abs(ctx.measureText(' A').actualBoundingBoxLeft) >= 49;
@assert ctx.measureText(' A').actualBoundingBoxRight <= 101;
@assert Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1;
@assert ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50;

@assert Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49;
@assert ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101;
}
variants:
- *load-font-variant-definition

Expand Down