1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
<!DOCTYPE html>
<html lang='en'>
<head>
<title>struct-dom-01-b-manual.svg</title>
<meta charset='utf-8'>
</head>
<body>
<h1>Source SVG: struct-dom-01-b-manual.svg</h1>
<svg version="1.1" baseProfile="basic" onload="domTest(evt)" id="svg-root"
width="100%" height="100%" viewBox="0 0 480 360"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--======================================================================-->
<!--= SVG 1.1 2nd Edition Test Case =-->
<!--======================================================================-->
<!--= Copyright 2009 World Wide Web Consortium, (Massachusetts =-->
<!--= Institute of Technology, European Research Consortium for =-->
<!--= Informatics and Mathematics (ERCIM), Keio University). =-->
<!--= All Rights Reserved. =-->
<!--= See http://www.w3.org/Consortium/Legal/. =-->
<!--======================================================================-->
<title id="test-title">$RCSfile: struct-dom-01-b.svg,v $</title>
<defs>
<font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F">
<font-face-src>
<font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/>
</font-face-src>
</font-face>
</defs>
<g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18">
<script type="text/ecmascript" xlink:href="../resources/testharness.js"></script>
<script type="text/ecmascript"><![CDATA[
function domTest(evt) {
var svg_ns = "http://www.w3.org/2000/svg";
// Get Document
var target = evt.target;
var doc = target.ownerDocument;
//
// Test that our rectangle is an SVGElement instance
//
var rect = doc.getElementById("rectId");
var rootSVG = rect.ownerSVGElement;
var rootId = rootSVG.getAttribute( "id" );
// Insert a new text element to the DOM tree using the id
var newText = doc.createElementNS(svg_ns, 'text');
newText.setAttribute('x', '50');
newText.setAttribute('y', '100');
var message = "This document's root identifier is: " + rootId;
var textContent = doc.createTextNode(message);
newText.appendChild(textContent);
rect.parentNode.appendChild(newText);
//
// Now, check that our rectangle is an instance of SVGRect by accessing
// specific methods in order to get its x, y, width and height attributes.
//
var x = rect.x.baseVal.value; // SVGRect -> SVGAnimatedLenght -> SVGLength -> long
var y = rect.y.baseVal.value;
var width = rect.width.baseVal.value;
var height = rect.height.baseVal.value;
//
// Now, build a new SVGRect through the SVGSVGElement interface.
//
var newRect = doc.createElementNS(svg_ns, 'rect');
//
// Set the x, y, width and height of this element
//
newRect.x.baseVal.value = x + 10;
newRect.y.baseVal.value = y + 10;
newRect.setAttribute("width", width);
newRect.setAttribute("height", height);
//
// Insert new element in DOM tree
//
rect.parentNode.insertBefore(newRect, rect);
//
// Check the pass criteria using the JS framework
//
test(function() {assert_equals(rootId, "svg-root")}, "Assert that the document's root identifier is 'svg-root'.");
test(function() {
assert_true(newRect instanceof SVGRectElement);
assert_equals(newRect.getAttribute('x'), String(x+10));
assert_equals(newRect.getAttribute('y'), String(y+10));
assert_equals(newRect.getAttribute('width'), String(width));
assert_equals(newRect.getAttribute('height'), String(height));
}, "Assert that 'newRect' is replica (ignoring fill) of 'rect' with different x and y.");
}
]]></script>
<!--======================================================================-->
<!-- Since this test is examining the SVG DOM, it could use any language -->
<!-- binding. Here is the equivalent code for the Java binding -->
<!--
//
// Test that our rectangle is an SVGElement instance
//
SVGRectElement rect = (SVGRectElement) doc.getElementById("rectId");
SVGElement rootSVG = rect.getOwnerSVGElement();
String rootId = rootSVG.getId();
// Insert a new text element to the DOM tree using the id
Element newText = doc.createElement("text");
newText.setAttribute("x", "50");
newText.setAttribute("y", "100");
String message = "This document's root identifier is=" " + rootId"
Text textContent = doc.createTextNode(message);
newText.appendChild(textContent);
rect.getParentNode().appendChild(newText);
//
// Now, check that our rectangle is an instance of SVGRect by accessing
// specific methods in order to get its x, y, width and height attributes.
//
float x = rect.getX().getBaseVal().getValue();
float y = rect.getY().getBaseVal().getValue();
float width = rect.getWidth().getBaseVal().getValue();
float height = rect.getHeight().getBaseVal().getValue();
//
// Now, build a new SVGRect through the SVGSVGElement interface.
//
SVGRectElement newRect = (SVGRectElement) doc.createElement("rect");
//
// Set the x, y, width and height of this element
//
newRect.getX().getBaseVal().setValue(x + 10);
newRect.getY().getBaseVal().setValue(y + 10);
newRect.getWidth().getBaseVal().setValue(width);
newRect.getHeight().getBaseVal().setValue(height);
//
// Insert new element in DOM tree
//
alert(newRect)
rect.getParentNode().insertBefore(newRect, rect);
-->
<!-- ===================================================================== -->
<!-- The following rectangle's is accessed in the 'domTest' ECMA Script -->
<!-- handler. -->
<!-- ===================================================================== -->
<rect id="rectId" x="40" y="150" width="50" height="50" fill="green"/>
</g>
<g font-family="SVGFreeSansASCII,sans-serif" font-size="32">
<text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.8 $</text>
</g>
<rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/>
<!-- comment out this watermark once the test is approved -->
<!--<g id="draft-watermark">
<rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/>
<text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240"
text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text>
</g>-->
</svg>
</body>
</html>
|