3 <title>SVGTextContentElement query interface RTL
</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 x=
"0" y=
"50">הפוך
</text>
11 window
.textElement
= document
.querySelector("text");
12 window
.totalExtent
= textElement
.getComputedTextLength();
16 assert_equals(textElement
.textContent
.length
, 4);
18 for (var i
= 0; i
< 4; ++i
)
19 positions
.push(textElement
.getStartPositionOfChar(i
).x
);
21 assert_approx_equals(positions
[0], totalExtent
, 0.5);
22 assert_less_than(positions
[1], positions
[0]);
23 assert_less_than(positions
[2], positions
[1]);
24 assert_less_than(positions
[3], positions
[2]);
25 assert_greater_than(positions
[3], 0);
26 }, document
.title
+', getStartPositionOfChar().');
29 assert_equals(textElement
.textContent
.length
, 4);
31 for (var i
= 0; i
< 4; ++i
)
32 positions
.push(textElement
.getEndPositionOfChar(i
).x
);
34 assert_less_than(positions
[0], totalExtent
);
35 assert_less_than(positions
[1], positions
[0]);
36 assert_less_than(positions
[2], positions
[1]);
37 assert_less_than(positions
[3], positions
[2]);
38 assert_approx_equals(positions
[3], 0, 0.5);
39 }, document
.title
+', getEndPositionOfChar().');
42 assert_equals(textElement
.textContent
.length
, 4);
44 for (var i
= 0; i
< 4; ++i
)
45 bounds
.push(textElement
.getExtentOfChar(i
));
51 // Verify right sides descending.
52 assert_approx_equals(right(bounds
[0]), totalExtent
, 0.5);
53 assert_less_than(right(bounds
[1]), right(bounds
[0]));
54 assert_less_than(right(bounds
[2]), right(bounds
[1]));
55 assert_less_than(right(bounds
[3]), right(bounds
[2]));
56 assert_greater_than(right(bounds
[3]), 0);
58 // Verify left sides descending.
59 assert_less_than(bounds
[0].x
, totalExtent
);
60 assert_less_than(bounds
[1].x
, bounds
[0].x
);
61 assert_less_than(bounds
[2].x
, bounds
[1].x
);
62 assert_less_than(bounds
[3].x
, bounds
[2].x
);
63 assert_approx_equals(bounds
[3].x
, 0, 0.5);
65 // Verify approx. adjacent.
66 assert_approx_equals(bounds
[0].x
, right(bounds
[1]), 0.5);
67 assert_approx_equals(bounds
[1].x
, right(bounds
[2]), 0.5);
68 assert_approx_equals(bounds
[2].x
, right(bounds
[3]), 0.5);
69 }, document
.title
+', getExtentOfChar().');
72 assert_equals(textElement
.textContent
.length
, 4);
75 var queryPoint
= document
.querySelector('svg').createSVGPoint();
78 // Sample left-to-right, expecting a decreasing character number.
79 for (var queryX
= 0.5; queryX
< totalExtent
- 0.5; queryX
+= 0.5) {
80 queryPoint
.x
= queryX
;
81 var offset
= textElement
.getCharNumAtPosition(queryPoint
);
82 assert_less_than_equal(offset
, prevOffset
);
85 assert_equals(prevOffset
, 0);
87 // Sample right-to-left, expecting an increasing character number.
88 for (var queryX
= totalExtent
- 0.5; queryX
>= 0.5; queryX
-= 0.5) {
89 queryPoint
.x
= queryX
;
90 var offset
= textElement
.getCharNumAtPosition(queryPoint
);
91 assert_greater_than_equal(offset
, prevOffset
);
94 assert_equals(prevOffset
, 3);
95 }, document
.title
+', getCharNumAtPosition().');