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