// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.text.measure.actualBoundingBox.small-font // Description:Testing that actualBoundingBox metrics are precise at small font sizes // Note: importScripts("/resources/testharness.js"); importScripts("/html/canvas/resources/canvas-tests.js"); 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(); self.fonts.add(f); await self.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"); done();