8 -webkit-writing-mode:vertical-lr;
11 -webkit-writing-mode:vertical-rl;
14 <p title=
"LTR"><span>12 345 6789</span></p>
15 <p title=
"RTL" dir=rtl
><span>12 345 6789</span></p>
16 <p title=
"VERTICAL-LR" class=vlr
><span>12 345 6789</span></p>
17 <p title=
"VERTICAL-RL" class=vrl
><span>12 345 6789</span></p>
20 Array
.prototype.forEach
.call(document
.querySelectorAll("p"), function (e
) {
21 testOffsetFromPoint(e
.firstChild
, e
.title
);
22 e
.style
.textRendering
= "optimizeLegibility";
23 testOffsetFromPoint(e
.firstChild
, e
.title
+ " (Complex Path)");
26 function testOffsetFromPoint(element
, name
) {
27 var writingMode
= getComputedStyle(element
).webkitWritingMode
;
28 var isVertical
= writingMode
&& writingMode
[0] == "v";
29 var results
= [ name
];
30 getOffsetFromPoint(element
, isVertical
, results
);
31 if (isVertical
) // The last character in vertical is flaky by win/mac/linux
32 results
.splice(-1, 1);
33 for (var result
of results
) {
34 var div
= document
.createElement("div");
35 div
.innerText
= result
;
40 function getOffsetFromPoint(element
, isVertical
, results
) {
42 var x
= element
.offsetLeft
+ element
.offsetWidth
/ 2;
43 var ymin
= element
.offsetTop
;
44 var width
= element
.offsetHeight
;
46 var y
= element
.offsetTop
+ element
.offsetHeight
/ 2;
47 var xmin
= element
.offsetLeft
;
48 width
= element
.offsetWidth
;
50 var lastCharacterOffset
= null;
51 var lastPosition
= null;
52 for (var position
= -1; position
<= width
+ 1; ++position
) {
57 var result
= document
.caretRangeFromPoint(x
, y
);
58 var characterOffset
= result
? result
.startOffset
: null;
59 if (characterOffset
=== lastCharacterOffset
)
61 var advance
= position
- lastPosition
;
62 results
.push(characterOffset
+ "=" + position
+ " (" + advance
+ ")");
63 lastCharacterOffset
= characterOffset
;
64 lastPosition
= position
;
69 if (window
.testRunner
)
70 testRunner
.dumpAsText();