Skip to content

Commit

Permalink
Add more whitespace subtests (#49567)
Browse files Browse the repository at this point in the history
Add more kinds of leading/trailing whitespace subtests to verify the effects on actualBoundingBoxLeft/actualBoundingBoxRight text metrics.
  • Loading branch information
rwlbuis authored Dec 6, 2024
1 parent f1beae8 commit b07d03b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
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

0 comments on commit b07d03b

Please sign in to comment.