OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset="UTF-8"> |
| 3 <title>BiDi getCharNumAtPosition()</title> |
| 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <svg width="50px" height="60px" font-family="Arial" font-size="30px"> |
| 7 <text y="40" direction="ltr">Foo הפוך</text> |
| 8 <text text-anchor="end" y="70" direction="rtl">Foo הפוך</text> |
| 9 </svg> |
| 10 <script> |
| 11 function getExtents(textElement) { |
| 12 var glyphBBoxes = []; |
| 13 for (var i = 0; i < 8; ++i) |
| 14 glyphBBoxes.push(textElement.getExtentOfChar(i)); |
| 15 return glyphBBoxes; |
| 16 } |
| 17 |
| 18 function getCharNums(textElement, glyphBBoxes) { |
| 19 var charNums = []; |
| 20 var point = textElement.ownerSVGElement.createSVGPoint(); |
| 21 for (var i = 0; i < glyphBBoxes.length; ++i) { |
| 22 var bbox = glyphBBoxes[i]; |
| 23 point.x = bbox.x + bbox.width / 2; |
| 24 point.y = bbox.y + bbox.height / 2; |
| 25 charNums.push(textElement.getCharNumAtPosition(point)); |
| 26 } |
| 27 return charNums; |
| 28 } |
| 29 |
| 30 var textElements = document.querySelectorAll("text"); |
| 31 for (var j = 0; j < textElements.length; ++j) { |
| 32 var textElement = textElements[j]; |
| 33 test(function() { |
| 34 assert_equals(textElement.textContent.length, 10); |
| 35 var glyphChars = getCharNums(textElement, getExtents(textElement)); |
| 36 for (var i = 0; i < glyphChars.length; ++i) |
| 37 assert_equals(glyphChars[i], i); |
| 38 }, document.title+', direction='+textElement.getAttribute("direction")+'.'); |
| 39 } |
| 40 </script> |
OLD | NEW |