2d.text.measure.selection-rects-baselines.tentative.html (2815B)
1 <!DOCTYPE html> 2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> 3 <meta charset="UTF-8"> 4 <title>Canvas test: 2d.text.measure.selection-rects-baselines.tentative</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/html/canvas/resources/canvas-tests.js"></script> 8 <link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css"> 9 <body class="show_output"> 10 11 <h1>2d.text.measure.selection-rects-baselines.tentative</h1> 12 <p class="desc">Check that TextMetrics::getSelectionRects() works correctly with textBaseline.</p> 13 14 15 <p class="output">Actual output:</p> 16 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 17 18 <ul id="d"></ul> 19 <script> 20 var t = async_test("Check that TextMetrics::getSelectionRects() works correctly with textBaseline."); 21 _addTest(function(canvas, ctx) { 22 23 ctx.font = '50px sans-serif'; 24 25 const kBaselines = [ 26 "top", 27 "hanging", 28 "middle", 29 "alphabetic", 30 "ideographic", 31 "bottom", 32 ]; 33 34 const kTexts = [ 35 'UNAVAILABLE', 36 '🏁🎶🏁', 37 ')(あ)(', 38 '-abcd_', 39 'איפה הספרייה?', 40 'bidiמתמטיקה' 41 ] 42 43 for (const text of kTexts) { 44 for (const baseline of kBaselines) { 45 const tm = ctx.measureText(text); 46 // First character. 47 for (const r of tm.getSelectionRects(0, 1)) { 48 assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0); 49 assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0); 50 } 51 // Last character. 52 for (const r of tm.getSelectionRects(text.length - 1, text.length)) { 53 assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0); 54 assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0); 55 } 56 // Whole string. 57 for (const r of tm.getSelectionRects(0, text.length)) { 58 assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0); 59 assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0); 60 } 61 // Intermediate string. 62 for (const r of tm.getSelectionRects(1, text.length - 1)) { 63 assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0); 64 assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0); 65 } 66 // Invalid start > end string. Creates 0 width rectangle. 67 for (const r of tm.getSelectionRects(3, 2)) { 68 assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0); 69 assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0); 70 } 71 for (const r of tm.getSelectionRects(1, 0)) { 72 assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0); 73 assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0); 74 } 75 } 76 } 77 78 }); 79 </script>