Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.small-font.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>OffscreenCanvas test: 2d.text.measure.actualBoundingBox.small-font</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<h1>2d.text.measure.actualBoundingBox.small-font</h1>
<p class="desc">Testing that actualBoundingBox metrics are precise at small font sizes</p>
<script>
promise_test(async t => {
var canvas = new OffscreenCanvas(100, 50);
var ctx = canvas.getContext('2d');
var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')");
f.load();
document.fonts.add(f);
await document.fonts.ready;
ctx.font = '1.5px CanvasTest';
ctx.direction = 'ltr';
ctx.textAlign = 'left';
ctx.textBaseline = 'alphabetic';
// At small font sizes, Skia may store glyph bounds as integers, causing
// loss of precision (crbug.com/479240778). The CanvasTest 'E' glyph fills
// the em square (0, -0.25em) to (1em, 0.75em), so at 1.5px:
// actualBoundingBoxRight ≈ 1.5 (1em)
// actualBoundingBoxAscent ≈ 1.125 (0.75em)
// actualBoundingBoxDescent≈ 0.375 (0.25em)
// With integer quantization these would snap to 2, 2, 1 respectively.
// Use ±0.25 tolerances so quantized values are reliably caught.
var m = ctx.measureText('E');
_assert(m.actualBoundingBoxRight > 1.25, "m.actualBoundingBoxRight > 1.25");
_assert(m.actualBoundingBoxRight < 1.75, "m.actualBoundingBoxRight < 1.75");
_assert(m.actualBoundingBoxAscent > 0.875, "m.actualBoundingBoxAscent > 0.875");
_assert(m.actualBoundingBoxAscent < 1.375, "m.actualBoundingBoxAscent < 1.375");
_assert(m.actualBoundingBoxDescent > 0.125, "m.actualBoundingBoxDescent > 0.125");
_assert(m.actualBoundingBoxDescent < 0.625, "m.actualBoundingBoxDescent < 0.625");
}, "Testing that actualBoundingBox metrics are precise at small font sizes");
</script>