OLD | NEW |
| (Empty) |
1 <html xmlns="http://www.w3.org/1999/xhtml" style="width: 100%; height: 100%;"> | |
2 <body> | |
3 <p>The left edges of the black boxes below should line up with the | |
4 left edges of their containing red or green boxes. In addition, all | |
5 the assertions below should pass.</p> | |
6 | |
7 <div style="width: 800px; height: 200px;"> | |
8 <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"> | |
9 <font> | |
10 <font-face font-family="xyzzy" units-per-em="100" ascent="100" descent="500"> | |
11 </font-face> | |
12 <glyph unicode="BD" d="M0,0 h40 v-80 h-40 z" horiz-adv-x="80"> | |
13 </glyph> | |
14 <glyph unicode="GG" d="M0,0 h20 v-60 h-20 z" horiz-adv-x="70"> | |
15 </glyph> | |
16 <glyph unicode="BB" d="M0,0 h20 v-70 h-20 z" horiz-adv-x="70"> | |
17 </glyph> | |
18 <glyph unicode="B" d="M0,0 h30 v-40 h-30 z" horiz-adv-x="60"> | |
19 </glyph> | |
20 <glyph unicode="D" d="M0,0 h30 v-40 h-30 z" horiz-adv-x="100"> | |
21 </glyph> | |
22 <glyph unicode="G" d="M0,0 h30 v-40 h-30 z" horiz-adv-x="60"> | |
23 </glyph> | |
24 </font> | |
25 <rect x="0" y="10" width="70" height="160" fill="red"/> | |
26 <rect x="70" y="10" width="100" height="150" fill="green"/> | |
27 <rect x="170" y="10" width="70" height="140" fill="red"/> | |
28 <rect x="240" y="10" width="70" height="130" fill="green"/> | |
29 <rect x="310" y="10" width="80" height="120" fill="red"/> | |
30 <rect x="390" y="10" width="60" height="110" fill="green"/> | |
31 <text id="foo" y="10" font-family="xyzzy" font-size="100px" letter-spacing="0px"
word-spacing="0px">GGDGGBBBDB</text> | |
32 </svg> | |
33 </div> | |
34 <pre id="console" /> | |
35 <script> | |
36 <![CDATA[ | |
37 | |
38 function debug(msg) | |
39 { | |
40 var span = document.createElementNS("http://www.w3.org/1999/xhtml", "span"); | |
41 document.getElementById("console").appendChild(span); // insert it first so
XHTML knows the namespace | |
42 span.innerHTML = msg + '<br />'; | |
43 } | |
44 | |
45 function escapeHTML(text) | |
46 { | |
47 return text.replace(/&/g, "&").replace(/</g, "<"); | |
48 } | |
49 | |
50 function testPassed(msg) | |
51 { | |
52 debug('<span><span class="pass">PASS</span> ' + escapeHTML(msg) + '</span>')
; | |
53 } | |
54 | |
55 function testFailed(msg) | |
56 { | |
57 debug('<span><span class="fail">FAIL</span> ' + escapeHTML(msg) + '</span>')
; | |
58 } | |
59 | |
60 function areArraysEqual(_a, _b) | |
61 { | |
62 if (_a.length !== _b.length) | |
63 return false; | |
64 for (var i = 0; i < _a.length; i++) | |
65 if (_a[i] !== _b[i]) | |
66 return false; | |
67 return true; | |
68 } | |
69 | |
70 function isResultCorrect(_actual, _expected) | |
71 { | |
72 if (_actual === _expected) | |
73 return true; | |
74 if (typeof(_expected) == "number" && isNaN(_expected)) | |
75 return typeof(_actual) == "number" && isNaN(_actual); | |
76 if (Object.prototype.toString.call(_expected) == Object.prototype.toString.c
all([])) | |
77 return areArraysEqual(_actual, _expected); | |
78 return false; | |
79 } | |
80 | |
81 function shouldBe(_a, _b) | |
82 { | |
83 if (typeof _a != "string" || typeof _b != "string") | |
84 debug("WARN: shouldBe() expects string arguments"); | |
85 var exception; | |
86 var _av; | |
87 try { | |
88 _av = eval(_a); | |
89 } catch (e) { | |
90 exception = e; | |
91 } | |
92 var _bv = eval(_b); | |
93 | |
94 if (exception) | |
95 testFailed(_a + " should be " + _bv + ". Threw exception " + exception); | |
96 else if (isResultCorrect(_av, _bv)) | |
97 testPassed(_a + " is " + _b); | |
98 else if (typeof(_av) == typeof(_bv)) | |
99 testFailed(_a + " should be " + _bv + ". Was " + _av + "."); | |
100 else | |
101 testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was "
+ _av + " (of type " + typeof _av + ")."); | |
102 } | |
103 | |
104 var t = document.getElementById("foo"); | |
105 shouldBe("t.getStartPositionOfChar(0).x", '0'); | |
106 shouldBe("t.getStartPositionOfChar(1).x", '0'); | |
107 shouldBe("t.getStartPositionOfChar(2).x", '0 + 70'); | |
108 shouldBe("t.getStartPositionOfChar(3).x", '0 + 70 + 100'); | |
109 shouldBe("t.getStartPositionOfChar(4).x", '0 + 70 + 100'); | |
110 shouldBe("t.getStartPositionOfChar(5).x", '0 + 70 + 100 + 70'); | |
111 shouldBe("t.getStartPositionOfChar(6).x", '0 + 70 + 100 + 70'); | |
112 shouldBe("t.getStartPositionOfChar(7).x", '0 + 70 + 100 + 70 + 70'); | |
113 shouldBe("t.getStartPositionOfChar(8).x", '0 + 70 + 100 + 70 + 70'); | |
114 shouldBe("t.getStartPositionOfChar(9).x", '0 + 70 + 100 + 70 + 70 + 80'); | |
115 | |
116 // The end positions of char n must map to the start position of char n-1. | |
117 shouldBe("t.getEndPositionOfChar(0).x", '70'); | |
118 shouldBe("t.getEndPositionOfChar(1).x", '70'); | |
119 shouldBe("t.getEndPositionOfChar(2).x", '70 + 100'); | |
120 shouldBe("t.getEndPositionOfChar(3).x", '70 + 100 + 70'); | |
121 shouldBe("t.getEndPositionOfChar(4).x", '70 + 100 + 70'); | |
122 shouldBe("t.getEndPositionOfChar(5).x", '70 + 100 + 70 + 70'); | |
123 shouldBe("t.getEndPositionOfChar(6).x", '70 + 100 + 70 + 70'); | |
124 shouldBe("t.getEndPositionOfChar(7).x", '70 + 100 + 70 + 70 + 80'); | |
125 shouldBe("t.getEndPositionOfChar(8).x", '70 + 100 + 70 + 70 + 80'); | |
126 shouldBe("t.getEndPositionOfChar(9).x", '70 + 100 + 70 + 70 + 80 + 60'); | |
127 ]]> | |
128 </script> | |
129 </body> | |
130 </html> | |
131 | |
OLD | NEW |