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