Debian Codegraph @

samples/tests/spec/scripting/textcontent/numberOfChars.svg

raw
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 Licensed to the Apache Software Foundation (ASF) under one or more
7 contributor license agreements. See the NOTICE file distributed with
8 this work for additional information regarding copyright ownership.
9 The ASF licenses this file to You under the Apache License, Version 2.0
10 (the "License"); you may not use this file except in compliance with
11 the License. You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
20 -->
21
22 <!-- ========================================================================= -->
23 <!-- Tests various text on a path -->
24 <!-- -->
25 <!-- @author [email protected] -->
26 <!-- @version $Id$ -->
27 <!-- ========================================================================= -->
28 <?xml-stylesheet type="text/css" href="../../../resources/style/test.css" ?>
29
30 <svg xmlns="http://www.w3.org/2000/svg"
31 xmlns:xlink="http://www.w3.org/1999/xlink" id="body" width="450" height="600"
32 viewBox="0 0 450 600" onmouseover="showNumberOfChars(evt)" >
33 <title>number of chars</title>
34
35 <style type="text/css"><![CDATA[
36 .description{
37 fill:gray;
38 fill-opacity:0.6;
39 }
40 filename{
41 fill-opacity:1.0;
42 }
43 ]]></style>
44
45 <defs>
46 <path id="arrow" d="M-5 0 L 5 0 M 0 -5 L 0 5z" />
47 <line stroke-width="3" id="line" x1="-5" y1="0" x2="5" y2="0" />
48 </defs>
49
50 <script><![CDATA[
51 var interval;
52 var currentFile;
53 var display;
54 var svgns = "http://www.w3.org/2000/svg";
55 var xlinkns = "http://www.w3.org/1999/xlink";
56 function showNumberOfChars(evt)
57 {
58 var elt = evt.target;
59
60 while (( elt != null ) && ( elt.getLocalName() != "text" )){
61 elt = elt.getParentNode();
62 }
63
64 if ( (elt != null) && ( elt.getLocalName() == "text" )
65 && !elt.hasAttributeNS(null,"class") )
66 {
67 var doc = elt.getOwnerDocument();
68
69 var t = doc.getElementById('numberOfChars');
70
71 var textnode = t.getFirstChild();
72
73 textnode.setData("Node has "+elt.getNumberOfChars()+" characters");
74
75 t = doc.getElementById("extraInfo");
76 textNode = t.getFirstChild();
77 textNode.setData("");
78
79 startCharactersBBox(elt);
80 }
81 }
82
83 function startCharactersBBox(elt){
84
85 rendering = elt;
86 currentIndex = 0;
87 display = 0 ;
88 run();
89
90 if ( interval == null ){
91 interval = setInterval('run()',500);
92 }
93 }
94
95 function run(){
96
97
98 var doc = rendering.getOwnerDocument();
99 var group = doc.getElementById('bboxGroup');
100
101 while (group.hasChildNodes() ){
102 group.removeChild(group.getFirstChild());
103 }
104
105 if ( display == 0 ) {
106 showCharactersBBox(rendering,currentIndex);
107 }
108 if ( display == 1 ) {
109 showCharactersStartPosition(rendering,currentIndex);
110 showCharactersEndPosition(rendering,currentIndex);
111 }
112 if ( display == 2 ) {
113 showRotationAngle(rendering,currentIndex);
114 }
115
116 if ( display == 3 ) {
117 showTextLength(rendering,currentIndex);
118 }
119
120 //selectAllText(rendering);
121 currentIndex++;
122 var it = doc.getElementById("charIndex");
123 var itn = it.getFirstChild();
124 itn.setData("Character: " + currentIndex);
125
126 if ( currentIndex >= rendering.getNumberOfChars() ){
127 currentIndex = 0;
128 display++;
129 }
130
131 if ( display == 4 ){
132 display = 0 ;
133 var t = doc.getElementById("extraInfo");
134 var textNode = t.getFirstChild();
135 textNode.setData("");
136 }
137
138 }
139
140 function selectAllText(rendering){
141 rendering.selectSubString(0,rendering.getNumberOfChars());
142 }
143
144 function showCharactersBBox(elt, index) {
145 var doc = elt.getOwnerDocument();
146
147 var group = doc.getElementById('bboxGroup');
148
149 try {
150 var box = elt.getExtentOfChar(index);
151 var mat = elt.getTransformToElement(group);
152 var root = doc.getRootElement();
153
154 var pt0 = root.createSVGPoint();
155 pt0.x = box.getX();
156 pt0.y = box.getY();
157 pt0 = pt0.matrixTransform(mat);
158
159 var pt1 = root.createSVGPoint();
160 pt1.x = box.getX()+box.getWidth();
161 pt1.y = box.getY();
162 pt1 = pt1.matrixTransform(mat);
163
164 var pt2 = root.createSVGPoint();
165 pt2.x = box.getX()+box.getWidth();
166 pt2.y = box.getY()+box.getHeight();
167 pt2 = pt2.matrixTransform(mat);
168
169 var pt3 = root.createSVGPoint();
170 pt3.x = box.getX();
171 pt3.y = box.getY()+box.getHeight();
172 pt3 = pt3.matrixTransform(mat);
173
174 var p = doc.createElementNS(svgns,"path");
175 p.setAttribute("d","M" + pt0.x + "," + pt0.y +
176 "L" + pt1.x + "," + pt1.y +
177 "L" + pt2.x + "," + pt2.y +
178 "L" + pt3.x + "," + pt3.y + "z");
179 p.setAttributeNS(null,"stroke","red");
180 group.appendChild(p);
181 } catch (e) { }
182 }
183
184 function showCharactersStartPosition(elt, index) {
185 var doc = elt.getOwnerDocument();
186 var group = doc.getElementById('bboxGroup');
187
188 try {
189 var point = elt.getStartPositionOfChar(index);
190 var mat = elt.getTransformToElement(group);
191 point = point.matrixTransform(mat);
192 var u = doc.createElementNS(svgns,"use");
193 u.setAttributeNS(null,"transform",
194 "translate("+point.x+","+point.y+")");
195 u.setAttributeNS(xlinkns,"href","#arrow");
196 u.setAttributeNS(null,"stroke","green");
197 group.appendChild(u);
198 } catch (e) { }
199 }
200
201 function showRotationAngle(elt, index) {
202 var doc = elt.getOwnerDocument();
203 var text = doc.getElementById("extraInfo");
204 var textNode = text.getFirstChild();
205 try {
206 var angle = elt.getRotationOfChar(index);
207
208 textNode.setData("angle : "+angle);
209
210 var group = doc.getElementById('bboxGroup');
211
212 var point1 = elt.getStartPositionOfChar(index);
213 var point2 = elt.getEndPositionOfChar(index);
214
215 var u = doc.createElementNS(svgns,"use");
216 var mat = elt.getTransformToElement(group);
217
218 point1 = point1.matrixTransform(mat);
219 point2 = point2.matrixTransform(mat);
220
221 x = ( point1.getX() + point2.getX() )/2;
222 y = ( point1.getY() + point2.getY() )/2;
223
224 u.setAttributeNS(null,"transform",
225 "translate("+x+","+y+") rotate("+angle+")");
226 u.setAttributeNS(xlinkns,"href","#line");
227 u.setAttributeNS(null,"stroke","green");
228 group.appendChild(u);
229 } catch (e) {
230 textNode.setData("angle : <not visible>");
231 }
232 }
233
234 function showCharactersEndPosition(elt, index) {
235 var doc = elt.getOwnerDocument();
236
237 var group = doc.getElementById('bboxGroup');
238
239 try {
240 var point = elt.getEndPositionOfChar(index);
241 var mat = elt.getTransformToElement(group);
242 point = point.matrixTransform(mat);
243
244 var u = doc.createElementNS(svgns,"use");
245 u.setAttributeNS(null,"transform",
246 "translate("+point.x+","+point.y+")");
247 u.setAttributeNS(xlinkns,"href","#arrow");
248 u.setAttributeNS(null,"stroke","blue");
249 group.appendChild(u);
250 } catch (e) { }
251 }
252
253 function showTextLength(elt,index) {
254
255 var doc = elt.getOwnerDocument();
256
257 var group = doc.getElementById('bboxGroup');
258
259 try {
260 var length = elt.getSubStringLength(0,index+1);
261 var text = doc.getElementById("extraInfo");
262 var textNode = text.getFirstChild();
263 textNode.setData("Length : "+length);
264
265 var point = elt.getStartPositionOfChar(0);
266 var mat = elt.getTransformToElement(group);
267 point = point.matrixTransform(mat);
268
269 var u = doc.createElementNS
270 (svgns,"line");
271 u.setAttributeNS(null,"x1",point.getX());
272 u.setAttributeNS(null,"y1",point.getY());
273 u.setAttributeNS(null,"x2",(point.getX()+length));
274 u.setAttributeNS(null,"y2",point.getY());
275 u.setAttributeNS(null,"stroke","red");
276 group.appendChild(u);
277 } catch (e) { }
278 }
279
280 function switchTo(evt,filename){
281
282 if ( interval != null ){
283 clearInterval(interval);
284 }
285 interval = null;
286
287 var doc = evt.target.getOwnerDocument();
288
289 if ( currentFile == null ){
290 currentFile = doc.getElementById('first');
291 }
292 if ( currentFile == evt.target ){
293 return;
294 }
295 currentFile.removeAttributeNS(null,'fill');
296 currentFile = evt.target;
297 currentFile.setAttributeNS(null,'fill','black');
298
299 var group = doc.getElementById('bboxGroup');
300
301 while (group.hasChildNodes() ){
302 group.removeChild(group.getFirstChild());
303 }
304
305 var use = doc.getElementById('filename');
306 use.setAttributeNS(xlinkns,"href",filename);
307
308 var container = doc.getElementById('container');
309 container.removeChild(use);
310 container.appendChild(use);
311 }
312 ]]></script>
313
314 <svg id="container" x="0" y="0" width="450" height="500" viewBox="0 0 450 500" >
315 <use id="filename" xlink:href="../../text/textOnPath.svg#content" />
316
317 <g id="bboxes" fill="none" stroke="red" >
318 </g>
319
320 <g id="bboxGroup" style="fill:none;stroke-opacity:0.6">
321 </g>
322 </svg>
323
324
325 <!-- ============================================================= -->
326 <!-- Batik sample mark -->
327 <!-- ============================================================= -->
328 <use xlink:href="../../../../batikLogo.svg#Batik_Tag_Box" />
329
330
331 <text class="filename" id="numberOfChars" x="90%" y="520"
332 style="text-anchor:end">no text selected
333 </text>
334 <text class="filename" id="charIndex" x="90%" y="535" style="text-anchor:end"
335 >no text selected</text>
336 <text class="filename" id="extraInfo" x="90%" y="550" style="text-anchor:end"
337 >no text selected</text>
338 <g fill="gray">
339 <text id="first" fill="black" class="filename" x="5%" y="530" onclick="switchTo(evt,'../../text/textOnPath.svg#content')" >textOnPath</text>
340 <text class="filename" x="5%" y="545" onclick="switchTo(evt,'../../text/textStyles.svg#testContent')" >textStyles</text>
341 <text class="filename" x="5%" y="560" onclick="switchTo(evt,'../../text/verticalText.svg#content')" >verticalText</text>
342 <text class="filename" x="5%" y="575" onclick="switchTo(evt,'../../text/textLayout.svg#testContent')" >textLayout</text>
343 <text class="filename" x="5%" y="590" onclick="switchTo(evt,'../../text/textEffect3.svg#testContent')" >textEffect3</text>
344
345 <text class="filename" x="25%" y="530" onclick="switchTo(evt,'../../fonts/fontAltGlyph.svg#content')" >fontAltGlyph</text>
346 <text class="filename" x="25%" y="545" onclick="switchTo(evt,'../../fonts/fontAltGlyph2.svg#content')" >fontAltGlyph2</text>
347 <text class="filename" x="25%" y="560" onclick="switchTo(evt,'../../fonts/fontAltGlyph3.svg#content')" >fontAltGlyph3</text>
348 <text class="filename" x="25%" y="575" onclick="switchTo(evt,'../../fonts/BatikFont.svg#content')" >BatikFont</text>
349 <text class="filename" x="25%" y="590" onclick="switchTo(evt,'../../fonts/fontDecorations.svg#content')" >fontDecorations</text>
350
351 <text class="filename" x="45%" y="545" onclick="switchTo(evt,'../../fonts/fontOnPath.svg#content')" >fontOnPath</text>
352 <text class="filename" x="45%" y="560" onclick="switchTo(evt,'../../fonts/fontGlyphsBoth.svg#content')" >fontGlyphsBoth</text>
353 </g>
354 </svg>