2d.text.measure.text-clusters-position.tentative.worker.js (2004B)
1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. 2 // OffscreenCanvas test in a worker:2d.text.measure.text-clusters-position.tentative 3 // Description:Test that TextMetrics::getTextClusters() returns clusters that are positioned according to the target align and baseline passed as options. 4 // Note: 5 6 importScripts("/resources/testharness.js"); 7 importScripts("/html/canvas/resources/canvas-tests.js"); 8 9 promise_test(async t => { 10 var canvas = new OffscreenCanvas(500, 500); 11 var ctx = canvas.getContext('2d'); 12 13 var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')"); 14 f.load(); 15 self.fonts.add(f); 16 await self.fonts.ready; 17 ctx.font = '40px CanvasTest'; 18 const text = 'E'; 19 20 // Origin for all the measurements is placed at the top left corner. 21 ctx.textAlign = 'left'; 22 ctx.textBaseline = 'top'; 23 let tm = ctx.measureText(text); 24 25 // X position. 26 _assertSame(Math.abs(tm.getTextClusters({align: 'left'})[0].x), 0, "Math.abs(tm.getTextClusters({align: 'left'})[\""+(0)+"\"].x)", "0"); 27 _assertSame(tm.getTextClusters({align: 'center'})[0].x, 20, "tm.getTextClusters({align: 'center'})[\""+(0)+"\"].x", "20"); 28 _assertSame(tm.getTextClusters({align: 'right'})[0].x, 40, "tm.getTextClusters({align: 'right'})[\""+(0)+"\"].x", "40"); 29 30 // Y position. 31 _assertSame(Math.abs(tm.getTextClusters({baseline: 'top'})[0].y), 0, "Math.abs(tm.getTextClusters({baseline: 'top'})[\""+(0)+"\"].y)", "0"); 32 _assertSame(tm.getTextClusters({baseline: 'middle'})[0].y, 20, "tm.getTextClusters({baseline: 'middle'})[\""+(0)+"\"].y", "20"); 33 _assertSame(tm.getTextClusters({baseline: 'bottom'})[0].y, 40, "tm.getTextClusters({baseline: 'bottom'})[\""+(0)+"\"].y", "40"); 34 _assertSame(tm.getTextClusters({baseline: 'alphabetic'})[0].y, 30, "tm.getTextClusters({baseline: 'alphabetic'})[\""+(0)+"\"].y", "30"); 35 }, "Test that TextMetrics::getTextClusters() returns clusters that are positioned according to the target align and baseline passed as options."); 36 done();