Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: LayoutTests/svg/text/svgtextcontentelement-glyphqueries-rtl.html

Issue 1041693002: Adjust glyph positions in RTL runs in SVGTextQuery (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More TEs. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset="UTF-8">
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>
8 </svg>
9 <script>
10 setup(function() {
11 window.textElement = document.querySelector("text");
12 window.totalExtent = textElement.getComputedTextLength();
13 });
14
15 test(function() {
16 assert_equals(textElement.textContent.length, 4);
17 var positions = [];
18 for (var i = 0; i < 4; ++i)
19 positions.push(textElement.getStartPositionOfChar(i).x);
20
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().');
27
28 test(function() {
29 assert_equals(textElement.textContent.length, 4);
30 var positions = [];
31 for (var i = 0; i < 4; ++i)
32 positions.push(textElement.getEndPositionOfChar(i).x);
33
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().');
40
41 test(function() {
42 assert_equals(textElement.textContent.length, 4);
43 var bounds = [];
44 for (var i = 0; i < 4; ++i)
45 bounds.push(textElement.getExtentOfChar(i));
46
47 function right(r) {
48 return r.x + r.width;
49 }
50
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);
57
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);
64
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().');
70
71 test(function() {
72 assert_equals(textElement.textContent.length, 4);
73
74 var prevOffset = 3;
75 var queryPoint = document.querySelector('svg').createSVGPoint();
76 queryPoint.y = 40;
77
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);
83 prevOffset = offset;
84 }
85 assert_equals(prevOffset, 0);
86
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);
92 prevOffset = offset;
93 }
94 assert_equals(prevOffset, 3);
95 }, document.title+', getCharNumAtPosition().');
96 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698