// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. // OffscreenCanvas test in a worker:2d.text.shape.position-to-advance.tentative // Description:Test ShapedText::positionToAdvance() and its symmetry with advanceToPosition() and glyphClusters(). // 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 = '50px CanvasTest'; ctx.direction = 'ltr'; ctx.textAlign = 'left'; ctx.textBaseline = 'alphabetic'; const text = 'ABC'; const st = ctx.shapeText(text); const clusters = st.glyphClusters(); _assertSame(clusters.length, 3, "clusters.length", "3"); assert_approx_equals(st.positionToAdvance(0), 0, 1e-4); assert_approx_equals(st.positionToAdvance(1), clusters[1].x, 1e-4); assert_approx_equals(st.positionToAdvance(2), clusters[2].x, 1e-4); assert_approx_equals(st.positionToAdvance(3), st.width, 1e-4); for (let i = 0; i <= text.length; ++i) { const adv = st.positionToAdvance(i); _assertSame(st.advanceToPosition(adv), i, "st.advanceToPosition(adv)", "i"); } assert_throws_js(TypeError, () => st.positionToAdvance(-1)); assert_throws_dom("IndexSizeError", () => st.positionToAdvance(text.length + 1)); }, "Test ShapedText::positionToAdvance() and its symmetry with advanceToPosition() and glyphClusters()."); done();