test_text_2.html 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 type="application/javascript" 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">
  18. abc אבג 123 דהו defg
  19. </text>
  20. </svg>
  21. </div>
  22. <pre id="test">
  23. <script class="testbody" type="application/javascript">
  24. SimpleTest.waitForExplicitFinish();
  25. function close(x, y, message) {
  26. ok(Math.abs(x - y) < 1e-4, message);
  27. }
  28. function runTest() {
  29. var text = document.querySelector("text");
  30. // there are only 20 addressable characters
  31. is(text.getNumberOfChars(), 20, "getNumberOfChars");
  32. var sum, total = text.getComputedTextLength();
  33. close(text.getSubStringLength(0, 20), total, "getSubStringLength all");
  34. // add the advance of each glyph
  35. sum = 0;
  36. for (var i = 0; i < 20; i++) {
  37. sum += text.getSubStringLength(i, 1);
  38. }
  39. close(total, sum, "sum getSubStringLength 1");
  40. // split the text up into three chunks and add them together
  41. close(total, text.getSubStringLength(0, 6) +
  42. text.getSubStringLength(6, 8) +
  43. text.getSubStringLength(14, 6), "sum getSubStringLength 2");
  44. SimpleTest.finish();
  45. }
  46. window.addEventListener("load", runTest, false);
  47. </script>
  48. </pre>
  49. </body>
  50. </html>