OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Text queries on elements with collapsed whitespace</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <svg> |
| 6 <text transform="translate(0 20)">A B C</text> |
| 7 <text transform="translate(0 40)">A <tspan>B</tspan> C</text> |
| 8 <text transform="translate(0 60)"> A B C </text> |
| 9 <text transform="translate(0 80)"> A <tspan> B C </tspan> </text> |
| 10 <text transform="translate(0 100)"> <tspan> A B </tspan> C </text> |
| 11 <text transform="translate(0 120)"> A <tspan> B </tspan> C </text> |
| 12 </svg> |
| 13 <script> |
| 14 setup(function() { |
| 15 window.textElements = document.getElementsByTagName('text'); |
| 16 var referenceElement = textElements[0]; |
| 17 window.reference = []; |
| 18 for (var i = 0; i < 5; ++i) |
| 19 reference.push(referenceElement.getExtentOfChar(i)); |
| 20 }); |
| 21 |
| 22 test(function() { |
| 23 for (var j = 1; j < textElements.length; ++j) { |
| 24 var element = textElements[j]; |
| 25 assert_equals(element.getNumberOfChars(), 5, 'collapsed length'); |
| 26 |
| 27 for (var i = 0; i < 5; ++i) { |
| 28 var extents = element.getExtentOfChar(i); |
| 29 for (var attr of ['x', 'y', 'width', 'height']) |
| 30 assert_equals(extents[attr], reference[i][attr], 'same extents a
s reference (' + attr + ')'); |
| 31 } |
| 32 |
| 33 var queryPoint = element.ownerSVGElement.createSVGPoint(); |
| 34 for (var i = 0; i < 5; ++i) { |
| 35 queryPoint.x = reference[i].x + reference[i].width / 2; |
| 36 queryPoint.y = reference[i].y + reference[i].height / 2; |
| 37 assert_equals(element.getCharNumAtPosition(queryPoint), i, 'at same
position as reference'); |
| 38 } |
| 39 } |
| 40 }); |
| 41 </script> |
OLD | NEW |