From 4227ea967c0fec24b6a737e8298812675a6e73c4 Mon Sep 17 00:00:00 2001 From: Rob Buis Date: Fri, 6 Dec 2024 14:27:01 +0000 Subject: [PATCH] Add more whitespace subtests Add more kinds of leading/trailing whitespace subtests to verify the effects on actualBoundingBoxLeft/actualBoundingBoxRight text metrics. --- ...d.text.measure.actualBoundingBox.whitespace.html | 13 +++++++++---- ...d.text.measure.actualBoundingBox.whitespace.html | 13 +++++++++---- ...t.measure.actualBoundingBox.whitespace.worker.js | 13 +++++++++---- html/canvas/tools/yaml-new/text.yaml | 13 +++++++++---- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.html b/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.html index 29f25f502d7d80..1e389a19264b63 100644 --- a/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.html +++ b/html/canvas/element/text/2d.text.measure.actualBoundingBox.whitespace.html @@ -38,11 +38,16 @@

2d.text.measure.actualBoundingBox.whitespace

// 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"); diff --git a/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.html b/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.html index e9bed7dcefd3bf..5895e6360a0725 100644 --- a/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.html +++ b/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.html @@ -28,11 +28,16 @@

2d.text.measure.actualBoundingBox.whitespace

// 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"); diff --git a/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.js b/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.js index b588b6e68f85d1..e3b74443e42fce 100644 --- a/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.js +++ b/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.whitespace.worker.js @@ -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(); diff --git a/html/canvas/tools/yaml-new/text.yaml b/html/canvas/tools/yaml-new/text.yaml index db2d5380dd81f2..38630509bf2f79 100644 --- a/html/canvas/tools/yaml-new/text.yaml +++ b/html/canvas/tools/yaml-new/text.yaml @@ -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