Rubber-stamped by Brady Eidson.
[webbrowser.git] / LayoutTests / svg / custom / acid3-test-77.html
blob1936d3d66e816ca2481240409b291b091ee9071e
1 <!--
2 // test 77: external SVG fonts, from Erik Dahlstrom
3 //
4 // SVGFonts are described here[3], and the relevant DOM methods
5 // used in the test are defined here[4].
6 //
7 // Note that in order to be more predictable the svg should be
8 // visible, so that clause "For non-rendering environments, the
9 // user agent shall make reasonable assumptions about glyph
10 // metrics." doesn't influence the results. We use 'opacity:0'
11 // to hide the SVG, but arguably it's still a "rendering
12 // environment".
14 // The font-size 4000 was chosen because that matches the
15 // unitsPerEm value in the svgfont, which makes it easy to check
16 // the glyph advances since they will then be exactly what was
17 // specified in the svgfont.
19 // [3] http://www.w3.org/TR/SVG11/fonts.html
20 // [4] http://www.w3.org/TR/SVG11/text.html#InterfaceSVGTextContentElement
21 -->
23 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
24 <html>
25 <head>
26 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
27 <script src="../../fast/js/resources/js-test-pre.js"></script>
28 </head>
29 <body>
30 <p id="description"></p>
31 <div id="console"></div>
32 <script>
33 description("Acid3 test 77, checking text metric functionality");
35 if (window.layoutTestController)
36 layoutTestController.waitUntilDone();
38 var text;
39 var iframe;
41 function startTest() {
42 iframe = document.createElement("iframe");
43 iframe.onload = fontLoaded;
44 iframe.src = "resources/Acid3Font-loader.svg";
45 document.documentElement.appendChild(iframe);
48 var fontLoaded = function() {
49 var svg = iframe.getSVGDocument().documentElement;
50 text = iframe.getSVGDocument().getElementsByTagName('text')[0];
51 text.textContent = "abc";
52 text.setAttribute("y", "1em");
53 text.setAttribute("font-size", "4000");
54 executeTest();
57 function executeTest() {
58 // The font-size 4000 was chosen because that matches the unitsPerEm value in the svgfont,
59 // which makes it easy to check the glyph advances since they will then be exactly what was specified in the svgfont.
60 shouldBe("text.getNumberOfChars()", "3");
61 shouldBe("text.getComputedTextLength()", "4711+42+23");
62 shouldBe("text.getSubStringLength(0,1)", "42");
63 shouldBe("text.getSubStringLength(0,2)", "42+23");
64 shouldBe("text.getSubStringLength(1,1)", "23");
65 shouldBe("text.getSubStringLength(1,0)", "0");
66 shouldBe("text.getSubStringLength(1, 3)", "4734");
67 shouldBe("text.getSubStringLength(0, 4)", "4776");
68 shouldThrow("text.getSubStringLength(3, 0)");
69 shouldThrow("text.getSubStringLength(-17, 20)");
70 shouldBe("text.getStartPositionOfChar(0).x", "0");
71 shouldBe("text.getStartPositionOfChar(1).x", "42");
72 shouldBe("text.getStartPositionOfChar(2).x", "42+23");
73 shouldBe("text.getStartPositionOfChar(0).y", "4000");
74 shouldThrow("text.getEndPositionOfChar(-1)");
75 shouldThrow("text.getEndPositionOfChar(4)");
76 shouldBe("text.getEndPositionOfChar(0).x", "42");
77 shouldBe("text.getEndPositionOfChar(1).x", "42+23");
78 shouldBe("text.getEndPositionOfChar(2).x", "42+23+4711");
79 shouldThrow("text.getEndPositionOfChar(-17)");
80 shouldThrow("text.getEndPositionOfChar(4)");
82 var script = document.createElement('script');
83 script.onload = completeTest;
84 script.src = "../../fast/js/resources/js-test-post.js";
85 successfullyParsed = true;
86 document.body.appendChild(script);
89 function completeTest() {
90 if (window.layoutTestController)
91 layoutTestController.notifyDone();
94 startTest();
95 </script>
96 </body>
97 </html>