96 lines
3.3 KiB
HTML
96 lines
3.3 KiB
HTML
<!--
|
|
// test 77: external SVG fonts, from Erik Dahlstrom
|
|
//
|
|
// SVGFonts are described here[3], and the relevant DOM methods
|
|
// used in the test are defined here[4].
|
|
//
|
|
// Note that in order to be more predictable the svg should be
|
|
// visible, so that clause "For non-rendering environments, the
|
|
// user agent shall make reasonable assumptions about glyph
|
|
// metrics." doesn't influence the results. We use 'opacity:0'
|
|
// to hide the SVG, but arguably it's still a "rendering
|
|
// environment".
|
|
//
|
|
// The font-size 4000 was chosen because that matches the
|
|
// unitsPerEm value in the svgfont, which makes it easy to check
|
|
// the glyph advances since they will then be exactly what was
|
|
// specified in the svgfont.
|
|
//
|
|
// [3] http://www.w3.org/TR/SVG11/fonts.html
|
|
// [4] http://www.w3.org/TR/SVG11/text.html#InterfaceSVGTextContentElement
|
|
-->
|
|
|
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
|
<html>
|
|
<head>
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
</head>
|
|
<body>
|
|
<p id="description"></p>
|
|
<div id="console"></div>
|
|
<script>
|
|
description("Acid3 test 77, checking text metric functionality");
|
|
|
|
if (window.testRunner)
|
|
testRunner.waitUntilDone();
|
|
|
|
var text;
|
|
var iframe;
|
|
|
|
function startTest() {
|
|
iframe = document.createElement("iframe");
|
|
iframe.onload = fontLoaded;
|
|
iframe.src = "resources/Acid3Font-loader.svg";
|
|
document.documentElement.appendChild(iframe);
|
|
}
|
|
|
|
var fontLoaded = function() {
|
|
var svg = iframe.getSVGDocument().documentElement;
|
|
text = iframe.getSVGDocument().getElementsByTagName('text')[0];
|
|
text.textContent = "abc";
|
|
text.setAttribute("y", "1em");
|
|
text.setAttribute("font-size", "4000");
|
|
executeTest();
|
|
}
|
|
|
|
function executeTest() {
|
|
// The font-size 4000 was chosen because that matches the unitsPerEm value in the svgfont,
|
|
// which makes it easy to check the glyph advances since they will then be exactly what was specified in the svgfont.
|
|
shouldBe("text.getNumberOfChars()", "3");
|
|
shouldBe("text.getComputedTextLength()", "4780");
|
|
shouldBe("text.getSubStringLength(0,1)", "44");
|
|
shouldBe("text.getSubStringLength(0,2)", "68");
|
|
shouldBe("text.getSubStringLength(1,1)", "24");
|
|
shouldBe("text.getSubStringLength(1,0)", "0");
|
|
shouldBe("text.getSubStringLength(1, 3)", "4736");
|
|
shouldBe("text.getSubStringLength(0, 4)", "4780");
|
|
shouldThrow("text.getSubStringLength(3, 0)");
|
|
shouldThrow("text.getSubStringLength(-17, 20)");
|
|
shouldBe("text.getStartPositionOfChar(0).x", "0");
|
|
shouldBe("text.getStartPositionOfChar(1).x", "44");
|
|
shouldBe("text.getStartPositionOfChar(2).x", "68");
|
|
shouldBe("text.getStartPositionOfChar(0).y", "4000");
|
|
shouldThrow("text.getEndPositionOfChar(-1)");
|
|
shouldThrow("text.getEndPositionOfChar(4)");
|
|
shouldBe("text.getEndPositionOfChar(0).x", "44");
|
|
shouldBe("text.getEndPositionOfChar(1).x", "68");
|
|
shouldBe("text.getEndPositionOfChar(2).x", "4780");
|
|
shouldThrow("text.getEndPositionOfChar(-17)");
|
|
shouldThrow("text.getEndPositionOfChar(4)");
|
|
|
|
var script = document.createElement('script');
|
|
script.onload = completeTest;
|
|
script.src = "../../resources/js-test-post.js";
|
|
document.body.appendChild(script);
|
|
}
|
|
|
|
function completeTest() {
|
|
if (window.testRunner)
|
|
testRunner.notifyDone();
|
|
}
|
|
|
|
startTest();
|
|
</script>
|
|
</body>
|
|
</html>
|