| 1 |
<svg version="1.1" baseProfile="full" onload="testSVGTextContentElement()" id="svg-root" |
| 2 |
width="100%" height="100%" viewBox="0 0 480 360" |
| 3 |
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 4 |
<!--======================================================================--> |
| 5 |
<!--= SVG 1.1 2nd Edition Test Case =--> |
| 6 |
<!--======================================================================--> |
| 7 |
<!--= Copyright 2009 World Wide Web Consortium, (Massachusetts =--> |
| 8 |
<!--= Institute of Technology, European Research Consortium for =--> |
| 9 |
<!--= Informatics and Mathematics (ERCIM), Keio University). =--> |
| 10 |
<!--= All Rights Reserved. =--> |
| 11 |
<!--= See http://www.w3.org/Consortium/Legal/. =--> |
| 12 |
<!--======================================================================--> |
| 13 |
<d:SVGTestCase xmlns:d="http://www.w3.org/2000/02/svg/testsuite/description/" |
| 14 |
template-version="1.4" reviewer="[reviewer]" author="AN" status="created" |
| 15 |
version="$Revision: 1.4 $" testname="$RCSfile: text-dom-01-f.svg,v $"> |
| 16 |
<d:testDescription xmlns="http://www.w3.org/1999/xhtml" href="http://www.w3.org/TR/SVG11/text.html#DOMInterfaces"> |
| 17 |
<p> |
| 18 |
This tests the methods and properties of the SVGTextContentElement interface on the text element with the id 'testText' |
| 19 |
and the content 'This is a test of the interface SVGTextContentElement'. The word 'is' has two glyphs with different |
| 20 |
rotation values defined with a <tspan/> element. There are 12 subtests testing the 9 methods and 2 properties. |
| 21 |
Note that the numeric results of some methods may vary. The additional instructions state where the result may vary |
| 22 |
and where it should have an exact value. |
| 23 |
</p> |
| 24 |
</d:testDescription> |
| 25 |
<d:operatorScript xmlns="http://www.w3.org/1999/xhtml"> |
| 26 |
<p> |
| 27 |
[[ |
| 28 |
Describe how to use the here. The instructions should specify any |
| 29 |
steps requied to run the test or any manual operation that need |
| 30 |
to be performed to run the test. |
| 31 |
]] |
| 32 |
</p> |
| 33 |
</d:operatorScript> |
| 34 |
<d:passCriteria xmlns="http://www.w3.org/1999/xhtml"> |
| 35 |
<p> |
| 36 |
The first subtest is testing the method .getCharNumAtPosition(svgPt), where svgPt has an x value of 240 and y value of 25. |
| 37 |
The result of this subtest must be "30". |
| 38 |
</p> |
| 39 |
<p> |
| 40 |
The second subtest is testing the method .getComputedTextLength(). The rounded result may vary in the implementations but should be around 364. |
| 41 |
A red line below the testText is visually indicating the result of the method .getComputedTextLength() and must look like a red underline |
| 42 |
with a length that spans the whole text length from 'T' to '.'. |
| 43 |
</p> |
| 44 |
<p> |
| 45 |
The third subtest is testing the method .getEndPositionOfChar() at the 11th character ('e'). |
| 46 |
The rounded result may vary in the implementations but should be around 131 for the 'x' value and must be 30 for the 'y' value. |
| 47 |
Additionally, a red vertical line is indicating the end position of the character 'e'. Its lower 'y' value must be at 30 |
| 48 |
and the 'x' values must match the end position of the 11th character 'e'. |
| 49 |
</p> |
| 50 |
<p> |
| 51 |
The fourth subtest is testing the method .getExtentOfChar() at the 11th character ('e'). |
| 52 |
The rounded result may vary in the implementations but should be around '123,16,8,17' for the 'x,y,width,height' values. |
| 53 |
A lightblue rectangle below the character 'e' must fully enclose the 11th glyph. |
| 54 |
</p> |
| 55 |
<p> |
| 56 |
The fifth subtest is testing the method .getNumberOfChars(). The result must be 54. |
| 57 |
</p> |
| 58 |
<p> |
| 59 |
The sixth subtest is testing the method .getRotationOfChar() for the fifth character. The result must be 45. |
| 60 |
Additionally, a lightblue rectangle below the text indicates the extent of the fifth glyph 'i'. |
| 61 |
It must fully enclose the diagonally rotated fifth glyph 'i'. |
| 62 |
</p> |
| 63 |
<p> |
| 64 |
The seventh subtest is testing the method .getStartPositionOfChar() at the 11th character ('e'). |
| 65 |
The rounded result may vary in the implementations but should be around 123 for the 'x' value and must be 30 for the 'y' value. |
| 66 |
Additionally, a red vertical line is indicating the start position of the character 'e'. Its lower 'y' value must be at 30 |
| 67 |
and the 'x' values must match the end position of the 11th character 'e'. |
| 68 |
</p> |
| 69 |
<p> |
| 70 |
The eighth subtest is testing the method .getSubStringLength(), starting at character 22 and including the 9 following characters. |
| 71 |
The result may vary in the implementations but should be around 58. Additionally, a green (lime) line visually indicates |
| 72 |
the result of the method. The word 'interface' must be fully underlined with the green line. |
| 73 |
</p> |
| 74 |
<p> |
| 75 |
The ninth subtest is testing the method .selectSubString(). After loading the file, the word "the" must be selected. |
| 76 |
</p> |
| 77 |
<p> |
| 78 |
The tenth subtest is testing the property .textLength. The rounded result of .textLength.baseVal.value may vary in |
| 79 |
the implementations but should be around 364. |
| 80 |
It must match the value calculated in the second subtest (.getComputedTextLength()). |
| 81 |
</p> |
| 82 |
<p> |
| 83 |
The eleventh subtest is again testing the property .textLength. The rounded result of .textLength.animVal.value may vary in |
| 84 |
the implementations but should be around 364. |
| 85 |
It must match the value calculated in the second subtest (.getComputedTextLength()). |
| 86 |
</p> |
| 87 |
<p> |
| 88 |
The twelfth subtest is again testing the property .lengthAdjust. The results of .lengthAdjust.baseVal and |
| 89 |
.lengthAdjust.animVal must be 1 and 1. |
| 90 |
</p> |
| 91 |
</d:passCriteria> |
| 92 |
</d:SVGTestCase> |
| 93 |
<title id="test-title">$RCSfile: text-dom-01-f.svg,v $</title> |
| 94 |
<defs> |
| 95 |
<font-face font-family="SVGFreeSansASCII" unicode-range="U+0-7F"> |
| 96 |
<font-face-src> |
| 97 |
<font-face-uri xlink:href="../resources/SVGFreeSans.svg#ascii"/> |
| 98 |
</font-face-src> |
| 99 |
</font-face> |
| 100 |
</defs> |
| 101 |
<g id="test-body-content" font-family="SVGFreeSansASCII,sans-serif" font-size="18"> |
| 102 |
<script type="text/ecmascript"><![CDATA[ |
| 103 |
function testSVGTextContentElement() { |
| 104 |
var svgNS = "http://www.w3.org/2000/svg"; |
| 105 |
var tContentEl = document.getElementById("testText"); |
| 106 |
var textGroup = document.getElementById("textGroup"); |
| 107 |
var svgPt = document.documentElement.createSVGPoint(); |
| 108 |
svgPt.x = 240; |
| 109 |
svgPt.y = 25; |
| 110 |
|
| 111 |
//1: testing .getCharNumAtPosition() |
| 112 |
var charNumresult = tContentEl.getCharNumAtPosition(svgPt); |
| 113 |
document.getElementById("text1").firstChild.data = ".getCharNumAtPosition() result: "+charNumresult; |
| 114 |
|
| 115 |
//2: testing .getCharNumAtPosition() |
| 116 |
var compTextLength = tContentEl.getComputedTextLength(); |
| 117 |
document.getElementById("text2").firstChild.data = ".getComputedTextLength() result: "+Math.round(compTextLength); |
| 118 |
var baseLine = document.createElementNS(svgNS,"line"); |
| 119 |
baseLine.setAttributeNS(null,"stroke","red"); |
| 120 |
baseLine.setAttributeNS(null,"x1",(240 - compTextLength * 0.5)); |
| 121 |
baseLine.setAttributeNS(null,"x2",(240 + compTextLength * 0.5)); |
| 122 |
baseLine.setAttributeNS(null,"y1",30); |
| 123 |
baseLine.setAttributeNS(null,"y2",30); |
| 124 |
textGroup.insertBefore(baseLine,tContentEl); |
| 125 |
|
| 126 |
//3: testing .getEndPositionOfChar(), end of character |
| 127 |
var endPosChar = tContentEl.getEndPositionOfChar(11); |
| 128 |
document.getElementById("text3").firstChild.data = ".getEndPositionOfChar(11) result ('e'): "+Math.round(endPosChar.x)+","+Math.round(endPosChar.y); |
| 129 |
var endPosLine = document.createElementNS(svgNS,"line"); |
| 130 |
endPosLine.setAttributeNS(null,"stroke","red"); |
| 131 |
endPosLine.setAttributeNS(null,"x1",endPosChar.x); |
| 132 |
endPosLine.setAttributeNS(null,"x2",endPosChar.x); |
| 133 |
endPosLine.setAttributeNS(null,"y1",endPosChar.y); |
| 134 |
endPosLine.setAttributeNS(null,"y2",endPosChar.y-15); |
| 135 |
textGroup.insertBefore(endPosLine,tContentEl); |
| 136 |
|
| 137 |
//4: testing getExtentOfChar |
| 138 |
var charExtent = tContentEl.getExtentOfChar(11); |
| 139 |
document.getElementById("text4").firstChild.data = ".getExtentOfChar(11) result ('e'): "+Math.round(charExtent.x)+","+Math.round(charExtent.y)+","+Math.round(charExtent.width)+","+Math.round(charExtent.height); |
| 140 |
var extentRect = document.createElementNS(svgNS,"rect"); |
| 141 |
extentRect.setAttributeNS(null,"fill","lightblue"); |
| 142 |
extentRect.setAttributeNS(null,"x",charExtent.x); |
| 143 |
extentRect.setAttributeNS(null,"y",charExtent.y); |
| 144 |
extentRect.setAttributeNS(null,"width",charExtent.width); |
| 145 |
extentRect.setAttributeNS(null,"height",charExtent.height); |
| 146 |
textGroup.insertBefore(extentRect,baseLine); |
| 147 |
|
| 148 |
//5: testing getNumberOfChars |
| 149 |
var numChars = tContentEl.getNumberOfChars(); |
| 150 |
document.getElementById("text5").firstChild.data = ".getNumberOfChars() result: "+numChars; |
| 151 |
|
| 152 |
//6: testing getRotationOfChar |
| 153 |
var charRot = tContentEl.getRotationOfChar(5); |
| 154 |
document.getElementById("text6").firstChild.data = ".getRotationOfChar(5) result: "+charRot; |
| 155 |
var rotCharExtent = tContentEl.getExtentOfChar(5); |
| 156 |
var rotExtentRect = document.createElementNS(svgNS,"rect"); |
| 157 |
rotExtentRect.setAttributeNS(null,"fill","lightblue"); |
| 158 |
rotExtentRect.setAttributeNS(null,"x",rotCharExtent.x); |
| 159 |
rotExtentRect.setAttributeNS(null,"y",rotCharExtent.y); |
| 160 |
rotExtentRect.setAttributeNS(null,"width",rotCharExtent.width); |
| 161 |
rotExtentRect.setAttributeNS(null,"height",rotCharExtent.height); |
| 162 |
textGroup.insertBefore(rotExtentRect,baseLine); |
| 163 |
|
| 164 |
//7: testing .getStartPositionOfChar(), end of character |
| 165 |
var startPosChar = tContentEl.getStartPositionOfChar(11); |
| 166 |
document.getElementById("text7").firstChild.data = ".getStartPositionOfChar(11) result ('e'): "+Math.round(startPosChar.x)+","+Math.round(startPosChar.y); |
| 167 |
var startPosLine = document.createElementNS(svgNS,"line"); |
| 168 |
startPosLine.setAttributeNS(null,"stroke","red"); |
| 169 |
startPosLine.setAttributeNS(null,"x1",startPosChar.x); |
| 170 |
startPosLine.setAttributeNS(null,"x2",startPosChar.x); |
| 171 |
startPosLine.setAttributeNS(null,"y1",startPosChar.y); |
| 172 |
startPosLine.setAttributeNS(null,"y2",startPosChar.y-15); |
| 173 |
textGroup.insertBefore(startPosLine,tContentEl); |
| 174 |
|
| 175 |
//8: testing .getSubStringLength() |
| 176 |
var startPosInterface = tContentEl.getStartPositionOfChar(22); |
| 177 |
var subStrLength = tContentEl.getSubStringLength(22,9); |
| 178 |
document.getElementById("text8").firstChild.data = ".getSubStringLength(22,9) result ('interface'): "+Math.round(subStrLength); |
| 179 |
var subStrLine = document.createElementNS(svgNS,"line"); |
| 180 |
subStrLine.setAttributeNS(null,"stroke","lime"); |
| 181 |
subStrLine.setAttributeNS(null,"x1",startPosInterface.x); |
| 182 |
subStrLine.setAttributeNS(null,"x2",(startPosInterface.x+subStrLength)); |
| 183 |
subStrLine.setAttributeNS(null,"y1",startPosInterface.y); |
| 184 |
subStrLine.setAttributeNS(null,"y2",startPosInterface.y); |
| 185 |
textGroup.insertBefore(subStrLine,tContentEl); |
| 186 |
|
| 187 |
//9: testing .selectSubString() |
| 188 |
tContentEl.selectSubString(18,3); |
| 189 |
|
| 190 |
//10: testing textLength.baseVal.value |
| 191 |
var tlbaseval = tContentEl.textLength.baseVal.value; |
| 192 |
document.getElementById("text10").firstChild.data = ".textLength.baseVal.value result: "+Math.round(tlbaseval); |
| 193 |
|
| 194 |
//11: testing textLength.baseVal.value |
| 195 |
var tlanimval = tContentEl.textLength.animVal.value; |
| 196 |
document.getElementById("text11").firstChild.data = ".textLength.animVal.value result: "+Math.round(tlanimval); |
| 197 |
|
| 198 |
//12: testing lengthAdjust baseVal and animVal |
| 199 |
document.getElementById("text12").firstChild.data = ".lengthAdjust.baseVal and .lengthAdjust.animVal result: "+tContentEl.lengthAdjust.baseVal+","+tContentEl.lengthAdjust.animVal;; |
| 200 |
} |
| 201 |
]]></script> |
| 202 |
<g id="textGroup" font-family="Arial" font-size="15"> |
| 203 |
<text x="240" y="30" text-anchor="middle" id="testText"> |
| 204 |
This <tspan rotate="45,90">is</tspan> a test of the interface SVGTextContentElement. |
| 205 |
</text> |
| 206 |
<text id="text1" x="30" y="60">.getCharNumAtPosition() result: </text> |
| 207 |
<text id="text2" x="30" y="80">.getComputedTextLength() result: </text> |
| 208 |
<text id="text3" x="30" y="100">.getEndPositionOfChar(11) result ('e'): </text> |
| 209 |
<text id="text4" x="30" y="120">.getExtentOfChar(11) result ('e'): </text> |
| 210 |
<text id="text5" x="30" y="140">.getNumberOfChars() result: </text> |
| 211 |
<text id="text6" x="30" y="160">.getRotationOfChar(5) result: </text> |
| 212 |
<text id="text7" x="30" y="180">.getStartPositionOfChar(11) result: </text> |
| 213 |
<text id="text8" x="30" y="200">.getSubStringLength(22,9) result ('interface'): </text> |
| 214 |
<text id="text9" x="30" y="220">.selectSubString(18,3) result: the word 'the' should be selected</text> |
| 215 |
<text id="text10" x="30" y="240">.textLength.baseVal.value result:</text> |
| 216 |
<text id="text11" x="30" y="260">.textLength.animVal.value result:</text> |
| 217 |
<text id="text12" x="30" y="280">.lengthAdjust.baseVal and .lengthAdjust.animVal result:</text> |
| 218 |
</g> |
| 219 |
</g> |
| 220 |
<g font-family="SVGFreeSansASCII,sans-serif" font-size="32"> |
| 221 |
<text id="revision" x="10" y="340" stroke="none" fill="black">$Revision: 1.4 $</text> |
| 222 |
</g> |
| 223 |
<rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000"/> |
| 224 |
<!-- comment out this watermark once the test is approved --> |
| 225 |
<g id="draft-watermark"> |
| 226 |
<rect x="1" y="1" width="478" height="20" fill="red" stroke="black" stroke-width="1"/> |
| 227 |
<text font-family="SVGFreeSansASCII,sans-serif" font-weight="bold" font-size="20" x="240" |
| 228 |
text-anchor="middle" y="18" stroke-width="0.5" stroke="black" fill="white">DRAFT</text> |
| 229 |
</g> |
| 230 |
</svg> |