| 1 |
<?xml version="1.0" standalone="no"?> |
| 2 |
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" |
| 3 |
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> |
| 4 |
|
| 5 |
<!-- |
| 6 |
|
| 7 |
Licensed to the Apache Software Foundation (ASF) under one or more |
| 8 |
contributor license agreements. See the NOTICE file distributed with |
| 9 |
this work for additional information regarding copyright ownership. |
| 10 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
| 11 |
(the "License"); you may not use this file except in compliance with |
| 12 |
the License. You may obtain a copy of the License at |
| 13 |
|
| 14 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
|
| 16 |
Unless required by applicable law or agreed to in writing, software |
| 17 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 18 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 |
See the License for the specific language governing permissions and |
| 20 |
limitations under the License. |
| 21 |
|
| 22 |
--> |
| 23 |
<!-- ====================================================================== --> |
| 24 |
<!-- Tests text content interface for the various text cases --> |
| 25 |
<!-- --> |
| 26 |
<!-- @author [email protected] --> |
| 27 |
<!-- @version $Id$ --> |
| 28 |
<!-- ====================================================================== --> |
| 29 |
<?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> |
| 30 |
|
| 31 |
<svg id="body" width="450" height="500" |
| 32 |
viewBox="0 0 450 500" |
| 33 |
xmlns="http://www.w3.org/2000/svg" |
| 34 |
xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 35 |
|
| 36 |
<script language="text/ecmascript"><![CDATA[ |
| 37 |
var svgns = "http://www.w3.org/2000/svg"; |
| 38 |
var xlinkns = "http://www.w3.org/1999/xlink"; |
| 39 |
|
| 40 |
var ids = new Array("simple", "tspans", "dxdy", "xy", |
| 41 |
"tp_start", "tp_middle", "tp_end", "test", |
| 42 |
"tp_ag_middle", "ag1", "ag2", "ag3", "ag4", |
| 43 |
"ligature", "tp_lig", "lig2", "tp_lig2"); |
| 44 |
for (var i=0; i<ids.length; i++) { |
| 45 |
var elem = document.getElementById(ids[i]); |
| 46 |
showCharactersInfo(elem); |
| 47 |
showTextInfo(elem); |
| 48 |
} |
| 49 |
|
| 50 |
function showTextInfo(elt) { |
| 51 |
var group = elt; |
| 52 |
var text = elt; |
| 53 |
while (group.localName != "g") { |
| 54 |
if (text.localName != "text") |
| 55 |
text = text.parentNode; |
| 56 |
group = group.parentNode; |
| 57 |
} |
| 58 |
var bbox = text.getBBox(); |
| 59 |
var x=bbox.x+bbox.width+10; |
| 60 |
var y=bbox.y+bbox.height*.6 |
| 61 |
var t = document.createElementNS(svgns, "text"); |
| 62 |
t.setAttribute("x", ""+x); |
| 63 |
t.setAttribute("y", ""+y); |
| 64 |
t.setAttribute("font-size", "10"); |
| 65 |
var str = "len: " + elt.getComputedTextLength(); |
| 66 |
var idx = str.indexOf('.'); |
| 67 |
if (idx >= 0) { |
| 68 |
idx += 4; |
| 69 |
if (idx > str.length) idx = str.length; |
| 70 |
str = str.substring(0,idx); |
| 71 |
} |
| 72 |
|
| 73 |
var tn = document.createTextNode(str); |
| 74 |
t.appendChild(tn); |
| 75 |
group.appendChild(t); |
| 76 |
} |
| 77 |
|
| 78 |
function showCharactersInfo(elt) { |
| 79 |
var numChar = elt.getNumberOfChars(); |
| 80 |
for(var i=0; i<numChar; i++) { |
| 81 |
showCharacterBBox(elt, i); |
| 82 |
showCharacterStartEndPosition(elt, i); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
function showCharacterBBox(elt, index) { |
| 87 |
var group = elt; |
| 88 |
while (group.localName != "g") |
| 89 |
group = group.parentNode; |
| 90 |
try { |
| 91 |
var box = elt.getExtentOfChar(index); |
| 92 |
var mat = elt.getTransformToElement(group); |
| 93 |
var root = document.getRootElement(); |
| 94 |
|
| 95 |
var pt0 = root.createSVGPoint(); |
| 96 |
pt0.x = box.getX(); |
| 97 |
pt0.y = box.getY(); |
| 98 |
pt0 = pt0.matrixTransform(mat); |
| 99 |
|
| 100 |
var pt1 = root.createSVGPoint(); |
| 101 |
pt1.x = box.getX()+box.getWidth(); |
| 102 |
pt1.y = box.getY(); |
| 103 |
pt1 = pt1.matrixTransform(mat); |
| 104 |
|
| 105 |
var pt2 = root.createSVGPoint(); |
| 106 |
pt2.x = box.getX()+box.getWidth(); |
| 107 |
pt2.y = box.getY()+box.getHeight(); |
| 108 |
pt2 = pt2.matrixTransform(mat); |
| 109 |
|
| 110 |
var pt3 = root.createSVGPoint(); |
| 111 |
pt3.x = box.getX(); |
| 112 |
pt3.y = box.getY()+box.getHeight(); |
| 113 |
pt3 = pt3.matrixTransform(mat); |
| 114 |
|
| 115 |
var p = document.createElementNS(svgns,"path"); |
| 116 |
p.setAttribute("d","M" + pt0.x + "," + pt0.y + |
| 117 |
"L" + pt1.x + "," + pt1.y + |
| 118 |
"L" + pt2.x + "," + pt2.y + |
| 119 |
"L" + pt3.x + "," + pt3.y + "z"); |
| 120 |
p.setAttributeNS(null,"stroke","grey"); |
| 121 |
p.setAttributeNS(null,"fill","none"); |
| 122 |
group.appendChild(p); |
| 123 |
} catch (e) { |
| 124 |
// System.err.println("Err: " + e); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
function showCharacterStartEndPosition(elt, index) { |
| 129 |
var group = elt; |
| 130 |
while (group.localName != "g") |
| 131 |
group = group.parentNode; |
| 132 |
// var mat = elt.getTransformToElement(group); |
| 133 |
|
| 134 |
try { |
| 135 |
var p1 = elt.getStartPositionOfChar(index); |
| 136 |
var u = document.createElementNS(svgns,"use"); |
| 137 |
u.setAttributeNS(xlinkns,"href","#dot"); |
| 138 |
u.setAttributeNS(null,"transform", |
| 139 |
"translate("+p1.x+","+p1.y+")"); |
| 140 |
group.appendChild(u); |
| 141 |
|
| 142 |
var p2 = elt.getEndPositionOfChar(index); |
| 143 |
u = document.createElementNS(svgns,"use"); |
| 144 |
u.setAttributeNS(xlinkns,"href","#box"); |
| 145 |
u.setAttributeNS(null,"transform", |
| 146 |
"translate("+p2.x+","+p2.y+")"); |
| 147 |
group.appendChild(u); |
| 148 |
|
| 149 |
u = document.createElementNS(svgns,"use"); |
| 150 |
u.setAttributeNS(xlinkns,"href","#line"); |
| 151 |
var ang = elt.getRotationOfChar(index); |
| 152 |
var x = ( p1.x + p2.x )/2; |
| 153 |
var y = ( p1.y + p2.y )/2; |
| 154 |
u.setAttributeNS(null,"transform", |
| 155 |
"translate("+x+","+y+") rotate("+ang+")"); |
| 156 |
group.appendChild(u); |
| 157 |
} catch (e) { |
| 158 |
// System.err.println("Err: " + e); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
function regardStart() { |
| 163 |
regardTestInstance.scriptDone(); |
| 164 |
} |
| 165 |
]]></script> |
| 166 |
|
| 167 |
<title>Text content interface test.</title> |
| 168 |
<text x="50%" y="45" class="title">Text content interface test</text> |
| 169 |
|
| 170 |
<defs> |
| 171 |
<rect id="box" x="-2.5" y="-2.5" width="5" height="5" |
| 172 |
stroke="red" fill="none"/> |
| 173 |
<rect id="dot" x="-1" y="-1" width="2" height="2" |
| 174 |
stroke="none" fill="green"/> |
| 175 |
<line stroke-width="1" id="line" stroke="#0CF" |
| 176 |
x1="-2.5" y1="0" x2="2.5" y2="0" /> |
| 177 |
<path id="Path1" style="fill:none; stroke:blue;" |
| 178 |
transform="scale(0.30,0.50)" |
| 179 |
d="M 50 100 C50 0 350 0 350 100"/> |
| 180 |
|
| 181 |
<font horiz-adv-x="600" id="stroke"> |
| 182 |
<font-face |
| 183 |
font-family="Stroke" |
| 184 |
font-weight="normal" |
| 185 |
units-per-em="1000" |
| 186 |
ascent="1000" |
| 187 |
descent="250" |
| 188 |
alphabetic="0"/> |
| 189 |
<missing-glyph horiz-adv-x="600" d="M0 0 V75 H50 V0 z"/> |
| 190 |
|
| 191 |
<glyph id="MyABC" unicode="ABC" glyph-name="ABC" horiz-adv-x="1800" |
| 192 |
d="M661,-13l-300,750c-3,8 -10,12 -18,13c-8,0 -15,-5 -19,-12l-320,-750c-4,-10 0,-22 11,-26c10,-4 22,0 26,11c0,0 63,147 131,308l329,0c64,-160 123,-307 123,-307c4,-10 16,-15 26,-11c10,4 15,16 11,26zM190,320c68,159 137,320 153,358c15,-38 80,-199 143,-358l-296,0z |
| 193 |
M675,750c-11,0 -20,-9 -20,-20l0,-750c0,-11 9,-20 20,-20l224,0c158,0 241,111 241,221c0,81 -45,162 -132,200c87,33 132,104 132,175c0,96 -83,194 -241,194l-224,0zM900,710c138,0 201,-80 201,-154c0,-74 -63,-154 -201,-154c0,0 -170,0 -204,0c0,151 0,292 0,308c33,0 204,0 204,0zM900,362c138,0 201,-94 201,-181c0,-87 -63,-181 -201,-181c0,0 -170,0 -204,0c0,19 0,181 0,362c33,0 204,0 204,0z |
| 194 |
M1100,355c0,-218 126,-395 282,-395c93,0 180,64 233,172c5,10 1,22 -9,27c-10,5 -22,1 -27,-9c-46,-93 -119,-149 -197,-149c-133,0 -242,159 -242,355c0,196 108,355 242,355c78,0 151,-56 197,-149c5,-10 17,-14 27,-9c10,5 14,17 9,27c-52,107 -139,172 -233,172c-155,0 -282,-177 -282,-395z"/> |
| 195 |
|
| 196 |
<glyph id="MyDE" unicode="DE" glyph-name="DE" horiz-adv-x="1080" |
| 197 |
d="M20,750c-11,0 -20,-9 -20,-20l0,-750c0,-11 9,-20 20,-20l224,0c165,0 241,205 241,395c0,190 -75,395 -241,395l-224,0zM244,710c132,0 201,-179 201,-355c0,-176 -69,-355 -201,-355c0,0 -170,0 -204,0c0,37 0,673 0,710c33,0 204,0 204,0z |
| 198 |
M920,0c0,0 -344,0 -380,0c0,19 0,192 0,362l251,0c11,0 20,9 20,20c0,11 -9,20 -20,20l-251,0c0,151 0,291 0,308c36,0 380,0 380,0c11,0 20,9 20,20c0,11 -9,20 -20,20l-400,0c-11,0 -20,-9 -20,-20l0,-750c0,-11 9,-20 20,-20l400,0c11,0 20,9 20,20c0,11 -9,20 -20,20z"/> |
| 199 |
|
| 200 |
<glyph id="MyA" unicode="A" glyph-name="A" horiz-adv-x="780" |
| 201 |
d="M661,-13l-300,750c-3,8 -10,12 -18,13c-8,0 -15,-5 -19,-12l-320,-750c-4,-10 0,-22 11,-26c10,-4 22,0 26,11c0,0 63,147 131,308l329,0c64,-160 123,-307 123,-307c4,-10 16,-15 26,-11c10,4 15,16 11,26zM190,320c68,159 137,320 153,358c15,-38 80,-199 143,-358l-296,0z"/> |
| 202 |
<glyph id="MyB" unicode="B" glyph-name="B" horiz-adv-x="630" |
| 203 |
d="M20,750c-11,0 -20,-9 -20,-20l0,-750c0,-11 9,-20 20,-20l224,0c158,0 241,111 241,221c0,81 -45,162 -132,200c87,33 132,104 132,175c0,96 -83,194 -241,194l-224,0zM244,710c138,0 201,-80 201,-154c0,-74 -63,-154 -201,-154c0,0 -170,0 -204,0c0,151 0,292 0,308c33,0 204,0 204,0zM244,362c138,0 201,-94 201,-181c0,-87 -63,-181 -201,-181c0,0 -170,0 -204,0c0,19 0,181 0,362c33,0 204,0 204,0z"/> |
| 204 |
<glyph id="MyC" unicode="C" glyph-name="C" horiz-adv-x="650" |
| 205 |
d="M0,355c0,-218 126,-395 282,-395c93,0 180,64 233,172c5,10 1,22 -9,27c-10,5 -22,1 -27,-9c-46,-93 -119,-149 -197,-149c-133,0 -242,159 -242,355c0,196 108,355 242,355c78,0 151,-56 197,-149c5,-10 17,-14 27,-9c10,5 14,17 9,27c-52,107 -139,172 -233,172c-155,0 -282,-177 -282,-395z"/> |
| 206 |
<glyph id="MyD" unicode="D" glyph-name="D" horiz-adv-x="630" |
| 207 |
d="M20,750c-11,0 -20,-9 -20,-20l0,-750c0,-11 9,-20 20,-20l224,0c165,0 241,205 241,395c0,190 -75,395 -241,395l-224,0zM244,710c132,0 201,-179 201,-355c0,-176 -69,-355 -201,-355c0,0 -170,0 -204,0c0,37 0,673 0,710c33,0 204,0 204,0z"/> |
| 208 |
<glyph id="MyE" unicode="E" glyph-name="E" horiz-adv-x="580" |
| 209 |
d="M420,0c0,0 -344,0 -380,0c0,19 0,192 0,362l251,0c11,0 20,9 20,20c0,11 -9,20 -20,20l-251,0c0,151 0,291 0,308c36,0 380,0 380,0c11,0 20,9 20,20c0,11 -9,20 -20,20l-400,0c-11,0 -20,-9 -20,-20l0,-750c0,-11 9,-20 20,-20l400,0c11,0 20,9 20,20c0,11 -9,20 -20,20z"/> |
| 210 |
|
| 211 |
</font> |
| 212 |
|
| 213 |
<altGlyphDef id="MyAltGlyphDef1"> |
| 214 |
<glyphRef xlink:href="#MyA"/> |
| 215 |
<glyphRef xlink:href="#MyB"/> |
| 216 |
<glyphRef xlink:href="#MyC"/> |
| 217 |
<glyphRef xlink:href="#MyD"/> |
| 218 |
<glyphRef xlink:href="#MyE"/> |
| 219 |
</altGlyphDef> |
| 220 |
<altGlyphDef id="MyAGTest"> |
| 221 |
<glyphRef xlink:href="#MyA"/> |
| 222 |
<glyphRef xlink:href="#MyB"/> |
| 223 |
<glyphRef xlink:href="#MyC"/> |
| 224 |
<glyphRef xlink:href="#MyD"/> |
| 225 |
</altGlyphDef> |
| 226 |
<altGlyphDef id="MyAltGlyphDef4"> |
| 227 |
<altGlyphItem> |
| 228 |
<glyphRef xlink:href="#MyA"/> |
| 229 |
<glyphRef xlink:href="#NoSuchId"/> |
| 230 |
<glyphRef xlink:href="#MyC"/> |
| 231 |
</altGlyphItem> |
| 232 |
<altGlyphItem> |
| 233 |
<glyphRef xlink:href="#MyA"/> |
| 234 |
<glyphRef xlink:href="#MyB"/> |
| 235 |
<glyphRef xlink:href="#MyC"/> |
| 236 |
<glyphRef xlink:href="#MyD"/> |
| 237 |
<glyphRef xlink:href="#MyE"/> |
| 238 |
</altGlyphItem> |
| 239 |
</altGlyphDef> |
| 240 |
<altGlyphDef id="MyAltGlyphDef5"> |
| 241 |
<altGlyphItem> |
| 242 |
<glyphRef xlink:href="#MyA"/> |
| 243 |
<glyphRef xlink:href="#NoSuchId"/> |
| 244 |
<glyphRef xlink:href="#MyA"/> |
| 245 |
</altGlyphItem> |
| 246 |
<altGlyphItem> |
| 247 |
<glyphRef xlink:href="#MyB"/> |
| 248 |
<glyphRef xlink:href="#MyB"/> |
| 249 |
<glyphRef xlink:href="#NoSuchId"/> |
| 250 |
</altGlyphItem> |
| 251 |
</altGlyphDef> |
| 252 |
</defs> |
| 253 |
|
| 254 |
<defs> |
| 255 |
</defs> |
| 256 |
|
| 257 |
<g id="test-content" style="font-size:18"> |
| 258 |
<text id="simple" x="25" y="100">Simple Text</text> |
| 259 |
<text x="25" y="130">Using |
| 260 |
<tspan id="tspans" fill="blue">Tspan</tspan></text> |
| 261 |
<text id="dxdy" x="25" y="160">Tspan |
| 262 |
<tspan fill="blue" dx="2 -1 0 -1 2" dy="-5 10 -5 -5 10" |
| 263 |
>Dx/Dy</tspan></text> |
| 264 |
<text id="xy" x="25" y="190">Tspan |
| 265 |
<tspan fill="blue" x="85" y="195" |
| 266 |
>X/Y</tspan></text> |
| 267 |
|
| 268 |
<g transform="translate(230,65)"> |
| 269 |
<use xlink:href="#Path1" style="fill:none; stroke:blue; stroke-width:2"/> |
| 270 |
<text id="tp_start" style="text-anchor:start"> |
| 271 |
<textPath xlink:href="#Path1" startOffset="50%">Text <tspan fill="red" dy="-10">on</tspan><tspan dy="10"> a Path</tspan></textPath> |
| 272 |
</text> |
| 273 |
</g> |
| 274 |
|
| 275 |
<g transform="translate(230,125)"> |
| 276 |
<use xlink:href="#Path1" style="fill:none; stroke:blue; stroke-width:2"/> |
| 277 |
<text id="tp_middle" style="text-anchor:middle"> |
| 278 |
<textPath xlink:href="#Path1" startOffset="50%">Text <tspan fill="red" dy="-10">on</tspan><tspan dy="10"> a Path</tspan></textPath> |
| 279 |
</text> |
| 280 |
</g> |
| 281 |
|
| 282 |
<g transform="translate(230,185)"> |
| 283 |
<use xlink:href="#Path1" style="fill:none; stroke:blue; stroke-width:2"/> |
| 284 |
<text id="tp_end" style="text-anchor:end"> |
| 285 |
<textPath xlink:href="#Path1" startOffset="50%">Text <tspan |
| 286 |
fill="red" dy="-10">on</tspan><tspan dy="10" |
| 287 |
> a Path</tspan></textPath> |
| 288 |
</text> |
| 289 |
</g> |
| 290 |
|
| 291 |
<g transform="translate(10,210)"> |
| 292 |
<use xlink:href="#Path1" style="fill:none; stroke:blue; stroke-width:2"/> |
| 293 |
<text id="tp_ag_middle" style="text-anchor:middle"> |
| 294 |
<textPath xlink:href="#Path1" startOffset="50%">glyphRefs: "<altGlyph |
| 295 |
rotate="10,10,10,10,10" dx="0,2,2,2,2" dy="0,2,2,-2,-2" |
| 296 |
fill="green" xlink:href="#MyAltGlyphDef1">No Match</altGlyph |
| 297 |
>"</textPath> |
| 298 |
</text> |
| 299 |
</g> |
| 300 |
|
| 301 |
<text x="170" y="270" id="test" >phRefs: "<altGlyph |
| 302 |
rotate="10,10,10,10,10" dx="0,2,2,2,2" dy="0,2,2,-2,-2" |
| 303 |
fill="green" xlink:href="#MyAGTest">No Match</altGlyph |
| 304 |
></text> |
| 305 |
|
| 306 |
<text id="ag1" x="5" y="300">5 valid glyphRefs: "<altGlyph |
| 307 |
fill="green" xlink:href="#MyAltGlyphDef1">No Match</altGlyph>"</text> |
| 308 |
|
| 309 |
<text id="ag2" x="5" y="330">2 altGlyphItems, both |
| 310 |
<tspan fill="red">invalid</tspan>: "<altGlyph |
| 311 |
fill="red" xlink:href="#MyAltGlyphDef5">No Match</altGlyph>"</text> |
| 312 |
|
| 313 |
<text id="ag3" x="5" y="360">2 altGlyphItems, 2nd valid: "<altGlyph |
| 314 |
fill="green" xlink:href="#MyAltGlyphDef4">No Match</altGlyph>"</text> |
| 315 |
|
| 316 |
<text id="ag4" x="5" y="390">5 glyphRefs, dx/dy/rotate: "<altGlyph |
| 317 |
rotate="10,10,10,10,10" dx="0,2,2,2,2" dy="0,2,2,-2,-2" |
| 318 |
fill="green" xlink:href="#MyAltGlyphDef1">No Match</altGlyph>"</text> |
| 319 |
|
| 320 |
<text id="ligature" x="5" y="420">ligature <tspan |
| 321 |
font-family="stroke" fill="green">ABCDE</tspan></text> |
| 322 |
|
| 323 |
<g transform="translate(10,430)"> |
| 324 |
<use xlink:href="#Path1" style="fill:none; stroke:blue; stroke-width:2"/> |
| 325 |
<text id="tp_lig" style="text-anchor:middle"> |
| 326 |
<textPath xlink:href="#Path1" startOffset="50%">ligature <tspan |
| 327 |
font-family="stroke" fill="green">ABCDE</tspan></textPath></text> |
| 328 |
</g> |
| 329 |
|
| 330 |
<text id="lig2" x="235" y="420">ligature <tspan |
| 331 |
font-family="stroke" fill="green">ABC</tspan></text> |
| 332 |
|
| 333 |
<g transform="translate(235,430)"> |
| 334 |
<use xlink:href="#Path1" style="fill:none; stroke:blue; stroke-width:2"/> |
| 335 |
<text id="tp_lig2" style="text-anchor:middle"> |
| 336 |
<textPath xlink:href="#Path1" startOffset="65%">ligature <tspan |
| 337 |
font-family="stroke" fill="green">ABCDE</tspan></textPath></text> |
| 338 |
</g> |
| 339 |
</g> |
| 340 |
</svg> |