Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / svg / text / bidi-getcharnumatpos.html
blob671c1d1c74b9a500ba29adf2ed70df9efbfe7688
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;
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));
27 return charNums;
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")+'.');
40 </script>