test_text_2.html (1727B)
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=655877 5 --> 6 <head> 7 <meta charset=UTF-8> 8 <title>Test for Bug 655877</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=655877">Mozilla Bug 655877</a> 14 <p id="display"></p> 15 <div id="content"> 16 <svg width="400" height="200"> 17 <text x="100" y="100" style="font: 16px sans-serif">abc אבג 123 דהו defg</text> 18 </svg> 19 </div> 20 21 <pre id="test"> 22 <script class="testbody" type="application/javascript"> 23 SimpleTest.waitForExplicitFinish(); 24 25 function close(x, y, message) { 26 if (Math.abs(x - y) < 1e-4) { 27 ok(true, message); 28 } else { 29 // Use is() so that the difference is actually printed in the error message 30 is(x, y, message); 31 } 32 } 33 34 function runTest() { 35 var text = document.querySelector("text"); 36 37 // there are only 20 addressable characters 38 is(text.getNumberOfChars(), 20, "getNumberOfChars"); 39 40 var sum, total = text.getComputedTextLength(); 41 42 close(text.getSubStringLength(0, 20), total, "getSubStringLength all"); 43 44 // add the advance of each glyph 45 sum = 0; 46 for (var i = 0; i < 20; i++) { 47 sum += text.getSubStringLength(i, 1); 48 } 49 close(sum, total, "sum getSubStringLength 1"); 50 51 // split the text up into three chunks and add them together 52 close(text.getSubStringLength(0, 6) + 53 text.getSubStringLength(6, 8) + 54 text.getSubStringLength(14, 6), total, "sum getSubStringLength 2"); 55 56 SimpleTest.finish(); 57 } 58 59 window.addEventListener("load", runTest); 60 </script> 61 </pre> 62 </body> 63 </html>